From b67191ea844e24c1640d92c45aafdfcfbefca650 Mon Sep 17 00:00:00 2001 From: ramtinms Date: Mon, 12 Aug 2024 11:18:24 -0700 Subject: [PATCH 1/8] update genesis block info --- fvm/evm/types/block.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fvm/evm/types/block.go b/fvm/evm/types/block.go index 6baacfb4761..f0f4972795b 100644 --- a/fvm/evm/types/block.go +++ b/fvm/evm/types/block.go @@ -3,6 +3,7 @@ package types import ( "bytes" "math/big" + "time" gethCommon "github.com/onflow/go-ethereum/common" gethTypes "github.com/onflow/go-ethereum/core/types" @@ -87,12 +88,17 @@ func NewBlockFromBytes(encoded []byte) (*Block, error) { return res, nil } +var GenesisTimeStamp = uint64(time.Date(2024, time.August, 1, 0, 0, 0, 0, time.UTC).Unix()) + // GenesisBlock is the genesis block in the EVM environment var GenesisBlock = &Block{ - ParentBlockHash: gethCommon.Hash{}, - Height: uint64(0), - TotalSupply: new(big.Int), - ReceiptRoot: gethTypes.EmptyRootHash, + ParentBlockHash: gethCommon.Hash{}, + Height: uint64(0), + Timestamp: GenesisTimeStamp, + TotalSupply: new(big.Int), + ReceiptRoot: gethTypes.EmptyRootHash, + TransactionHashRoot: gethTypes.EmptyRootHash, + TotalGasUsed: 0, } var GenesisBlockHash, _ = GenesisBlock.Hash() From dbe5cd5ed5ece6ebee45902baf789ba397a8871a Mon Sep 17 00:00:00 2001 From: ramtinms Date: Mon, 12 Aug 2024 11:35:36 -0700 Subject: [PATCH 2/8] make genesis block chain dependent --- fvm/evm/evm.go | 2 +- fvm/evm/handler/blockstore.go | 26 ++++++++---- fvm/evm/handler/blockstore_benchmark_test.go | 2 +- fvm/evm/handler/blockstore_test.go | 23 ++++++----- fvm/evm/handler/handler_test.go | 36 +++++++++-------- fvm/evm/types/block.go | 42 ++++++++++++++------ fvm/evm/types/block_test.go | 13 +++--- 7 files changed, 90 insertions(+), 54 deletions(-) diff --git a/fvm/evm/evm.go b/fvm/evm/evm.go index d18d6260cc2..3efee341ce9 100644 --- a/fvm/evm/evm.go +++ b/fvm/evm/evm.go @@ -36,7 +36,7 @@ func SetupEnvironment( backend := backends.NewWrappedEnvironment(fvmEnv) emulator := evm.NewEmulator(backend, StorageAccountAddress(chainID)) - blockStore := handler.NewBlockStore(backend, StorageAccountAddress(chainID)) + blockStore := handler.NewBlockStore(chainID, backend, StorageAccountAddress(chainID)) addressAllocator := handler.NewAddressAllocator() if tracer != debug.NopTracer { diff --git a/fvm/evm/handler/blockstore.go b/fvm/evm/handler/blockstore.go index fe6bed4e145..588ae93277f 100644 --- a/fvm/evm/handler/blockstore.go +++ b/fvm/evm/handler/blockstore.go @@ -18,6 +18,7 @@ const ( ) type BlockStore struct { + chainID flow.ChainID backend types.Backend rootAddress flow.Address } @@ -25,8 +26,13 @@ type BlockStore struct { var _ types.BlockStore = &BlockStore{} // NewBlockStore constructs a new block store -func NewBlockStore(backend types.Backend, rootAddress flow.Address) *BlockStore { +func NewBlockStore( + chainID flow.ChainID, + backend types.Backend, + rootAddress flow.Address, +) *BlockStore { return &BlockStore{ + chainID: chainID, backend: backend, rootAddress: rootAddress, } @@ -145,7 +151,7 @@ func (bs *BlockStore) LatestBlock() (*types.Block, error) { return nil, err } if len(data) == 0 { - return types.GenesisBlock, nil + return types.GenesisBlock(bs.chainID), nil } return types.NewBlockFromBytes(data) } @@ -171,10 +177,13 @@ func (bs *BlockStore) getBlockHashList() (*BlockHashList, error) { // return nil, err // } // if bhl.IsEmpty() { - // err = bhl.Push(types.GenesisBlock.Height, types.GenesisBlockHash) - // if err != nil { - // return nil, err - // } + // err = bhl.Push( + // types.GenesisBlock(bs.chainID).Height, + // types.GenesisBlockHash(bs.chainID), + // ) + // if err != nil { + // return nil, err + // } // } // return bhl, nil } @@ -192,7 +201,10 @@ func (bs *BlockStore) checkLegacyAndMigrate() (*BlockHashList, error) { return nil, err } if bhl.IsEmpty() { - err = bhl.Push(types.GenesisBlock.Height, types.GenesisBlockHash) + err = bhl.Push( + types.GenesisBlock(bs.chainID).Height, + types.GenesisBlockHash(bs.chainID), + ) if err != nil { return nil, err } diff --git a/fvm/evm/handler/blockstore_benchmark_test.go b/fvm/evm/handler/blockstore_benchmark_test.go index e55c2204205..013b6326b0a 100644 --- a/fvm/evm/handler/blockstore_benchmark_test.go +++ b/fvm/evm/handler/blockstore_benchmark_test.go @@ -17,7 +17,7 @@ func benchmarkBlockProposalGrowth(b *testing.B, txCounts int) { testutils.RunWithTestBackend(b, func(backend *testutils.TestBackend) { testutils.RunWithTestFlowEVMRootAddress(b, backend, func(rootAddr flow.Address) { - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(flow.Testnet, backend, rootAddr) for i := 0; i < txCounts; i++ { bp, err := bs.BlockProposal() require.NoError(b, err) diff --git a/fvm/evm/handler/blockstore_test.go b/fvm/evm/handler/blockstore_test.go index a5123f5d558..bb8c9a0deac 100644 --- a/fvm/evm/handler/blockstore_test.go +++ b/fvm/evm/handler/blockstore_test.go @@ -16,23 +16,24 @@ import ( func TestBlockStore(t *testing.T) { + var chainID = flow.Testnet testutils.RunWithTestBackend(t, func(backend *testutils.TestBackend) { testutils.RunWithTestFlowEVMRootAddress(t, backend, func(root flow.Address) { - bs := handler.NewBlockStore(backend, root) + bs := handler.NewBlockStore(chainID, backend, root) // check the Genesis block b, err := bs.LatestBlock() require.NoError(t, err) - require.Equal(t, types.GenesisBlock, b) + require.Equal(t, types.GenesisBlock(chainID), b) h, err := bs.BlockHash(0) require.NoError(t, err) - require.Equal(t, types.GenesisBlockHash, h) + require.Equal(t, types.GenesisBlockHash(chainID), h) // test block proposal construction from the Genesis block bp, err := bs.BlockProposal() require.NoError(t, err) require.Equal(t, uint64(1), bp.Height) - expectedParentHash, err := types.GenesisBlock.Hash() + expectedParentHash, err := types.GenesisBlock(chainID).Hash() require.NoError(t, err) require.Equal(t, expectedParentHash, bp.ParentBlockHash) @@ -47,7 +48,7 @@ func TestBlockStore(t *testing.T) { require.NoError(t, err) // reset the bs and check if it still return the block proposal - bs = handler.NewBlockStore(backend, root) + bs = handler.NewBlockStore(chainID, backend, root) retbp, err = bs.BlockProposal() require.NoError(t, err) require.Equal(t, bp, retbp) @@ -60,7 +61,7 @@ func TestBlockStore(t *testing.T) { // this should still return the genesis block retb, err := bs.LatestBlock() require.NoError(t, err) - require.Equal(t, types.GenesisBlock, retb) + require.Equal(t, types.GenesisBlock(chainID), retb) // commit the changes err = bs.CommitBlockProposal(bp) @@ -78,7 +79,7 @@ func TestBlockStore(t *testing.T) { // genesis h, err = bs.BlockHash(0) require.NoError(t, err) - require.Equal(t, types.GenesisBlockHash, h) + require.Equal(t, types.GenesisBlockHash(chainID), h) // block 1 h, err = bs.BlockHash(1) @@ -99,6 +100,7 @@ func TestBlockStore(t *testing.T) { // TODO: we can remove this when the previewnet is out func TestBlockStoreMigration(t *testing.T) { + var chainID = flow.Testnet testutils.RunWithTestBackend(t, func(backend *testutils.TestBackend) { testutils.RunWithTestFlowEVMRootAddress(t, backend, func(root flow.Address) { legacyCapacity := 16 @@ -114,7 +116,7 @@ func TestBlockStoreMigration(t *testing.T) { legacy.Encode(), ) require.NoError(t, err) - bs := handler.NewBlockStore(backend, root) + bs := handler.NewBlockStore(chainID, backend, root) for i := 0; i <= maxHeightAdded-legacyCapacity; i++ { h, err := bs.BlockHash(uint64(i)) @@ -138,10 +140,11 @@ func TestBlockStoreMigration(t *testing.T) { // and storage of blocks works as it should, the breaking change was introduced // in this PR https://github.com/onflow/flow-go/pull/5660 func TestBlockStore_AddedTimestamp(t *testing.T) { + var chainID = flow.Testnet testutils.RunWithTestBackend(t, func(backend *testutils.TestBackend) { testutils.RunWithTestFlowEVMRootAddress(t, backend, func(root flow.Address) { - bs := handler.NewBlockStore(backend, root) + bs := handler.NewBlockStore(chainID, backend, root) // block type before breaking change (no timestamp and total gas used) type oldBlockV1 struct { @@ -154,7 +157,7 @@ func TestBlockStore_AddedTimestamp(t *testing.T) { TransactionHashes []gethCommon.Hash } - g := types.GenesisBlock + g := types.GenesisBlock(chainID) h, err := g.Hash() require.NoError(t, err) diff --git a/fvm/evm/handler/handler_test.go b/fvm/evm/handler/handler_test.go index 364255c7376..62e006fd49e 100644 --- a/fvm/evm/handler/handler_test.go +++ b/fvm/evm/handler/handler_test.go @@ -35,6 +35,8 @@ import ( var flowTokenAddress = common.MustBytesToAddress(systemcontracts.SystemContractsForChain(flow.Emulator).FlowToken.Address.Bytes()) var randomBeaconAddress = systemcontracts.SystemContractsForChain(flow.Emulator).RandomBeaconHistory.Address +const defaultChainID = flow.Testnet + func TestHandler_TransactionRunOrPanic(t *testing.T) { t.Parallel() @@ -47,7 +49,7 @@ func TestHandler_TransactionRunOrPanic(t *testing.T) { sc := systemcontracts.SystemContractsForChain(flow.Emulator) - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(defaultChainID, backend, rootAddr) aa := handler.NewAddressAllocator() @@ -125,7 +127,7 @@ func TestHandler_TransactionRunOrPanic(t *testing.T) { testutils.RunWithTestBackend(t, func(backend *testutils.TestBackend) { testutils.RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) { testutils.RunWithEOATestAccount(t, backend, rootAddr, func(eoa *testutils.EOATestAccount) { - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(defaultChainID, backend, rootAddr) aa := handler.NewAddressAllocator() em := &testutils.TestEmulator{ RunTransactionFunc: func(tx *gethTypes.Transaction) (*types.Result, error) { @@ -184,7 +186,7 @@ func TestHandler_TransactionRunOrPanic(t *testing.T) { testutils.RunWithTestBackend(t, func(backend *testutils.TestBackend) { testutils.RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) { testutils.RunWithEOATestAccount(t, backend, rootAddr, func(eoa *testutils.EOATestAccount) { - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(defaultChainID, backend, rootAddr) aa := handler.NewAddressAllocator() em := &testutils.TestEmulator{ RunTransactionFunc: func(tx *gethTypes.Transaction) (*types.Result, error) { @@ -278,7 +280,7 @@ func TestHandler_OpsWithoutEmulator(t *testing.T) { // test call last executed block without initialization b := handler.LastExecutedBlock() - require.Equal(t, types.GenesisBlock, b) + require.Equal(t, types.GenesisBlock(defaultChainID), b) // do some changes address := testutils.RandomAddress(t) @@ -452,7 +454,7 @@ func TestHandler_COA(t *testing.T) { testutils.RunWithTestBackend(t, func(backend *testutils.TestBackend) { testutils.RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) { testutils.RunWithEOATestAccount(t, backend, rootAddr, func(eoa *testutils.EOATestAccount) { - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(defaultChainID, backend, rootAddr) aa := handler.NewAddressAllocator() // Withdraw calls are only possible within FOA accounts @@ -530,7 +532,7 @@ func TestHandler_COA(t *testing.T) { testutils.RunWithTestBackend(t, func(backend *testutils.TestBackend) { testutils.RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) { testutils.RunWithEOATestAccount(t, backend, rootAddr, func(eoa *testutils.EOATestAccount) { - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(defaultChainID, backend, rootAddr) aa := handler.NewAddressAllocator() // test non fatal error of emulator @@ -723,7 +725,7 @@ func TestHandler_TransactionRun(t *testing.T) { testutils.RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) { testutils.RunWithEOATestAccount(t, backend, rootAddr, func(eoa *testutils.EOATestAccount) { - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(chainID, backend, rootAddr) aa := handler.NewAddressAllocator() result := &types.Result{ @@ -767,7 +769,7 @@ func TestHandler_TransactionRun(t *testing.T) { testutils.RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) { testutils.RunWithEOATestAccount(t, backend, rootAddr, func(eoa *testutils.EOATestAccount) { - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(chainID, backend, rootAddr) aa := handler.NewAddressAllocator() result := &types.Result{ @@ -812,7 +814,7 @@ func TestHandler_TransactionRun(t *testing.T) { testutils.RunWithTestBackend(t, func(backend *testutils.TestBackend) { testutils.RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) { testutils.RunWithEOATestAccount(t, backend, rootAddr, func(eoa *testutils.EOATestAccount) { - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(chainID, backend, rootAddr) aa := handler.NewAddressAllocator() evmErr := fmt.Errorf("%w: next nonce %v, tx nonce %v", gethCore.ErrNonceTooLow, 1, 0) em := &testutils.TestEmulator{ @@ -864,7 +866,7 @@ func TestHandler_TransactionRun(t *testing.T) { testutils.RunWithEOATestAccount(t, backend, rootAddr, func(eoa *testutils.EOATestAccount) { sc := systemcontracts.SystemContractsForChain(chainID) - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(chainID, backend, rootAddr) aa := handler.NewAddressAllocator() gasConsumed := testutils.RandomGas(1000) @@ -965,7 +967,7 @@ func TestHandler_TransactionRun(t *testing.T) { testutils.RunWithTestBackend(t, func(backend *testutils.TestBackend) { testutils.RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) { testutils.RunWithEOATestAccount(t, backend, rootAddr, func(eoa *testutils.EOATestAccount) { - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(chainID, backend, rootAddr) aa := handler.NewAddressAllocator() gasConsumed := testutils.RandomGas(1000) @@ -1012,7 +1014,7 @@ func TestHandler_TransactionRun(t *testing.T) { testutils.RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) { testutils.RunWithEOATestAccount(t, backend, rootAddr, func(eoa *testutils.EOATestAccount) { - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(defaultChainID, backend, rootAddr) aa := handler.NewAddressAllocator() nonce := uint64(1) @@ -1104,7 +1106,7 @@ func TestHandler_TransactionRun(t *testing.T) { require.NoError(t, err) tracer.WithBlockID(blockID) - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(chainID, backend, rootAddr) aa := handler.NewAddressAllocator() em := &testutils.TestEmulator{ @@ -1174,7 +1176,7 @@ func TestHandler_TransactionRun(t *testing.T) { require.NoError(t, err) tracer.WithBlockID(flow.Identifier{0x1}) - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(defaultChainID, backend, rootAddr) aa := handler.NewAddressAllocator() em := &testutils.TestEmulator{ @@ -1213,7 +1215,7 @@ func TestHandler_TransactionRun(t *testing.T) { testutils.RunWithTestBackend(t, func(backend *testutils.TestBackend) { testutils.RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) { testutils.RunWithEOATestAccount(t, backend, rootAddr, func(eoa *testutils.EOATestAccount) { - bs := handler.NewBlockStore(backend, rootAddr) + bs := handler.NewBlockStore(defaultChainID, backend, rootAddr) aa := handler.NewAddressAllocator() const batchSize = 3 @@ -1375,7 +1377,7 @@ func TestHandler_Metrics(t *testing.T) { rootAddr, flowTokenAddress, rootAddr, - handler.NewBlockStore(backend, rootAddr), + handler.NewBlockStore(defaultChainID, backend, rootAddr), handler.NewAddressAllocator(), backend, em, @@ -1467,7 +1469,7 @@ func SetupHandler(t testing.TB, backend types.Backend, rootAddr flow.Address) *h rootAddr, flowTokenAddress, rootAddr, - handler.NewBlockStore(backend, rootAddr), + handler.NewBlockStore(defaultChainID, backend, rootAddr), handler.NewAddressAllocator(), backend, emulator.NewEmulator(backend, rootAddr), diff --git a/fvm/evm/types/block.go b/fvm/evm/types/block.go index f0f4972795b..8c5ca399b05 100644 --- a/fvm/evm/types/block.go +++ b/fvm/evm/types/block.go @@ -5,6 +5,7 @@ import ( "math/big" "time" + "github.com/onflow/flow-go/model/flow" gethCommon "github.com/onflow/go-ethereum/common" gethTypes "github.com/onflow/go-ethereum/core/types" gethCrypto "github.com/onflow/go-ethereum/crypto" @@ -88,20 +89,37 @@ func NewBlockFromBytes(encoded []byte) (*Block, error) { return res, nil } -var GenesisTimeStamp = uint64(time.Date(2024, time.August, 1, 0, 0, 0, 0, time.UTC).Unix()) - -// GenesisBlock is the genesis block in the EVM environment -var GenesisBlock = &Block{ - ParentBlockHash: gethCommon.Hash{}, - Height: uint64(0), - Timestamp: GenesisTimeStamp, - TotalSupply: new(big.Int), - ReceiptRoot: gethTypes.EmptyRootHash, - TransactionHashRoot: gethTypes.EmptyRootHash, - TotalGasUsed: 0, +// GenesisTimeStamp returns the block time stamp for EVM genesis block +func GenesisTimeStamp(flowChainID flow.ChainID) uint64 { + // default evm chain ID is previewNet + switch flowChainID { + case flow.Mainnet: + return uint64(time.Date(2024, time.August, 1, 0, 0, 0, 0, time.UTC).Unix()) + case flow.Testnet: + return uint64(time.Date(2024, time.September, 1, 0, 0, 0, 0, time.UTC).Unix()) + default: + return 0 + } } -var GenesisBlockHash, _ = GenesisBlock.Hash() +// GenesisBlock returns the genesis block in the EVM environment +func GenesisBlock(chainID flow.ChainID) *Block { + return &Block{ + ParentBlockHash: gethCommon.Hash{}, + Height: uint64(0), + Timestamp: GenesisTimeStamp(chainID), + TotalSupply: new(big.Int), + ReceiptRoot: gethTypes.EmptyRootHash, + TransactionHashRoot: gethTypes.EmptyRootHash, + TotalGasUsed: 0, + } +} + +// GenesisBlockHash returns the genesis block hash in the EVM environment +func GenesisBlockHash(chainID flow.ChainID) gethCommon.Hash { + h, _ := GenesisBlock(chainID).Hash() + return h +} // BlockProposal is a EVM block proposal // holding all the interim data of block before commitment diff --git a/fvm/evm/types/block_test.go b/fvm/evm/types/block_test.go index 38af86f8326..e227a038757 100644 --- a/fvm/evm/types/block_test.go +++ b/fvm/evm/types/block_test.go @@ -4,6 +4,7 @@ import ( "math/big" "testing" + "github.com/onflow/flow-go/model/flow" gethCommon "github.com/onflow/go-ethereum/common" gethTypes "github.com/onflow/go-ethereum/core/types" gethRLP "github.com/onflow/go-ethereum/rlp" @@ -60,7 +61,7 @@ func Test_BlockProposal(t *testing.T) { func Test_DecodeBlocks(t *testing.T) { bv0 := blockV0{ - ParentBlockHash: GenesisBlockHash, + ParentBlockHash: GenesisBlockHash(flow.Previewnet.Chain().ChainID()), Height: 1, UUIDIndex: 2, TotalSupply: 3, @@ -79,7 +80,7 @@ func Test_DecodeBlocks(t *testing.T) { require.Empty(t, b.TotalGasUsed) bv1 := blockV1{ - ParentBlockHash: GenesisBlockHash, + ParentBlockHash: GenesisBlockHash(flow.Previewnet.Chain().ChainID()), Height: 1, UUIDIndex: 2, TotalSupply: 3, @@ -100,7 +101,7 @@ func Test_DecodeBlocks(t *testing.T) { require.Empty(t, b.TotalGasUsed) bv2 := blockV2{ - ParentBlockHash: GenesisBlockHash, + ParentBlockHash: GenesisBlockHash(flow.Previewnet.Chain().ChainID()), Height: 1, TotalSupply: 2, StateRoot: gethCommon.Hash{0x01}, @@ -120,7 +121,7 @@ func Test_DecodeBlocks(t *testing.T) { require.Empty(t, b.TotalGasUsed) bv3 := blockV3{ - ParentBlockHash: GenesisBlockHash, + ParentBlockHash: GenesisBlockHash(flow.Previewnet.Chain().ChainID()), Height: 1, TotalSupply: 2, ReceiptRoot: gethCommon.Hash{0x02}, @@ -139,7 +140,7 @@ func Test_DecodeBlocks(t *testing.T) { require.Empty(t, b.TotalGasUsed) bv4 := blockV4{ - ParentBlockHash: GenesisBlockHash, + ParentBlockHash: GenesisBlockHash(flow.Previewnet.Chain().ChainID()), Height: 1, TotalSupply: big.NewInt(4), ReceiptRoot: gethCommon.Hash{0x02}, @@ -158,7 +159,7 @@ func Test_DecodeBlocks(t *testing.T) { require.Empty(t, b.TotalGasUsed) bv5 := blockV5{ - ParentBlockHash: GenesisBlockHash, + ParentBlockHash: GenesisBlockHash(flow.Previewnet.Chain().ChainID()), Height: 1, TotalSupply: big.NewInt(2), ReceiptRoot: gethCommon.Hash{0x02}, From 00d55ec568b9efabd77028c78b010b6feaa79358 Mon Sep 17 00:00:00 2001 From: ramtinms Date: Mon, 12 Aug 2024 23:42:25 -0700 Subject: [PATCH 3/8] hot fix --- fvm/evm/types/block.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fvm/evm/types/block.go b/fvm/evm/types/block.go index 8c5ca399b05..2c7e10e77eb 100644 --- a/fvm/evm/types/block.go +++ b/fvm/evm/types/block.go @@ -93,9 +93,9 @@ func NewBlockFromBytes(encoded []byte) (*Block, error) { func GenesisTimeStamp(flowChainID flow.ChainID) uint64 { // default evm chain ID is previewNet switch flowChainID { - case flow.Mainnet: - return uint64(time.Date(2024, time.August, 1, 0, 0, 0, 0, time.UTC).Unix()) case flow.Testnet: + return uint64(time.Date(2024, time.August, 1, 0, 0, 0, 0, time.UTC).Unix()) + case flow.Mainnet: return uint64(time.Date(2024, time.September, 1, 0, 0, 0, 0, time.UTC).Unix()) default: return 0 From a392a4222cff2f7eab0297c6b1fc46cc162c4941 Mon Sep 17 00:00:00 2001 From: ramtinms Date: Mon, 12 Aug 2024 23:50:06 -0700 Subject: [PATCH 4/8] lint fix --- fvm/evm/types/block.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fvm/evm/types/block.go b/fvm/evm/types/block.go index 2c7e10e77eb..5706020f63f 100644 --- a/fvm/evm/types/block.go +++ b/fvm/evm/types/block.go @@ -5,12 +5,13 @@ import ( "math/big" "time" - "github.com/onflow/flow-go/model/flow" gethCommon "github.com/onflow/go-ethereum/common" gethTypes "github.com/onflow/go-ethereum/core/types" gethCrypto "github.com/onflow/go-ethereum/crypto" gethRLP "github.com/onflow/go-ethereum/rlp" gethTrie "github.com/onflow/go-ethereum/trie" + + "github.com/onflow/flow-go/model/flow" ) // Block represents a evm block. From 5a107246ab61b427df7d41e9c67e4f1a6c089e1e Mon Sep 17 00:00:00 2001 From: ramtinms Date: Mon, 12 Aug 2024 23:55:33 -0700 Subject: [PATCH 5/8] typo --- fvm/evm/types/block.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fvm/evm/types/block.go b/fvm/evm/types/block.go index 5706020f63f..3cd9111b6fb 100644 --- a/fvm/evm/types/block.go +++ b/fvm/evm/types/block.go @@ -90,8 +90,8 @@ func NewBlockFromBytes(encoded []byte) (*Block, error) { return res, nil } -// GenesisTimeStamp returns the block time stamp for EVM genesis block -func GenesisTimeStamp(flowChainID flow.ChainID) uint64 { +// GenesisTimestamp returns the block time stamp for EVM genesis block +func GenesisTimestamp(flowChainID flow.ChainID) uint64 { // default evm chain ID is previewNet switch flowChainID { case flow.Testnet: @@ -108,7 +108,7 @@ func GenesisBlock(chainID flow.ChainID) *Block { return &Block{ ParentBlockHash: gethCommon.Hash{}, Height: uint64(0), - Timestamp: GenesisTimeStamp(chainID), + Timestamp: GenesisTimestamp(chainID), TotalSupply: new(big.Int), ReceiptRoot: gethTypes.EmptyRootHash, TransactionHashRoot: gethTypes.EmptyRootHash, From d38e325e355707f8740c5d3bacc07870b24d63c6 Mon Sep 17 00:00:00 2001 From: ramtinms Date: Mon, 12 Aug 2024 23:57:06 -0700 Subject: [PATCH 6/8] handle error --- fvm/evm/types/block.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fvm/evm/types/block.go b/fvm/evm/types/block.go index 3cd9111b6fb..0cd6410b7af 100644 --- a/fvm/evm/types/block.go +++ b/fvm/evm/types/block.go @@ -118,7 +118,10 @@ func GenesisBlock(chainID flow.ChainID) *Block { // GenesisBlockHash returns the genesis block hash in the EVM environment func GenesisBlockHash(chainID flow.ChainID) gethCommon.Hash { - h, _ := GenesisBlock(chainID).Hash() + h, err := GenesisBlock(chainID).Hash() + if err != nil { // this never happens + panic(err) + } return h } From 15c93a312536a5b95d427793d450868eefdfdfaf Mon Sep 17 00:00:00 2001 From: ramtinms Date: Tue, 13 Aug 2024 00:03:19 -0700 Subject: [PATCH 7/8] add test for genesis block --- fvm/evm/types/block_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/fvm/evm/types/block_test.go b/fvm/evm/types/block_test.go index e227a038757..0adfea282c3 100644 --- a/fvm/evm/types/block_test.go +++ b/fvm/evm/types/block_test.go @@ -12,6 +12,24 @@ import ( "github.com/stretchr/testify/require" ) +func Test_GenesisBlock(t *testing.T) { + testnetGenesis := GenesisBlock(flow.Testnet) + require.Equal(t, testnetGenesis.Timestamp, GenesisTimestamp(flow.Testnet)) + testnetGenesisHash := GenesisBlockHash(flow.Testnet) + h, err := testnetGenesis.Hash() + require.NoError(t, err) + require.Equal(t, h, testnetGenesisHash) + + mainnetGenesis := GenesisBlock(flow.Mainnet) + require.Equal(t, mainnetGenesis.Timestamp, GenesisTimestamp(flow.Mainnet)) + mainnetGenesisHash := GenesisBlockHash(flow.Mainnet) + h, err = mainnetGenesis.Hash() + require.NoError(t, err) + require.Equal(t, h, mainnetGenesisHash) + + assert.NotEqual(t, testnetGenesisHash, mainnetGenesisHash) +} + func Test_BlockHash(t *testing.T) { b := Block{ ParentBlockHash: gethCommon.HexToHash("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), From f1e673e06680ef0bdb2ccbc206e132bd0a9310eb Mon Sep 17 00:00:00 2001 From: ramtinms Date: Tue, 13 Aug 2024 00:17:29 -0700 Subject: [PATCH 8/8] lint fix --- fvm/evm/types/block_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fvm/evm/types/block_test.go b/fvm/evm/types/block_test.go index 0adfea282c3..3d95568b5cd 100644 --- a/fvm/evm/types/block_test.go +++ b/fvm/evm/types/block_test.go @@ -4,12 +4,13 @@ import ( "math/big" "testing" - "github.com/onflow/flow-go/model/flow" gethCommon "github.com/onflow/go-ethereum/common" gethTypes "github.com/onflow/go-ethereum/core/types" gethRLP "github.com/onflow/go-ethereum/rlp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/onflow/flow-go/model/flow" ) func Test_GenesisBlock(t *testing.T) {