Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade validator #184

Merged
merged 12 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion consensus/tests/engine_v2_tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestGetMissedRoundsInEpochByBlockNum(t *testing.T) {
startingBlockNum := currentBlock.Number().Int64() + 1
// Skipped the round
roundNumber := startingBlockNum + 2
block := CreateBlock(blockchain, chainConfig, currentBlock, int(startingBlockNum), roundNumber, blockCoinBase, signer, signFn, nil, nil, "c2bf7b59be5184fc1148be5db14692b2dc89a1b345895d3e8d0ee7b8a7607450")
block := CreateBlock(blockchain, chainConfig, currentBlock, int(startingBlockNum), roundNumber, blockCoinBase, signer, signFn, nil, nil, "25cb20ed8e7f21934d832318bc912e99e8745b4b3018e65d30bafc565df19c3a")
err := blockchain.InsertBlock(block)
if err != nil {
t.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions consensus/tests/engine_v2_tests/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ func PrepareXDCTestBlockChainWith128Candidates(t *testing.T, numOfBlocks int, ch
blockCoinBase = signer.Hex()
}
roundNumber := int64(i) - chainConfig.XDPoS.V2.SwitchBlock.Int64()
block := CreateBlock(blockchain, chainConfig, currentBlock, i, roundNumber, blockCoinBase, signer, signFn, nil, nil, "c2bf7b59be5184fc1148be5db14692b2dc89a1b345895d3e8d0ee7b8a7607450")
block := CreateBlock(blockchain, chainConfig, currentBlock, i, roundNumber, blockCoinBase, signer, signFn, nil, nil, "25cb20ed8e7f21934d832318bc912e99e8745b4b3018e65d30bafc565df19c3a")
err = blockchain.InsertBlock(block)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -614,7 +614,7 @@ func PrepareQCandProcess(t *testing.T, blockchain *BlockChain, currentBlock *typ
func CreateBlock(blockchain *BlockChain, chainConfig *params.ChainConfig, startingBlock *types.Block, blockNumber int, roundNumber int64, blockCoinBase string, signer common.Address, signFn func(account accounts.Account, hash []byte) ([]byte, error), penalties []common.Address, signersKey []*ecdsa.PrivateKey, merkleRoot string) *types.Block {
currentBlock := startingBlock
if len(merkleRoot) == 0 {
merkleRoot = "711be05c0b9d89bd511dd4c20ade1820b2c1fb13343ee0cedd3869150eb2d377"
merkleRoot = "c778a53427689109ddaedda8c5271caaf622da65dfbb1b38b47561d4b0c94ac3"
}
var header *types.Header
statedb, err := blockchain.State()
Expand Down
8 changes: 4 additions & 4 deletions consensus/tests/engine_v2_tests/mine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestYourTurnInitialV2(t *testing.T) {
t.Logf("Inserting block with propose at 11...")
blockCoinbaseA := "0xaaa0000000000000000000000000000000000011"
//Get from block validator error message
merkleRoot := "711be05c0b9d89bd511dd4c20ade1820b2c1fb13343ee0cedd3869150eb2d377"
merkleRoot := "c778a53427689109ddaedda8c5271caaf622da65dfbb1b38b47561d4b0c94ac3"
extraInBytes := generateV2Extra(11, parentBlock, signer, signFn, nil)

header := &types.Header{
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestShouldMineOncePerRound(t *testing.T) {
_, err := adaptor.Seal(blockchain, block910, nil)
assert.Nil(t, err)
time.Sleep(time.Duration(minePeriod) * time.Second)
merkleRoot := "711be05c0b9d89bd511dd4c20ade1820b2c1fb13343ee0cedd3869150eb2d377"
merkleRoot := "c778a53427689109ddaedda8c5271caaf622da65dfbb1b38b47561d4b0c94ac3"

header := &types.Header{
Root: common.HexToHash(merkleRoot),
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestUpdateMasterNodes(t *testing.T) {
t.Fatal(err)
}
//Get from block validator error message
merkleRoot := "2f34d88e4afb95a51b5dd3b157bdec944790c033bbf6e990cc7f946ad07d47c4"
merkleRoot := "41ad5ea0d4c46f36548b27a946fe51e3cefd4d8567cb5c3398ebb570f99d9ee3"
header := &types.Header{
Root: common.HexToHash(merkleRoot),
Number: big.NewInt(int64(1350)),
Expand Down Expand Up @@ -270,7 +270,7 @@ func TestUpdateMultipleMasterNodes(t *testing.T) {
t.Logf("Inserting block with propose at 1350...")
blockCoinbaseA := "0xaaa0000000000000000000000000000000001350"
//Get from block validator error message
merkleRoot := "c2bf7b59be5184fc1148be5db14692b2dc89a1b345895d3e8d0ee7b8a7607450"
merkleRoot := "25cb20ed8e7f21934d832318bc912e99e8745b4b3018e65d30bafc565df19c3a"
parentBlock := CreateBlock(blockchain, config, currentBlock, 1350, 450, blockCoinbaseA, signer, signFn, nil, nil, merkleRoot)
err := blockchain.InsertBlock(parentBlock)
assert.Nil(t, err)
Expand Down
2 changes: 1 addition & 1 deletion consensus/tests/engine_v2_tests/penalty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestHookPenaltyV2TwoEpoch(t *testing.T) {
header1335 := blockchain.GetHeaderByNumber(config.XDPoS.Epoch + config.XDPoS.Gap - uint64(common.MergeSignRange))
tx, err := signingTxWithKey(header1335, 0, voterKey)
assert.Nil(t, err)
block1349 := CreateBlock(blockchain, conf, block1348, 1349, 1358, signer.Hex(), signer, signFn, nil, nil, "c2bf7b59be5184fc1148be5db14692b2dc89a1b345895d3e8d0ee7b8a7607450")
block1349 := CreateBlock(blockchain, conf, block1348, 1349, 1358, signer.Hex(), signer, signFn, nil, nil, "25cb20ed8e7f21934d832318bc912e99e8745b4b3018e65d30bafc565df19c3a")
err = blockchain.InsertBlock(block1349)
assert.Nil(t, err)
adaptor.CacheSigningTxs(block1349.Hash(), []*types.Transaction{tx})
Expand Down
2 changes: 1 addition & 1 deletion consensus/tests/engine_v2_tests/verify_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestShouldVerifyBlock(t *testing.T) {
err = adaptor.VerifyHeader(blockchain, invalidPenaltiesExistBlock, true)
assert.Equal(t, utils.ErrInvalidFieldInNonGapPlusOneSwitch, err)

merkleRoot := "711be05c0b9d89bd511dd4c20ade1820b2c1fb13343ee0cedd3869150eb2d377"
merkleRoot := "c778a53427689109ddaedda8c5271caaf622da65dfbb1b38b47561d4b0c94ac3"
parentNotExistBlock := blockchain.GetBlockByNumber(901).Header()
parentNotExistBlock.ParentHash = common.HexToHash(merkleRoot)
err = adaptor.VerifyHeader(blockchain, parentNotExistBlock, true)
Expand Down
267 changes: 159 additions & 108 deletions contracts/validator/contract/validator.go

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion contracts/validator/src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ cache/
artifacts/
node_modules/
.vscode/

yarn.lock

abi
abigen
yarn.lock
bytecode
2 changes: 1 addition & 1 deletion contracts/validator/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ node scripts/deployToGenesis.js
./abigen --abi abi --bin bytecode --pkg contract --type XDCValidator --out ../contract/validator.go
```

If you don't have `abigen`, compile it. It's in `cmd/abigen/main.go` in XDC main repo (or Geth repo).
If you don't have `abigen`, compile it. It's in `cmd/abigen/main.go` in XDC main repo (or Geth repo). and run `go build`

3. Go `../contract/validator.go` change `github.com/ethereum/go-ethereum` to `ethereum "github.com/XinFinOrg/XDC-Subnet"`

Expand Down
Loading
Loading