|
|
|
@ -2166,39 +2166,38 @@ func (bc *BlockChain) NextCXReceiptsCheckpoint(currentNum uint64, shardID uint32 |
|
|
|
|
|
|
|
|
|
// the new checkpoint will not exceed currentNum+1
|
|
|
|
|
for num := lastCheckpoint; num <= currentNum+1; num++ { |
|
|
|
|
newCheckpoint = num |
|
|
|
|
by, _ := rawdb.ReadCXReceiptsProofSpent(bc.db, shardID, num) |
|
|
|
|
if by == rawdb.NAByte { |
|
|
|
|
// TODO chao: check if there is IncompingReceiptsHash in crosslink header
|
|
|
|
|
// if the rootHash is non-empty, it means incomingReceipts are not delivered
|
|
|
|
|
// otherwise, it means there is no cross-shard transactions for this block
|
|
|
|
|
newCheckpoint = num |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
if by == rawdb.SpentByte { |
|
|
|
|
newCheckpoint = num |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
// the first unspent blockHash found, break the loop
|
|
|
|
|
newCheckpoint = num |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
return newCheckpoint |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// cleanCXReceiptsCheckpoints will update the checkpoint and clean spent receipts upto checkpoint
|
|
|
|
|
func (bc *BlockChain) cleanCXReceiptsCheckpoints(shardID uint32, currentNum uint64) { |
|
|
|
|
// updateCXReceiptsCheckpoints will update the checkpoint and clean spent receipts upto checkpoint
|
|
|
|
|
func (bc *BlockChain) updateCXReceiptsCheckpoints(shardID uint32, currentNum uint64) { |
|
|
|
|
lastCheckpoint, err := rawdb.ReadCXReceiptsProofUnspentCheckpoint(bc.db, shardID) |
|
|
|
|
if err != nil { |
|
|
|
|
utils.Logger().Warn().Msg("[cleanCXReceiptsCheckpoints] Cannot get lastCheckpoint") |
|
|
|
|
utils.Logger().Warn().Msg("[updateCXReceiptsCheckpoints] Cannot get lastCheckpoint") |
|
|
|
|
} |
|
|
|
|
newCheckpoint := bc.NextCXReceiptsCheckpoint(currentNum, shardID) |
|
|
|
|
if lastCheckpoint == newCheckpoint { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
utils.Logger().Debug().Uint64("lastCheckpoint", lastCheckpoint).Uint64("newCheckpont", newCheckpoint).Msg("[CleanCXReceiptsCheckpoints]") |
|
|
|
|
utils.Logger().Debug().Uint64("lastCheckpoint", lastCheckpoint).Uint64("newCheckpont", newCheckpoint).Msg("[updateCXReceiptsCheckpoints]") |
|
|
|
|
for num := lastCheckpoint; num < newCheckpoint; num++ { |
|
|
|
|
rawdb.DeleteCXReceiptsProofSpent(bc.db, shardID, num) |
|
|
|
|
} |
|
|
|
|
rawdb.WriteCXReceiptsProofUnspentCheckpoint(bc.db, shardID, newCheckpoint) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// WriteCXReceiptsProofSpent mark the CXReceiptsProof list with given unspent status
|
|
|
|
@ -2220,8 +2219,8 @@ func (bc *BlockChain) IsSpent(cxp *types.CXReceiptsProof) bool { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// CleanCXReceiptsCheckpointsByBlock cleans checkpoints based on incomingReceipts of the given block
|
|
|
|
|
func (bc *BlockChain) CleanCXReceiptsCheckpointsByBlock(block *types.Block) { |
|
|
|
|
// UpdateCXReceiptsCheckpointsByBlock cleans checkpoints and update latest checkpoint based on incomingReceipts of the given block
|
|
|
|
|
func (bc *BlockChain) UpdateCXReceiptsCheckpointsByBlock(block *types.Block) { |
|
|
|
|
m := make(map[uint32]uint64) |
|
|
|
|
for _, cxp := range block.IncomingReceipts() { |
|
|
|
|
shardID := cxp.MerkleProof.ShardID |
|
|
|
@ -2235,6 +2234,6 @@ func (bc *BlockChain) CleanCXReceiptsCheckpointsByBlock(block *types.Block) { |
|
|
|
|
|
|
|
|
|
for k, v := range m { |
|
|
|
|
utils.Logger().Debug().Uint32("shardID", k).Uint64("blockNum", v).Msg("[CleanCXReceiptsCheckpoints] Cleaning CXReceiptsProof upto") |
|
|
|
|
bc.cleanCXReceiptsCheckpoints(k, v) |
|
|
|
|
bc.updateCXReceiptsCheckpoints(k, v) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|