fix incoming receipt tx block header verification by correct shard state reading

pull/1539/head
Dennis Won 5 years ago
parent d1af9e5009
commit 602f36a4b7
  1. 4
      cmd/harmony/main.go
  2. 15
      internal/chain/engine.go
  3. 12
      node/node.go

@ -364,8 +364,8 @@ func setupConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
// currentNode.DRand = dRand
// This needs to be executed after consensus and drand are setup
if err := currentNode.InitShardState(); err != nil {
ctxerror.Crit(utils.GetLogger(), err, "InitShardState failed",
if err := currentNode.GetInitShardState(); err != nil {
ctxerror.Crit(utils.GetLogger(), err, "GetInitShardState failed",
"shardID", *shardID)
}

@ -11,6 +11,7 @@ import (
"github.com/harmony-one/harmony/block"
"github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/ctxerror"
@ -139,12 +140,7 @@ func (e *engineImpl) VerifyHeaderWithSignature(chain engine.ChainReader, header
// retrievePublicKeys finds the public keys of current block's committee
func retrievePublicKeys(bc engine.ChainReader, header *block.Header) ([]*bls.PublicKey, error) {
shardState, err := bc.ReadShardState(header.Epoch())
if err != nil {
return nil, ctxerror.New("cannot read shard state",
"epoch", header.Epoch(),
).WithCause(err)
}
shardState := core.GetShardState(header.Epoch())
committee := shardState.FindCommitteeByID(header.ShardID())
if committee == nil {
return nil, ctxerror.New("cannot find shard in the shard state",
@ -172,12 +168,7 @@ func retrievePublicKeysFromLastBlock(bc engine.ChainReader, header *block.Header
return nil, ctxerror.New("cannot find parent block header in DB",
"parentHash", header.ParentHash())
}
parentShardState, err := bc.ReadShardState(parentHeader.Epoch())
if err != nil {
return nil, ctxerror.New("cannot read shard state",
"epoch", parentHeader.Epoch(),
).WithCause(err)
}
parentShardState := core.GetShardState(parentHeader.Epoch())
parentCommittee := parentShardState.FindCommitteeByID(parentHeader.ShardID())
if parentCommittee == nil {
return nil, ctxerror.New("cannot find shard in the shard state",

@ -457,10 +457,10 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, chainDBFactory shardc
return &node
}
// InitShardState initialize shard state from latest epoch and update committee pub keys for consensus and drand
func (node *Node) InitShardState() (err error) {
// GetInitShardState initialize shard state from latest epoch and update committee pub keys for consensus and drand
func (node *Node) GetInitShardState() (err error) {
if node.Consensus == nil {
return ctxerror.New("[InitShardState] consenus is nil; Cannot figure out shardID")
return ctxerror.New("[GetInitShardState] consenus is nil; Cannot figure out shardID")
}
shardID := node.Consensus.ShardID
@ -472,11 +472,11 @@ func (node *Node) InitShardState() (err error) {
Uint64("blockNum", blockNum).
Uint32("shardID", shardID).
Uint64("epoch", epoch.Uint64()).
Msg("[InitShardState] Try To Get PublicKeys from database")
Msg("[GetInitShardState] Try To Get PublicKeys from database")
pubKeys := core.GetPublicKeys(epoch, shardID)
if len(pubKeys) == 0 {
return ctxerror.New(
"[InitShardState] PublicKeys is Empty, Cannot update public keys",
"[GetInitShardState] PublicKeys is Empty, Cannot update public keys",
"shardID", shardID,
"blockNum", blockNum)
}
@ -486,7 +486,7 @@ func (node *Node) InitShardState() (err error) {
utils.Logger().Info().
Uint64("blockNum", blockNum).
Int("numPubKeys", len(pubKeys)).
Msg("[InitShardState] Successfully updated public keys")
Msg("[GetInitShardState] Successfully updated public keys")
node.Consensus.UpdatePublicKeys(pubKeys)
node.Consensus.SetMode(consensus.Normal)
return nil

Loading…
Cancel
Save