|
|
|
@ -127,7 +127,7 @@ func (e *engineImpl) VerifySeal(chain engine.ChainReader, header *block.Header) |
|
|
|
|
} |
|
|
|
|
parentHash := header.ParentHash() |
|
|
|
|
parentHeader := chain.GetHeader(parentHash, header.Number().Uint64()-1) |
|
|
|
|
parentQuorum, err := QuorumForBlock(chain, parentHeader) |
|
|
|
|
parentQuorum, err := QuorumForBlock(chain, parentHeader, false) |
|
|
|
|
if err != nil { |
|
|
|
|
return errors.Wrapf(err, |
|
|
|
|
"cannot calculate quorum for block %s", header.Number()) |
|
|
|
@ -160,12 +160,18 @@ func (e *engineImpl) Finalize(chain engine.ChainReader, header *block.Header, st |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// QuorumForBlock returns the quorum for the given block header.
|
|
|
|
|
func QuorumForBlock(chain engine.ChainReader, h *block.Header) (quorum int, err error) { |
|
|
|
|
ss, err := chain.ReadShardState(h.Epoch()) |
|
|
|
|
if err != nil { |
|
|
|
|
return 0, ctxerror.New("failed to read shard state of epoch", |
|
|
|
|
"epoch", h.Epoch().Uint64()) |
|
|
|
|
func QuorumForBlock(chain engine.ChainReader, h *block.Header, reCalculate bool) (quorum int, err error) { |
|
|
|
|
var ss shard.State |
|
|
|
|
if reCalculate { |
|
|
|
|
ss = core.CalculateShardState(h.Epoch()) |
|
|
|
|
} else { |
|
|
|
|
ss, err = chain.ReadShardState(h.Epoch()) |
|
|
|
|
if err != nil { |
|
|
|
|
return 0, ctxerror.New("failed to read shard state of epoch", |
|
|
|
|
"epoch", h.Epoch().Uint64()).WithCause(err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
c := ss.FindCommitteeByID(h.ShardID()) |
|
|
|
|
if c == nil { |
|
|
|
|
return 0, errors.Errorf( |
|
|
|
@ -191,7 +197,7 @@ func (e *engineImpl) VerifyHeaderWithSignature(chain engine.ChainReader, header |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
hash := header.Hash() |
|
|
|
|
quorum, err := QuorumForBlock(chain, header) |
|
|
|
|
quorum, err := QuorumForBlock(chain, header, reCalculate) |
|
|
|
|
if err != nil { |
|
|
|
|
return errors.Wrapf(err, |
|
|
|
|
"cannot calculate quorum for block %s", header.Number()) |
|
|
|
|