Fix cross link verification and change batch size to 50

pull/1936/head
Rongjian Lan 5 years ago
parent 24962022be
commit 108d01f730
  1. 21
      core/blockchain.go
  2. 4
      node/node_cross_shard.go
  3. 15
      node/node_handler.go

@ -1294,7 +1294,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
if err := bc.WriteCrossLinks(types.CrossLinks{crossLink}); err == nil {
utils.Logger().Info().Uint64("blockNum", crossLink.BlockNum()).Uint32("shardID", crossLink.ShardID()).Msg("[insertChain/crosslinks] Cross Link Added to Beaconchain")
}
bc.LastContinuousCrossLink(crossLink.ShardID(), crossLink)
bc.LastContinuousCrossLink(crossLink)
}
//clean/update local database cache after crosslink inserted into blockchain
num, err := bc.DeleteCommittedFromPendingCrossLinks(*crossLinks)
@ -2189,19 +2189,18 @@ func (bc *BlockChain) ReadCrossLink(shardID uint32, blockNum uint64) (*types.Cro
return crossLink, err
}
// WriteShardLastCrossLink saves the last crosslink of a shard
func (bc *BlockChain) WriteShardLastCrossLink(shardID uint32, cl types.CrossLink) error {
return rawdb.WriteShardLastCrossLink(bc.db, cl.ShardID(), cl.Serialize())
}
// LastContinuousCrossLink saves the last crosslink of a shard
// This function will update the latest crosslink in the sense that
// any previous block's crosslink is received up to this point
// there is no missing hole between genesis to this crosslink of given shardID
func (bc *BlockChain) LastContinuousCrossLink(shardID uint32, cl types.CrossLink) error {
cl0, err := bc.ReadShardLastCrossLink(shardID)
func (bc *BlockChain) LastContinuousCrossLink(cl types.CrossLink) error {
if !bc.Config().IsCrossLink(cl.Epoch()) {
return errors.New("Trying to write last continuous cross link with epoch before cross link starting epoch")
}
cl0, err := bc.ReadShardLastCrossLink(cl.ShardID())
if cl0 == nil {
bc.WriteShardLastCrossLink(shardID, cl)
rawdb.WriteShardLastCrossLink(bc.db, cl.ShardID(), cl.Serialize())
return nil
}
if err != nil {
@ -2209,7 +2208,7 @@ func (bc *BlockChain) LastContinuousCrossLink(shardID uint32, cl types.CrossLink
}
newCheckpoint := uint64(0)
for i := cl0.BlockNum() + 1; i < cl.BlockNum(); i++ {
tmp, err := bc.ReadCrossLink(shardID, i)
tmp, err := bc.ReadCrossLink(cl.ShardID(), i)
if err != nil || tmp == nil {
newCheckpoint = i - 1
break
@ -2221,7 +2220,7 @@ func (bc *BlockChain) LastContinuousCrossLink(shardID uint32, cl types.CrossLink
if newCheckpoint > 0 {
utils.Logger().Debug().Msgf("LastContinuousCrossLink: latest checkpoint blockNum %d", newCheckpoint)
cln, err := bc.ReadCrossLink(shardID, newCheckpoint)
cln, err := bc.ReadCrossLink(cl.ShardID(), newCheckpoint)
if err != nil {
return err
}

@ -230,8 +230,8 @@ func (node *Node) VerifyCrossLink(cl types.CrossLink) error {
return ctxerror.New("CrossLink BlockNumber should greater than 1")
}
if node.Blockchain().Config().IsCrossLink(cl.Epoch()) {
return ctxerror.New("CrossLink Epoch should >= crosslink epoch", "crossLinkEpoch", node.Blockchain().Config().CrossLinkEpoch)
if !node.Blockchain().Config().IsCrossLink(cl.Epoch()) {
return ctxerror.New("CrossLink Epoch should >= cross link starting epoch", "crossLinkEpoch", cl.Epoch(), "cross_link_starting_eoch", node.Blockchain().Config().CrossLinkEpoch)
}
// Verify signature of the new cross link header

@ -26,8 +26,7 @@ import (
)
const (
consensusTimeout = 30 * time.Second
crossLinkBatchSize = 7
crossLinkBatchSize = 50
)
// receiveGroupMessage use libp2p pubsub mechanism to receive broadcast messages
@ -218,23 +217,23 @@ func (node *Node) BroadcastCrossLink(newBlock *types.Block) {
if err != nil {
utils.Logger().Debug().Err(err).Msg("[BroadcastCrossLink] ReadShardLastCrossLink Failed")
header := node.Blockchain().GetHeaderByNumber(newBlock.NumberU64() - 2)
if header != nil {
if header != nil && node.Blockchain().Config().IsCrossLink(header.Epoch()) {
headers = append(headers, header)
}
header = node.Blockchain().GetHeaderByNumber(newBlock.NumberU64() - 1)
if header != nil {
if header != nil && node.Blockchain().Config().IsCrossLink(header.Epoch()) {
headers = append(headers, header)
}
headers = append(headers, newBlock.Header())
} else {
latestBlockNum = lastLink.BlockNum()
for blockNum := latestBlockNum + 1; blockNum <= newBlock.NumberU64(); blockNum++ {
if blockNum > latestBlockNum+crossLinkBatchSize {
break
}
header := node.Blockchain().GetHeaderByNumber(blockNum)
if header != nil {
if header != nil && node.Blockchain().Config().IsCrossLink(header.Epoch()) {
headers = append(headers, header)
if len(headers) == crossLinkBatchSize {
break
}
}
}
}

Loading…
Cancel
Save