mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-20 05:41:35 +00:00
XIN-154 fix verify header bug on Validators (#66)
This commit is contained in:
parent
d975ba4014
commit
6090b7f02e
2 changed files with 13 additions and 4 deletions
|
|
@ -612,7 +612,8 @@ func (x *XDPoS_v2) verifyHeader(chain consensus.ChainReader, header *types.Heade
|
|||
return utils.ErrInvalidCheckpointSigners
|
||||
}
|
||||
} else {
|
||||
if header.Validators != nil {
|
||||
if len(header.Validators) != 0 {
|
||||
log.Warn("[verifyHeader] Validators shall not have values in non-epochSwitch block", "Hash", header.Hash(), "Number", header.Number, "Validators", header.Validators)
|
||||
return utils.ErrInvalidFieldInNonEpochSwitch
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS"
|
||||
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/utils"
|
||||
"github.com/XinFinOrg/XDPoSChain/params"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
|
@ -22,12 +23,19 @@ func TestShouldVerifyBlock(t *testing.T) {
|
|||
// Skip the mining time validation by set mine time to 0
|
||||
config.XDPoS.V2.MinePeriod = 0
|
||||
// Block 901 is the first v2 block with round of 1
|
||||
blockchain, _, currentBlock, _, _, _ := PrepareXDCTestBlockChainForV2Engine(t, 901, &config, 0)
|
||||
blockchain, _, _, _, _, _ := PrepareXDCTestBlockChainForV2Engine(t, 910, &config, 0)
|
||||
adaptor := blockchain.Engine().(*XDPoS.XDPoS)
|
||||
|
||||
// Happy path
|
||||
err = adaptor.VerifyHeader(blockchain, currentBlock.Header(), true)
|
||||
err = adaptor.VerifyHeader(blockchain, blockchain.GetBlockByNumber(901).Header(), true)
|
||||
assert.Nil(t, err)
|
||||
|
||||
// TODO: unhappy path XIN-135: https://hashlabs.atlassian.net/wiki/spaces/HASHLABS/pages/95944705/Verify+header
|
||||
// Verify non-epoch switch block
|
||||
err = adaptor.VerifyHeader(blockchain, blockchain.GetBlockByNumber(902).Header(), true)
|
||||
assert.Nil(t, err)
|
||||
|
||||
nonEpochSwitchWithValidators := blockchain.GetBlockByNumber(902).Header()
|
||||
nonEpochSwitchWithValidators.Validators = acc1Addr.Bytes()
|
||||
err = adaptor.VerifyHeader(blockchain, nonEpochSwitchWithValidators, true)
|
||||
assert.Equal(t, utils.ErrInvalidFieldInNonEpochSwitch, err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue