-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set eth upgrades in backwards compatible way (#667)
* fix: set eth upgrades in backwards compatible way * fix * undo debugging * add UT
- Loading branch information
Showing
4 changed files
with
109 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// (c) 2019-2021, Ava Labs, Inc. | ||
// | ||
// This file is a derived work, based on the go-ethereum library whose original | ||
// notices appear below. | ||
// | ||
// It is distributed under a license compatible with the licensing terms of the | ||
// original code from which it is derived. | ||
// | ||
// Much love to the original authors for their work. | ||
// ********** | ||
// Copyright 2017 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package core | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ava-labs/coreth/core/rawdb" | ||
"github.com/ava-labs/coreth/core/types" | ||
"github.com/ava-labs/coreth/params" | ||
"github.com/ava-labs/coreth/triedb" | ||
"github.com/ava-labs/coreth/utils" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGenesisEthUpgrades(t *testing.T) { | ||
db := rawdb.NewMemoryDatabase() | ||
preEthUpgrades := ¶ms.ChainConfig{ | ||
ChainID: big.NewInt(43114), // Specifically refers to mainnet for this UT | ||
HomesteadBlock: big.NewInt(0), | ||
DAOForkBlock: nil, | ||
DAOForkSupport: false, | ||
EIP150Block: big.NewInt(0), | ||
EIP155Block: big.NewInt(0), | ||
EIP158Block: big.NewInt(0), | ||
ByzantiumBlock: big.NewInt(0), | ||
ConstantinopleBlock: big.NewInt(0), | ||
PetersburgBlock: big.NewInt(0), | ||
IstanbulBlock: big.NewInt(0), | ||
MuirGlacierBlock: big.NewInt(0), | ||
NetworkUpgrades: params.NetworkUpgrades{ | ||
ApricotPhase1BlockTimestamp: utils.NewUint64(0), | ||
ApricotPhase2BlockTimestamp: utils.NewUint64(0), | ||
}, | ||
} | ||
|
||
tdb := triedb.NewDatabase(db, triedb.HashDefaults) | ||
config := *preEthUpgrades | ||
// Set this up once, just to get the genesis hash | ||
_, genHash, err := SetupGenesisBlock(db, tdb, &Genesis{Config: &config}, common.Hash{}, false) | ||
require.NoError(t, err) | ||
|
||
// Write the configuration back to the db as it would be in prior versions | ||
rawdb.WriteChainConfig(db, genHash, preEthUpgrades) | ||
|
||
// Make some other block | ||
block := types.NewBlock( | ||
&types.Header{ | ||
Number: big.NewInt(1640340), // Berlin activation on mainnet | ||
Difficulty: big.NewInt(1), | ||
ParentHash: genHash, | ||
Time: uint64(time.Now().Unix()), | ||
}, | ||
nil, nil, nil, nil, | ||
) | ||
rawdb.WriteBlock(db, block) | ||
|
||
// We should still be able to re-initialize | ||
config = *preEthUpgrades | ||
config.SetEthUpgrades() // New versions will set additional fields eg, LondonBlock | ||
_, _, err = SetupGenesisBlock(db, tdb, &Genesis{Config: &config}, block.Hash(), false) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters