erigon-pulse/core/genesis_test.go

144 lines
4.7 KiB
Go
Raw Normal View History

package core_test
Full BSC support with validator mode (#3233) * migrated consensus and chain config files for bsc support * migrated more files from bsc * fixed consensus crashing * updated erigon lib for parlia snapshot prefix * added staticpeers for bsc * [+] added system contracts [*] fixed bug with loading snapshot [+] enabled gas bailout [+] added fix to prevent syncing more than 1000 headers (for testing only) [*] fixed bug with crashing sender recover sometimes * migrated system contract calls * [*] fixed bug with returning mutable balance object [+] migrated lightclient contracts from bsc [*] fixed parlia consensus config param * [*] fixed tendermint deps * [+] added some logs * [+] enabled bsc forks [*] fixed syscalls from coinbase [*] more logging * Fix call sys contract gas calculation * [*] fixed executing system transactions * [*] enabled receipt hash, gas and bloom filter checks * [-] removed some logging scripts [*] set header checkpoint to 10 million blocks (for testing forks) * [*] fixed bug with commiting dirty inter block state state after system transaction execution [-] removed some extra logs and comments * [+] added chapel and rialto testnet support * [*] fixed chapel allocs * [-] removed 6 mil block limit for headers sync * Fix hardforks on chapel and other testnets * [*] fixed header sync issue after merge * [*] tiny code cleanup * [-] removed some comments * [*] increased mdbx map size to 4 TB * [*] increased max chaindata size to 6 tb * [*] bring more compatibility with origin erigon and some code cleanup * [+] added support of validator mode for BSC chain * [*] enable private key load for bsc, rialto and chapel chains * [*] fixed running BSC validator node * Fix the branch list * [*] tiny fixes for linter * [*] formatted imports for core and parlia packages * [*] fixed import rules in other files * Revert "[*] formatted imports for core and parlia packages" This reverts commit c764b58b34fedc2b14d69458583ba0dad114f227. * [*] changed import rules in more packages * [*] fixed type mismatch in hack command * [*] fixed crash on new epoch, enabled bootstrap flags * [*] fixed linter errors * [*] fixed missing err check for syscalls * [*] now BSC implementation is fully compatible with erigon original sources * Revert "Add chain config and CLI changes for Binance Smart Chain support (#3131)" This reverts commit 3d048b7f1a5e74ca318af96268472e2fb0262d3b. * Revert "Add Parlia consensus engine for Binance Smart Chain support (#3086)" This reverts commit ee99f17fbe0889483004f0ee113e37ad0c5c8283. * [*] fixed several issues after merge * [*] fixed integration compilation * Revert "Fix the branch list" This reverts commit 8150ca57e5f2707a84a9f6a1c5b809b7cc84547b. * [-] removed receipt repair migration * [*] fixed parlia fork numbers output * [*] bring more devel compatibility, fixed bsc address list for access list calculation * [*] fixed bug with commiting state transition for bad blocks in BSC * [*] fixed bsc changes apply for integration command and updated config print for parlia * [*] fixed bug with applying bsc forks for chapel and rialto testnet chains [*] let's use finalize and assemble for mining to let consensus know for what it's finalizing block * Fix compilation errors in hack.go * Fix lint * reset changes in erigon-snapshots to devel * Remove unrelated changes * Fix embed * Remove more unrelated changes * Remove more unrelated changes * Restore clique and aura miner config * Refactor interfaces not to use slice pointers * Refactor parlia functions to return tx and receipt instead of dealing with slices * Fix for header panic * Fix lint, restore system contract addresses * Remove more unrelated changes, unify GatherForks Co-authored-by: Dmitry Ivanov <convexman18@gmail.com> Co-authored-by: j75689 <j75689@gmail.com> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-01-14 19:06:35 +00:00
import (
"context"
"math/big"
"testing"
"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon-lib/chain/networkname"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/state/temporal"
"github.com/ledgerwatch/erigon/turbo/rpchelper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
Full BSC support with validator mode (#3233) * migrated consensus and chain config files for bsc support * migrated more files from bsc * fixed consensus crashing * updated erigon lib for parlia snapshot prefix * added staticpeers for bsc * [+] added system contracts [*] fixed bug with loading snapshot [+] enabled gas bailout [+] added fix to prevent syncing more than 1000 headers (for testing only) [*] fixed bug with crashing sender recover sometimes * migrated system contract calls * [*] fixed bug with returning mutable balance object [+] migrated lightclient contracts from bsc [*] fixed parlia consensus config param * [*] fixed tendermint deps * [+] added some logs * [+] enabled bsc forks [*] fixed syscalls from coinbase [*] more logging * Fix call sys contract gas calculation * [*] fixed executing system transactions * [*] enabled receipt hash, gas and bloom filter checks * [-] removed some logging scripts [*] set header checkpoint to 10 million blocks (for testing forks) * [*] fixed bug with commiting dirty inter block state state after system transaction execution [-] removed some extra logs and comments * [+] added chapel and rialto testnet support * [*] fixed chapel allocs * [-] removed 6 mil block limit for headers sync * Fix hardforks on chapel and other testnets * [*] fixed header sync issue after merge * [*] tiny code cleanup * [-] removed some comments * [*] increased mdbx map size to 4 TB * [*] increased max chaindata size to 6 tb * [*] bring more compatibility with origin erigon and some code cleanup * [+] added support of validator mode for BSC chain * [*] enable private key load for bsc, rialto and chapel chains * [*] fixed running BSC validator node * Fix the branch list * [*] tiny fixes for linter * [*] formatted imports for core and parlia packages * [*] fixed import rules in other files * Revert "[*] formatted imports for core and parlia packages" This reverts commit c764b58b34fedc2b14d69458583ba0dad114f227. * [*] changed import rules in more packages * [*] fixed type mismatch in hack command * [*] fixed crash on new epoch, enabled bootstrap flags * [*] fixed linter errors * [*] fixed missing err check for syscalls * [*] now BSC implementation is fully compatible with erigon original sources * Revert "Add chain config and CLI changes for Binance Smart Chain support (#3131)" This reverts commit 3d048b7f1a5e74ca318af96268472e2fb0262d3b. * Revert "Add Parlia consensus engine for Binance Smart Chain support (#3086)" This reverts commit ee99f17fbe0889483004f0ee113e37ad0c5c8283. * [*] fixed several issues after merge * [*] fixed integration compilation * Revert "Fix the branch list" This reverts commit 8150ca57e5f2707a84a9f6a1c5b809b7cc84547b. * [-] removed receipt repair migration * [*] fixed parlia fork numbers output * [*] bring more devel compatibility, fixed bsc address list for access list calculation * [*] fixed bug with commiting state transition for bad blocks in BSC * [*] fixed bsc changes apply for integration command and updated config print for parlia * [*] fixed bug with applying bsc forks for chapel and rialto testnet chains [*] let's use finalize and assemble for mining to let consensus know for what it's finalizing block * Fix compilation errors in hack.go * Fix lint * reset changes in erigon-snapshots to devel * Remove unrelated changes * Fix embed * Remove more unrelated changes * Remove more unrelated changes * Restore clique and aura miner config * Refactor interfaces not to use slice pointers * Refactor parlia functions to return tx and receipt instead of dealing with slices * Fix for header panic * Fix lint, restore system contract addresses * Remove more unrelated changes, unify GatherForks Co-authored-by: Dmitry Ivanov <convexman18@gmail.com> Co-authored-by: j75689 <j75689@gmail.com> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-01-14 19:06:35 +00:00
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/log/v3"
Full BSC support with validator mode (#3233) * migrated consensus and chain config files for bsc support * migrated more files from bsc * fixed consensus crashing * updated erigon lib for parlia snapshot prefix * added staticpeers for bsc * [+] added system contracts [*] fixed bug with loading snapshot [+] enabled gas bailout [+] added fix to prevent syncing more than 1000 headers (for testing only) [*] fixed bug with crashing sender recover sometimes * migrated system contract calls * [*] fixed bug with returning mutable balance object [+] migrated lightclient contracts from bsc [*] fixed parlia consensus config param * [*] fixed tendermint deps * [+] added some logs * [+] enabled bsc forks [*] fixed syscalls from coinbase [*] more logging * Fix call sys contract gas calculation * [*] fixed executing system transactions * [*] enabled receipt hash, gas and bloom filter checks * [-] removed some logging scripts [*] set header checkpoint to 10 million blocks (for testing forks) * [*] fixed bug with commiting dirty inter block state state after system transaction execution [-] removed some extra logs and comments * [+] added chapel and rialto testnet support * [*] fixed chapel allocs * [-] removed 6 mil block limit for headers sync * Fix hardforks on chapel and other testnets * [*] fixed header sync issue after merge * [*] tiny code cleanup * [-] removed some comments * [*] increased mdbx map size to 4 TB * [*] increased max chaindata size to 6 tb * [*] bring more compatibility with origin erigon and some code cleanup * [+] added support of validator mode for BSC chain * [*] enable private key load for bsc, rialto and chapel chains * [*] fixed running BSC validator node * Fix the branch list * [*] tiny fixes for linter * [*] formatted imports for core and parlia packages * [*] fixed import rules in other files * Revert "[*] formatted imports for core and parlia packages" This reverts commit c764b58b34fedc2b14d69458583ba0dad114f227. * [*] changed import rules in more packages * [*] fixed type mismatch in hack command * [*] fixed crash on new epoch, enabled bootstrap flags * [*] fixed linter errors * [*] fixed missing err check for syscalls * [*] now BSC implementation is fully compatible with erigon original sources * Revert "Add chain config and CLI changes for Binance Smart Chain support (#3131)" This reverts commit 3d048b7f1a5e74ca318af96268472e2fb0262d3b. * Revert "Add Parlia consensus engine for Binance Smart Chain support (#3086)" This reverts commit ee99f17fbe0889483004f0ee113e37ad0c5c8283. * [*] fixed several issues after merge * [*] fixed integration compilation * Revert "Fix the branch list" This reverts commit 8150ca57e5f2707a84a9f6a1c5b809b7cc84547b. * [-] removed receipt repair migration * [*] fixed parlia fork numbers output * [*] bring more devel compatibility, fixed bsc address list for access list calculation * [*] fixed bug with commiting state transition for bad blocks in BSC * [*] fixed bsc changes apply for integration command and updated config print for parlia * [*] fixed bug with applying bsc forks for chapel and rialto testnet chains [*] let's use finalize and assemble for mining to let consensus know for what it's finalizing block * Fix compilation errors in hack.go * Fix lint * reset changes in erigon-snapshots to devel * Remove unrelated changes * Fix embed * Remove more unrelated changes * Remove more unrelated changes * Restore clique and aura miner config * Refactor interfaces not to use slice pointers * Refactor parlia functions to return tx and receipt instead of dealing with slices * Fix for header panic * Fix lint, restore system contract addresses * Remove more unrelated changes, unify GatherForks Co-authored-by: Dmitry Ivanov <convexman18@gmail.com> Co-authored-by: j75689 <j75689@gmail.com> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-01-14 19:06:35 +00:00
)
func TestGenesisBlockHashes(t *testing.T) {
2023-11-17 03:52:40 +00:00
t.Parallel()
logger := log.New()
2023-06-14 03:01:00 +00:00
_, db, _ := temporal.NewTestDB(t, datadir.New(t.TempDir()), nil)
check := func(network string) {
genesis := core.GenesisBlockByChainName(network)
tx, err := db.BeginRw(context.Background())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback()
_, block, err := core.WriteGenesisBlock(tx, genesis, nil, "", logger)
require.NoError(t, err)
expect := params.GenesisHashByChainName(network)
require.NotNil(t, expect, network)
require.Equal(t, block.Hash().Bytes(), expect.Bytes(), network)
}
for _, network := range networkname.All {
check(network)
}
}
func TestGenesisBlockRoots(t *testing.T) {
2023-11-17 03:52:40 +00:00
t.Parallel()
require := require.New(t)
var err error
block, _, _ := core.GenesisToBlock(core.MainnetGenesisBlock(), "", log.Root())
if block.Hash() != params.MainnetGenesisHash {
t.Errorf("wrong mainnet genesis hash, got %v, want %v", block.Hash(), params.MainnetGenesisHash)
}
block, _, err = core.GenesisToBlock(core.GnosisGenesisBlock(), "", log.Root())
require.NoError(err)
if block.Root() != params.GnosisGenesisStateRoot {
t.Errorf("wrong Gnosis Chain genesis state root, got %v, want %v", block.Root(), params.GnosisGenesisStateRoot)
}
if block.Hash() != params.GnosisGenesisHash {
t.Errorf("wrong Gnosis Chain genesis hash, got %v, want %v", block.Hash(), params.GnosisGenesisHash)
}
block, _, err = core.GenesisToBlock(core.ChiadoGenesisBlock(), "", log.Root())
require.NoError(err)
if block.Root() != params.ChiadoGenesisStateRoot {
t.Errorf("wrong Chiado genesis state root, got %v, want %v", block.Root(), params.ChiadoGenesisStateRoot)
}
if block.Hash() != params.ChiadoGenesisHash {
t.Errorf("wrong Chiado genesis hash, got %v, want %v", block.Hash(), params.ChiadoGenesisHash)
}
}
func TestCommitGenesisIdempotency(t *testing.T) {
2023-11-17 03:52:40 +00:00
t.Parallel()
logger := log.New()
2023-06-14 03:01:00 +00:00
_, db, _ := temporal.NewTestDB(t, datadir.New(t.TempDir()), nil)
tx, err := db.BeginRw(context.Background())
require.NoError(t, err)
defer tx.Rollback()
genesis := core.GenesisBlockByChainName(networkname.MainnetChainName)
_, _, err = core.WriteGenesisBlock(tx, genesis, nil, "", logger)
require.NoError(t, err)
seq, err := tx.ReadSequence(kv.EthTx)
require.NoError(t, err)
require.Equal(t, uint64(2), seq)
_, _, err = core.WriteGenesisBlock(tx, genesis, nil, "", logger)
require.NoError(t, err)
seq, err = tx.ReadSequence(kv.EthTx)
Full BSC support with validator mode (#3233) * migrated consensus and chain config files for bsc support * migrated more files from bsc * fixed consensus crashing * updated erigon lib for parlia snapshot prefix * added staticpeers for bsc * [+] added system contracts [*] fixed bug with loading snapshot [+] enabled gas bailout [+] added fix to prevent syncing more than 1000 headers (for testing only) [*] fixed bug with crashing sender recover sometimes * migrated system contract calls * [*] fixed bug with returning mutable balance object [+] migrated lightclient contracts from bsc [*] fixed parlia consensus config param * [*] fixed tendermint deps * [+] added some logs * [+] enabled bsc forks [*] fixed syscalls from coinbase [*] more logging * Fix call sys contract gas calculation * [*] fixed executing system transactions * [*] enabled receipt hash, gas and bloom filter checks * [-] removed some logging scripts [*] set header checkpoint to 10 million blocks (for testing forks) * [*] fixed bug with commiting dirty inter block state state after system transaction execution [-] removed some extra logs and comments * [+] added chapel and rialto testnet support * [*] fixed chapel allocs * [-] removed 6 mil block limit for headers sync * Fix hardforks on chapel and other testnets * [*] fixed header sync issue after merge * [*] tiny code cleanup * [-] removed some comments * [*] increased mdbx map size to 4 TB * [*] increased max chaindata size to 6 tb * [*] bring more compatibility with origin erigon and some code cleanup * [+] added support of validator mode for BSC chain * [*] enable private key load for bsc, rialto and chapel chains * [*] fixed running BSC validator node * Fix the branch list * [*] tiny fixes for linter * [*] formatted imports for core and parlia packages * [*] fixed import rules in other files * Revert "[*] formatted imports for core and parlia packages" This reverts commit c764b58b34fedc2b14d69458583ba0dad114f227. * [*] changed import rules in more packages * [*] fixed type mismatch in hack command * [*] fixed crash on new epoch, enabled bootstrap flags * [*] fixed linter errors * [*] fixed missing err check for syscalls * [*] now BSC implementation is fully compatible with erigon original sources * Revert "Add chain config and CLI changes for Binance Smart Chain support (#3131)" This reverts commit 3d048b7f1a5e74ca318af96268472e2fb0262d3b. * Revert "Add Parlia consensus engine for Binance Smart Chain support (#3086)" This reverts commit ee99f17fbe0889483004f0ee113e37ad0c5c8283. * [*] fixed several issues after merge * [*] fixed integration compilation * Revert "Fix the branch list" This reverts commit 8150ca57e5f2707a84a9f6a1c5b809b7cc84547b. * [-] removed receipt repair migration * [*] fixed parlia fork numbers output * [*] bring more devel compatibility, fixed bsc address list for access list calculation * [*] fixed bug with commiting state transition for bad blocks in BSC * [*] fixed bsc changes apply for integration command and updated config print for parlia * [*] fixed bug with applying bsc forks for chapel and rialto testnet chains [*] let's use finalize and assemble for mining to let consensus know for what it's finalizing block * Fix compilation errors in hack.go * Fix lint * reset changes in erigon-snapshots to devel * Remove unrelated changes * Fix embed * Remove more unrelated changes * Remove more unrelated changes * Restore clique and aura miner config * Refactor interfaces not to use slice pointers * Refactor parlia functions to return tx and receipt instead of dealing with slices * Fix for header panic * Fix lint, restore system contract addresses * Remove more unrelated changes, unify GatherForks Co-authored-by: Dmitry Ivanov <convexman18@gmail.com> Co-authored-by: j75689 <j75689@gmail.com> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-01-14 19:06:35 +00:00
require.NoError(t, err)
require.Equal(t, uint64(2), seq)
Full BSC support with validator mode (#3233) * migrated consensus and chain config files for bsc support * migrated more files from bsc * fixed consensus crashing * updated erigon lib for parlia snapshot prefix * added staticpeers for bsc * [+] added system contracts [*] fixed bug with loading snapshot [+] enabled gas bailout [+] added fix to prevent syncing more than 1000 headers (for testing only) [*] fixed bug with crashing sender recover sometimes * migrated system contract calls * [*] fixed bug with returning mutable balance object [+] migrated lightclient contracts from bsc [*] fixed parlia consensus config param * [*] fixed tendermint deps * [+] added some logs * [+] enabled bsc forks [*] fixed syscalls from coinbase [*] more logging * Fix call sys contract gas calculation * [*] fixed executing system transactions * [*] enabled receipt hash, gas and bloom filter checks * [-] removed some logging scripts [*] set header checkpoint to 10 million blocks (for testing forks) * [*] fixed bug with commiting dirty inter block state state after system transaction execution [-] removed some extra logs and comments * [+] added chapel and rialto testnet support * [*] fixed chapel allocs * [-] removed 6 mil block limit for headers sync * Fix hardforks on chapel and other testnets * [*] fixed header sync issue after merge * [*] tiny code cleanup * [-] removed some comments * [*] increased mdbx map size to 4 TB * [*] increased max chaindata size to 6 tb * [*] bring more compatibility with origin erigon and some code cleanup * [+] added support of validator mode for BSC chain * [*] enable private key load for bsc, rialto and chapel chains * [*] fixed running BSC validator node * Fix the branch list * [*] tiny fixes for linter * [*] formatted imports for core and parlia packages * [*] fixed import rules in other files * Revert "[*] formatted imports for core and parlia packages" This reverts commit c764b58b34fedc2b14d69458583ba0dad114f227. * [*] changed import rules in more packages * [*] fixed type mismatch in hack command * [*] fixed crash on new epoch, enabled bootstrap flags * [*] fixed linter errors * [*] fixed missing err check for syscalls * [*] now BSC implementation is fully compatible with erigon original sources * Revert "Add chain config and CLI changes for Binance Smart Chain support (#3131)" This reverts commit 3d048b7f1a5e74ca318af96268472e2fb0262d3b. * Revert "Add Parlia consensus engine for Binance Smart Chain support (#3086)" This reverts commit ee99f17fbe0889483004f0ee113e37ad0c5c8283. * [*] fixed several issues after merge * [*] fixed integration compilation * Revert "Fix the branch list" This reverts commit 8150ca57e5f2707a84a9f6a1c5b809b7cc84547b. * [-] removed receipt repair migration * [*] fixed parlia fork numbers output * [*] bring more devel compatibility, fixed bsc address list for access list calculation * [*] fixed bug with commiting state transition for bad blocks in BSC * [*] fixed bsc changes apply for integration command and updated config print for parlia * [*] fixed bug with applying bsc forks for chapel and rialto testnet chains [*] let's use finalize and assemble for mining to let consensus know for what it's finalizing block * Fix compilation errors in hack.go * Fix lint * reset changes in erigon-snapshots to devel * Remove unrelated changes * Fix embed * Remove more unrelated changes * Remove more unrelated changes * Restore clique and aura miner config * Refactor interfaces not to use slice pointers * Refactor parlia functions to return tx and receipt instead of dealing with slices * Fix for header panic * Fix lint, restore system contract addresses * Remove more unrelated changes, unify GatherForks Co-authored-by: Dmitry Ivanov <convexman18@gmail.com> Co-authored-by: j75689 <j75689@gmail.com> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-01-14 19:06:35 +00:00
}
func TestAllocConstructor(t *testing.T) {
2023-11-17 03:52:40 +00:00
t.Parallel()
require := require.New(t)
assert := assert.New(t)
logger := log.New()
// This deployment code initially sets contract's 0th storage to 0x2a
// and its 1st storage to 0x01c9.
deploymentCode := common.FromHex("602a5f556101c960015560048060135f395ff35f355f55")
funds := big.NewInt(1000000000)
address := libcommon.HexToAddress("0x1000000000000000000000000000000000000001")
genSpec := &types.Genesis{
Config: params.AllProtocolChanges,
Alloc: types.GenesisAlloc{
address: {Constructor: deploymentCode, Balance: funds},
},
}
2023-06-14 03:01:00 +00:00
historyV3, db, _ := temporal.NewTestDB(t, datadir.New(t.TempDir()), nil)
_, _, err := core.CommitGenesisBlock(db, genSpec, "", logger)
require.NoError(err)
tx, err := db.BeginRo(context.Background())
require.NoError(err)
defer tx.Rollback()
//TODO: support historyV3
reader, err := rpchelper.CreateHistoryStateReader(tx, 1, 0, historyV3, genSpec.Config.ChainName)
require.NoError(err)
state := state.New(reader)
balance := state.GetBalance(address)
assert.Equal(funds, balance.ToBig())
code := state.GetCode(address)
assert.Equal(common.FromHex("5f355f55"), code)
key0 := libcommon.HexToHash("0000000000000000000000000000000000000000000000000000000000000000")
storage0 := &uint256.Int{}
state.GetState(address, &key0, storage0)
assert.Equal(uint256.NewInt(0x2a), storage0)
key1 := libcommon.HexToHash("0000000000000000000000000000000000000000000000000000000000000001")
storage1 := &uint256.Int{}
state.GetState(address, &key1, storage1)
assert.Equal(uint256.NewInt(0x01c9), storage1)
}