fix crosslink epoch calculation; remove first block comparison by using first epoch comparison

pull/1877/head
Chao Ma 5 years ago
parent fd9fe64129
commit d165ca090e
  1. 22
      core/types/crosslink.go
  2. 3
      node/node_cross_shard.go

@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/block"
"github.com/harmony-one/harmony/shard"
)
// CrossLink is only used on beacon chain to store the hash links from other shards
@ -19,14 +20,25 @@ type CrossLink struct {
BlockNumberF *big.Int
SignatureF [96]byte //aggregated signature
BitmapF []byte //corresponding bitmap mask for agg signature
ShardIDF uint32 //need first verify signature on |blockNumber|blockHash| is correct
EpochF *big.Int //need first verify signature on |blockNumber|blockHash| is correct
ShardIDF uint32 //will be verified with signature on |blockNumber|blockHash| is correct
ParentEpochF *big.Int //will be verified with signature on |blockNumber|blockHash| is correct
}
// NewCrossLink returns a new cross link object
func NewCrossLink(header *block.Header) CrossLink {
parentBlockNum := header.Number().Sub(header.Number(), big.NewInt(1))
return CrossLink{header.ParentHash(), parentBlockNum, header.LastCommitSignature(), header.LastCommitBitmap(), header.ShardID(), header.Epoch()}
if header.Number().Uint64() == 0 {
return CrossLink{}
}
epoch := big.NewInt(0)
parentBlockNum := big.NewInt(0)
// check if previous header is the last block of an epoch
if shard.Schedule.IsLastBlock(header.Number().Uint64() - 1) {
epoch.Sub(header.Epoch(), big.NewInt(1))
} else {
epoch = header.Epoch()
}
parentBlockNum.Sub(header.Number(), big.NewInt(1))
return CrossLink{header.ParentHash(), parentBlockNum, header.LastCommitSignature(), header.LastCommitBitmap(), header.ShardID(), epoch}
}
// ShardID returns shardID
@ -36,7 +48,7 @@ func (cl CrossLink) ShardID() uint32 {
// ShardID returns shardID
func (cl CrossLink) Epoch() *big.Int {
return cl.EpochF
return cl.ParentEpochF
}
// Number returns blockNum with big.Int format

@ -158,14 +158,13 @@ func (node *Node) ProcessCrossLinkMessage(msgPayload []byte) {
Msg("[ProcessingCrossLink] Crosslink Message Broadcast Unable to Decode")
return
}
firstCrossLinkBlock := core.EpochFirstBlock(node.Blockchain().Config().CrossLinkEpoch)
candidates := []types.CrossLink{}
utils.Logger().Debug().
Msgf("[ProcessingCrossLink] Crosslink going to propose: %d", len(crosslinks))
for i, cl := range crosslinks {
if cl.Number() == nil || cl.Number().Cmp(firstCrossLinkBlock) < 0 {
if cl.Number() == nil || cl.Epoch().Cmp(node.Blockchain().Config().CrossLinkEpoch) < 0 {
utils.Logger().Debug().
Msgf("[ProcessingCrossLink] Crosslink %d skipped: %v", i, cl)
continue

Loading…
Cancel
Save