refactor big int compare and fix 1 bug on headers

This commit is contained in:
Liam Lai 2022-02-21 01:16:33 +03:00
parent 221326aafc
commit 491dc911f3
2 changed files with 7 additions and 5 deletions

View file

@ -180,10 +180,10 @@ func (x *XDPoS) VerifyHeaders(chain consensus.ChainReader, headers []*types.Head
}
if v1headers != nil {
x.EngineV1.VerifyHeaders(chain, headers, fullVerifies, abort, results)
x.EngineV1.VerifyHeaders(chain, v1headers, fullVerifies, abort, results)
}
if v2headers != nil {
x.EngineV2.VerifyHeaders(chain, headers, fullVerifies, abort, results)
x.EngineV2.VerifyHeaders(chain, v2headers, fullVerifies, abort, results)
}
return abort, results

View file

@ -551,13 +551,13 @@ func (x *XDPoS_v2) verifyHeader(chain consensus.ChainReader, header *types.Heade
if header.Number == nil {
return utils.ErrUnknownBlock
}
number := header.Number.Uint64()
if fullVerify {
if len(header.Validator) == 0 {
return consensus.ErrNoValidatorSignature
}
// Don't waste time checking blocks from the future
if header.Time.Cmp(big.NewInt(time.Now().Unix())) > 0 {
if header.Time.Int64() > time.Now().Unix() {
return consensus.ErrFutureBlock
}
}
@ -593,7 +593,7 @@ func (x *XDPoS_v2) verifyHeader(chain consensus.ChainReader, header *types.Heade
// Verify v2 block that is on the epoch switch
if header.Validators != nil {
// Skip if it's the first v2 block as it wil inherit from last v1 epoch block
if header.Number.Cmp(new(big.Int).Add(x.config.V2.SwitchBlock, big.NewInt(1))) == 1 && header.Coinbase != (common.Address{}) {
if header.Number.Uint64() > x.config.V2.SwitchBlock.Uint64()+1 && header.Coinbase != (common.Address{}) {
return utils.ErrInvalidCheckpointBeneficiary
}
if !bytes.Equal(header.Nonce[:], utils.NonceDropVote) {
@ -614,6 +614,8 @@ func (x *XDPoS_v2) verifyHeader(chain consensus.ChainReader, header *types.Heade
// Ensure that the block's timestamp isn't too close to it's parent
var parent *types.Header
number := header.Number.Uint64()
if len(parents) > 0 {
parent = parents[len(parents)-1]
} else {