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