From a8e89d9b5f1d04ac7e81ad2b33e594456a09afa0 Mon Sep 17 00:00:00 2001 From: Dang Nhat Trinh Date: Thu, 6 Jul 2023 23:30:56 +0700 Subject: [PATCH] Revert GetBlockReceipts interface and some minor fixes --- accounts/abi/bind/backends/simulated.go | 4 +-- cmd/tomo/bugcmd.go | 3 +- console/console_test.go | 25 +++++-------- core/bench_test.go | 2 +- core/blockchain_test.go | 10 +++--- core/database_util_test.go | 9 ++--- core/genesis.go | 19 +++++++--- core/types/transaction.go | 3 +- eth/api_backend.go | 4 +-- eth/config.go | 8 +++-- eth/filters/filter.go | 4 +-- eth/filters/filter_system.go | 2 +- eth/filters/filter_system_test.go | 10 ++++-- internal/ethapi/api.go | 2 +- internal/ethapi/backend.go | 2 +- les/api_backend.go | 4 +-- les/handler_test.go | 7 ++-- les/odr_test.go | 48 +++++++++++++------------ params/config.go | 2 +- tests/block_test_util.go | 19 +++++----- 20 files changed, 102 insertions(+), 85 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 1b55704812..7bebd34984 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -569,8 +569,8 @@ func (fb *filterBackend) HeaderByNumber(ctx context.Context, block rpc.BlockNumb return fb.bc.GetHeaderByNumber(uint64(block.Int64())), nil } -func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash, config *params.ChainConfig) (types.Receipts, error) { - return core.GetBlockReceipts(fb.db, hash, core.GetBlockNumber(fb.db, hash), config), nil +func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) { + return core.GetBlockReceipts(fb.db, hash, core.GetBlockNumber(fb.db, hash), fb.ChainConfig()), nil } func (fb *filterBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) { diff --git a/cmd/tomo/bugcmd.go b/cmd/tomo/bugcmd.go index 3174f73881..5cec10ad49 100644 --- a/cmd/tomo/bugcmd.go +++ b/cmd/tomo/bugcmd.go @@ -105,5 +105,4 @@ const header = `Please answer these questions before submitting your issue. Than #### What did you see instead? -#### System details -` +#### System details` diff --git a/console/console_test.go b/console/console_test.go index 22527f4ddc..9565c7e97a 100644 --- a/console/console_test.go +++ b/console/console_test.go @@ -19,20 +19,19 @@ package console import ( "bytes" "errors" - "github.com/tomochain/tomochain/tomox" - "github.com/tomochain/tomochain/tomoxlending" - "io/ioutil" "os" "strings" "testing" "time" "github.com/tomochain/tomochain/common" - "github.com/tomochain/tomochain/consensus/ethash" + "github.com/tomochain/tomochain/console/prompt" "github.com/tomochain/tomochain/core" "github.com/tomochain/tomochain/eth" "github.com/tomochain/tomochain/internal/jsre" "github.com/tomochain/tomochain/node" + "github.com/tomochain/tomochain/tomox" + "github.com/tomochain/tomochain/tomoxlending" ) const ( @@ -67,10 +66,10 @@ func (p *hookedPrompter) PromptPassword(prompt string) (string, error) { func (p *hookedPrompter) PromptConfirm(prompt string) (bool, error) { return false, errors.New("not implemented") } -func (p *hookedPrompter) SetHistory(history []string) {} -func (p *hookedPrompter) AppendHistory(command string) {} -func (p *hookedPrompter) ClearHistory() {} -func (p *hookedPrompter) SetWordCompleter(completer WordCompleter) {} +func (p *hookedPrompter) SetHistory(history []string) {} +func (p *hookedPrompter) AppendHistory(command string) {} +func (p *hookedPrompter) ClearHistory() {} +func (p *hookedPrompter) SetWordCompleter(completer prompt.WordCompleter) {} // tester is a console test environment for the console tests to operate on. type tester struct { @@ -86,10 +85,7 @@ type tester struct { // Please ensure you call Close() on the returned tester to avoid leaks. func newTester(t *testing.T, confOverride func(*eth.Config)) *tester { // Create a temporary storage for the node keys and initialize it - workspace, err := ioutil.TempDir("", "console-tester-") - if err != nil { - t.Fatalf("failed to create temporary keystore: %v", err) - } + workspace := t.TempDir() // Create a networkless protocol stack and start an Ethereum service within stack, err := node.New(&node.Config{DataDir: workspace, UseLightweightKDF: true, Name: testInstance}) @@ -99,9 +95,6 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester { ethConf := ð.Config{ Genesis: core.DeveloperGenesisBlock(15, common.Address{}), Etherbase: common.HexToAddress(testAddress), - Ethash: ethash.Config{ - PowMode: ethash.ModeTest, - }, } if confOverride != nil { confOverride(ethConf) @@ -262,7 +255,7 @@ func TestPrettyError(t *testing.T) { defer tester.Close(t) tester.console.Evaluate("throw 'hello'") - want := jsre.ErrorColor("hello") + "\n" + want := jsre.ErrorColor("hello") + "\n\tat :1:1(1)\n\n" if output := tester.output.String(); output != want { t.Fatalf("pretty error mismatch: have %s, want %s", output, want) } diff --git a/core/bench_test.go b/core/bench_test.go index a52aa7f2c2..d0a90b1ec3 100644 --- a/core/bench_test.go +++ b/core/bench_test.go @@ -294,7 +294,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) { if full { hash := header.Hash() GetBody(db, hash, n) - GetBlockReceipts(db, hash, n) + GetBlockReceipts(db, hash, n, params.TestChainConfig) } } diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 6860924112..cf209d9f99 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -18,7 +18,6 @@ package core import ( "fmt" - "github.com/tomochain/tomochain/core/rawdb" "math/big" "math/rand" "sync" @@ -27,6 +26,7 @@ import ( "github.com/tomochain/tomochain/common" "github.com/tomochain/tomochain/consensus/ethash" + "github.com/tomochain/tomochain/core/rawdb" "github.com/tomochain/tomochain/core/state" "github.com/tomochain/tomochain/core/types" "github.com/tomochain/tomochain/core/vm" @@ -622,7 +622,7 @@ func TestFastVsFullChains(t *testing.T) { } else if types.CalcUncleHash(fblock.Uncles()) != types.CalcUncleHash(ablock.Uncles()) { t.Errorf("block #%d [%x]: uncles mismatch: have %v, want %v", num, hash, fblock.Uncles(), ablock.Uncles()) } - if freceipts, areceipts := GetBlockReceipts(fastDb, hash, GetBlockNumber(fastDb, hash)), GetBlockReceipts(archiveDb, hash, GetBlockNumber(archiveDb, hash)); types.DeriveSha(freceipts) != types.DeriveSha(areceipts) { + if freceipts, areceipts := GetBlockReceipts(fastDb, hash, GetBlockNumber(fastDb, hash), fast.Config()), GetBlockReceipts(archiveDb, hash, GetBlockNumber(archiveDb, hash), fast.Config()); types.DeriveSha(freceipts) != types.DeriveSha(areceipts) { t.Errorf("block #%d [%x]: receipts mismatch: have %v, want %v", num, hash, freceipts, areceipts) } } @@ -807,7 +807,7 @@ func TestChainTxReorgs(t *testing.T) { if txn, _, _, _ := GetTransaction(db, tx.Hash()); txn != nil { t.Errorf("drop %d: tx %v found while shouldn't have been", i, txn) } - if rcpt, _, _, _ := GetReceipt(db, tx.Hash()); rcpt != nil { + if rcpt, _, _, _ := GetReceipt(db, tx.Hash(), blockchain.Config()); rcpt != nil { t.Errorf("drop %d: receipt %v found while shouldn't have been", i, rcpt) } } @@ -816,7 +816,7 @@ func TestChainTxReorgs(t *testing.T) { if txn, _, _, _ := GetTransaction(db, tx.Hash()); txn == nil { t.Errorf("add %d: expected tx to be found", i) } - if rcpt, _, _, _ := GetReceipt(db, tx.Hash()); rcpt == nil { + if rcpt, _, _, _ := GetReceipt(db, tx.Hash(), blockchain.Config()); rcpt == nil { t.Errorf("add %d: expected receipt to be found", i) } } @@ -825,7 +825,7 @@ func TestChainTxReorgs(t *testing.T) { if txn, _, _, _ := GetTransaction(db, tx.Hash()); txn == nil { t.Errorf("share %d: expected tx to be found", i) } - if rcpt, _, _, _ := GetReceipt(db, tx.Hash()); rcpt == nil { + if rcpt, _, _, _ := GetReceipt(db, tx.Hash(), blockchain.Config()); rcpt == nil { t.Errorf("share %d: expected receipt to be found", i) } } diff --git a/core/database_util_test.go b/core/database_util_test.go index f28ca160a5..ab57e8876e 100644 --- a/core/database_util_test.go +++ b/core/database_util_test.go @@ -18,13 +18,14 @@ package core import ( "bytes" - "github.com/tomochain/tomochain/core/rawdb" "math/big" "testing" "github.com/tomochain/tomochain/common" + "github.com/tomochain/tomochain/core/rawdb" "github.com/tomochain/tomochain/core/types" "github.com/tomochain/tomochain/crypto/sha3" + "github.com/tomochain/tomochain/params" "github.com/tomochain/tomochain/rlp" ) @@ -361,14 +362,14 @@ func TestBlockReceiptStorage(t *testing.T) { // Check that no receipt entries are in a pristine database hash := common.BytesToHash([]byte{0x03, 0x14}) - if rs := GetBlockReceipts(db, hash, 0); len(rs) != 0 { + if rs := GetBlockReceipts(db, hash, 0, params.TestChainConfig); len(rs) != 0 { t.Fatalf("non existent receipts returned: %v", rs) } // Insert the receipt slice into the database and check presence if err := WriteBlockReceipts(db, hash, 0, receipts); err != nil { t.Fatalf("failed to write block receipts: %v", err) } - if rs := GetBlockReceipts(db, hash, 0); len(rs) == 0 { + if rs := GetBlockReceipts(db, hash, 0, params.TestChainConfig); len(rs) == 0 { t.Fatalf("no receipts returned") } else { for i := 0; i < len(receipts); i++ { @@ -382,7 +383,7 @@ func TestBlockReceiptStorage(t *testing.T) { } // Delete the receipt slice and check purge DeleteBlockReceipts(db, hash, 0) - if rs := GetBlockReceipts(db, hash, 0); len(rs) != 0 { + if rs := GetBlockReceipts(db, hash, 0, params.TestChainConfig); len(rs) != 0 { t.Fatalf("deleted receipts returned: %v", rs) } } diff --git a/core/genesis.go b/core/genesis.go index e1b7185a41..8b8d0dd158 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -22,13 +22,13 @@ import ( "encoding/json" "errors" "fmt" - "github.com/tomochain/tomochain/core/rawdb" "math/big" "strings" "github.com/tomochain/tomochain/common" "github.com/tomochain/tomochain/common/hexutil" "github.com/tomochain/tomochain/common/math" + "github.com/tomochain/tomochain/core/rawdb" "github.com/tomochain/tomochain/core/state" "github.com/tomochain/tomochain/core/types" "github.com/tomochain/tomochain/ethdb" @@ -60,6 +60,7 @@ type Genesis struct { Number uint64 `json:"number"` GasUsed uint64 `json:"gasUsed"` ParentHash common.Hash `json:"parentHash"` + BaseFee *big.Int `json:"baseFeePerGas"` } // GenesisAlloc specifies the initial state that is part of the genesis block. @@ -140,10 +141,10 @@ func (e *GenesisMismatchError) Error() string { // SetupGenesisBlock writes or updates the genesis block in db. // The block that will be used is: // -// genesis == nil genesis != nil -// +------------------------------------------ -// db has no genesis | main-net default | genesis -// db has genesis | from DB | genesis (if compatible) +// genesis == nil genesis != nil +// +------------------------------------------ +// db has no genesis | main-net default | genesis +// db has genesis | from DB | genesis (if compatible) // // The stored chain configuration will be updated if it is compatible (i.e. does not // specify a fork block below the local head block). In case of a conflict, the @@ -255,6 +256,13 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block { if g.Difficulty == nil { head.Difficulty = params.GenesisDifficulty } + if g.Config != nil && g.Config.IsLondon(common.Big0) { + if g.BaseFee != nil { + head.BaseFee = g.BaseFee + } else { + head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee) + } + } statedb.Commit(false) statedb.Database().TrieDB().Commit(root, true) @@ -358,6 +366,7 @@ func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis { Config: &config, ExtraData: append(append(make([]byte, 32), faucet[:]...), make([]byte, 65)...), GasLimit: 6283185, + BaseFee: big.NewInt(params.InitialBaseFee), Difficulty: big.NewInt(1), Alloc: map[common.Address]GenesisAccount{ common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover diff --git a/core/types/transaction.go b/core/types/transaction.go index c682596c01..5f4851d375 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -828,7 +828,8 @@ func NewTransactionsByPriceAndNonce(signer Signer, txs map[common.Address]Transa } specialTxs := Transactions{} for _, accTxs := range txs { - if len(accTxs) == 0 { + // check because sometimes the map value can be null + if accTxs == nil || len(accTxs) == 0 { continue } from, _ := Sender(signer, accTxs[0]) diff --git a/eth/api_backend.go b/eth/api_backend.go index 7204e1fc3e..ed3768dd27 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -160,8 +160,8 @@ func (b *EthApiBackend) GetBlock(ctx context.Context, blockHash common.Hash) (*t return b.eth.blockchain.GetBlockByHash(blockHash), nil } -func (b *EthApiBackend) GetReceipts(ctx context.Context, blockHash common.Hash, config *params.ChainConfig) (types.Receipts, error) { - return core.GetBlockReceipts(b.eth.chainDb, blockHash, core.GetBlockNumber(b.eth.chainDb, blockHash), config), nil +func (b *EthApiBackend) GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error) { + return core.GetBlockReceipts(b.eth.chainDb, blockHash, core.GetBlockNumber(b.eth.chainDb, blockHash), b.ChainConfig()), nil } func (b *EthApiBackend) GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error) { diff --git a/eth/config.go b/eth/config.go index a68521e28d..7390feec47 100644 --- a/eth/config.go +++ b/eth/config.go @@ -52,8 +52,12 @@ var DefaultConfig = Config{ TxPool: core.DefaultTxPoolConfig, GPO: gasprice.Config{ - Blocks: 20, - Percentile: 60, + Blocks: 20, + Percentile: 60, + MaxHeaderHistory: 1024, + MaxBlockHistory: 1024, + MaxPrice: gasprice.DefaultMaxPrice, + IgnorePrice: gasprice.DefaultIgnorePrice, }, RPCGasCap: 50000000, RPCEVMTimeout: 5 * time.Second, diff --git a/eth/filters/filter.go b/eth/filters/filter.go index 7f0ea75fe1..7767deb0ed 100644 --- a/eth/filters/filter.go +++ b/eth/filters/filter.go @@ -34,7 +34,7 @@ type Backend interface { ChainDb() ethdb.Database EventMux() *event.TypeMux HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) - GetReceipts(ctx context.Context, blockHash common.Hash, config *params.ChainConfig) (types.Receipts, error) + GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error) GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error) ChainConfig() *params.ChainConfig @@ -216,7 +216,7 @@ func (f *Filter) checkMatches(ctx context.Context, header *types.Header) (logs [ if len(logs) > 0 { // We have matching logs, check if we need to resolve full logs via the light client if logs[0].TxHash == (common.Hash{}) { - receipts, err := f.backend.GetReceipts(ctx, header.Hash(), f.backend.ChainConfig()) + receipts, err := f.backend.GetReceipts(ctx, header.Hash()) if err != nil { return nil, err } diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go index 4c15d29a88..3d92fc1ac7 100644 --- a/eth/filters/filter_system.go +++ b/eth/filters/filter_system.go @@ -390,7 +390,7 @@ func (es *EventSystem) lightFilterLogs(header *types.Header, addresses []common. logs := filterLogs(unfiltered, nil, nil, addresses, topics) if len(logs) > 0 && logs[0].TxHash == (common.Hash{}) { // We have matching but non-derived logs - receipts, err := es.backend.GetReceipts(ctx, header.Hash(), es.backend.ChainConfig()) + receipts, err := es.backend.GetReceipts(ctx, header.Hash()) if err != nil { return nil } diff --git a/eth/filters/filter_system_test.go b/eth/filters/filter_system_test.go index d947a672ac..eb3e7cce4b 100644 --- a/eth/filters/filter_system_test.go +++ b/eth/filters/filter_system_test.go @@ -19,7 +19,6 @@ package filters import ( "context" "fmt" - "github.com/tomochain/tomochain/core/rawdb" "math/big" "math/rand" "reflect" @@ -31,6 +30,7 @@ import ( "github.com/tomochain/tomochain/consensus/ethash" "github.com/tomochain/tomochain/core" "github.com/tomochain/tomochain/core/bloombits" + "github.com/tomochain/tomochain/core/rawdb" "github.com/tomochain/tomochain/core/types" "github.com/tomochain/tomochain/ethdb" "github.com/tomochain/tomochain/event" @@ -48,6 +48,10 @@ type testBackend struct { chainFeed *event.Feed } +func (b *testBackend) ChainConfig() *params.ChainConfig { + return params.TestChainConfig +} + func (b *testBackend) ChainDb() ethdb.Database { return b.db } @@ -71,12 +75,12 @@ func (b *testBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumbe func (b *testBackend) GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error) { number := core.GetBlockNumber(b.db, blockHash) - return core.GetBlockReceipts(b.db, blockHash, number), nil + return core.GetBlockReceipts(b.db, blockHash, number, b.ChainConfig()), nil } func (b *testBackend) GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error) { number := core.GetBlockNumber(b.db, blockHash) - receipts := core.GetBlockReceipts(b.db, blockHash, number) + receipts := core.GetBlockReceipts(b.db, blockHash, number, b.ChainConfig()) logs := make([][]*types.Log, len(receipts)) for i, receipt := range receipts { diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 59295255a6..0b7e8e6979 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1849,7 +1849,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha if err != nil { return nil, err } - receipts, err := s.b.GetReceipts(ctx, blockHash, s.b.ChainConfig()) + receipts, err := s.b.GetReceipts(ctx, blockHash) if err != nil { return nil, err } diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index afc3a7f2db..9a88c2310b 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -66,7 +66,7 @@ type Backend interface { StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error) GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error) - GetReceipts(ctx context.Context, blockHash common.Hash, config *params.ChainConfig) (types.Receipts, error) + GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error) GetTd(blockHash common.Hash) *big.Int GetEVM(ctx context.Context, msg *core.Message, state *state.StateDB, tomoxState *tradingstate.TradingStateDB, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription diff --git a/les/api_backend.go b/les/api_backend.go index e82efa5447..15a3ebe8e2 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -134,8 +134,8 @@ func (b *LesApiBackend) GetBlock(ctx context.Context, blockHash common.Hash) (*t return b.eth.blockchain.GetBlockByHash(ctx, blockHash) } -func (b *LesApiBackend) GetReceipts(ctx context.Context, blockHash common.Hash, config *params.ChainConfig) (types.Receipts, error) { - return light.GetBlockReceipts(ctx, b.eth.odr, blockHash, core.GetBlockNumber(b.eth.chainDb, blockHash), config) +func (b *LesApiBackend) GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error) { + return light.GetBlockReceipts(ctx, b.eth.odr, blockHash, core.GetBlockNumber(b.eth.chainDb, blockHash), b.ChainConfig()) } func (b *LesApiBackend) GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error) { diff --git a/les/handler_test.go b/les/handler_test.go index 225900dd52..a5c839cb0a 100644 --- a/les/handler_test.go +++ b/les/handler_test.go @@ -18,7 +18,6 @@ package les import ( "encoding/binary" - "github.com/tomochain/tomochain/core/rawdb" "math/big" "math/rand" "testing" @@ -27,6 +26,7 @@ import ( "github.com/tomochain/tomochain/common" "github.com/tomochain/tomochain/consensus/ethash" "github.com/tomochain/tomochain/core" + "github.com/tomochain/tomochain/core/rawdb" "github.com/tomochain/tomochain/core/types" "github.com/tomochain/tomochain/crypto" "github.com/tomochain/tomochain/eth/downloader" @@ -253,8 +253,9 @@ func testGetBlockBodies(t *testing.T, protocol int) { } // Tests that the contract codes can be retrieved based on account addresses. -func TestGetCodeLes1(t *testing.T) { testGetCode(t, 1) } func TestGetCodeLes2(t *testing.T) { testGetCode(t, 2) } +func TestGetCodeLes3(t *testing.T) { testGetCode(t, 3) } +func TestGetCodeLes4(t *testing.T) { testGetCode(t, 4) } func testGetCode(t *testing.T, protocol int) { // Assemble the test environment @@ -304,7 +305,7 @@ func testGetReceipt(t *testing.T, protocol int) { block := bc.GetBlockByNumber(i) hashes = append(hashes, block.Hash()) - receipts = append(receipts, core.GetBlockReceipts(db, block.Hash(), block.NumberU64())) + receipts = append(receipts, core.GetBlockReceipts(db, block.Hash(), block.NumberU64(), bc.Config())) } // Send the hash request and verify the response cost := peer.GetRequestCost(GetReceiptsMsg, len(hashes)) diff --git a/les/odr_test.go b/les/odr_test.go index 2f3342bbaa..ecbb69ed66 100644 --- a/les/odr_test.go +++ b/les/odr_test.go @@ -64,9 +64,9 @@ func odrGetBlock(ctx context.Context, db ethdb.Database, config *params.ChainCon func odrGetReceipts(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { var receipts types.Receipts if bc != nil { - receipts = core.GetBlockReceipts(db, bhash, core.GetBlockNumber(db, bhash)) + receipts = core.GetBlockReceipts(db, bhash, core.GetBlockNumber(db, bhash), config) } else { - receipts, _ = light.GetBlockReceipts(ctx, lc.Odr(), bhash, core.GetBlockNumber(db, bhash)) + receipts, _ = light.GetBlockReceipts(ctx, lc.Odr(), bhash, core.GetBlockNumber(db, bhash), config) } if receipts == nil { return nil @@ -109,12 +109,6 @@ func odrAccounts(ctx context.Context, db ethdb.Database, config *params.ChainCon // //func TestOdrContractCallLes2(t *testing.T) { testOdr(t, 2, 2, odrContractCall) } -type callmsg struct { - core.Message -} - -func (callmsg) CheckNonce() bool { return false } - func odrContractCall(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { data := common.Hex2Bytes("60CD26850000000000000000000000000000000000000000000000000000000000000000") @@ -133,20 +127,18 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai if value, ok := feeCapacity[testContractAddr]; ok { balanceTokenFee = value } - //msg := &Message{ - // To: call.To, - // From: call.From, - // Value: call.Value, - // GasLimit: call.Gas, - // GasPrice: call.GasPrice, - // GasFeeCap: call.GasFeeCap, - // GasTipCap: call.GasTipCap, - // Data: call.Data, - // AccessList: call.AccessList, - // SkipAccountChecks: false, - //} - msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, balanceTokenFee)} - + fromAddr := from.Address() + msg := &core.Message{ + To: &fromAddr, + From: testContractAddr, + Nonce: 0, + Value: new(big.Int), + GasLimit: 100000, + GasPrice: new(big.Int), + Data: data, + SkipAccountChecks: false, + BalanceTokenFee: balanceTokenFee, + } context := core.NewEVMContext(msg, header, bc, nil) vmenv := vm.NewEVM(context, statedb, nil, config, vm.Config{}) @@ -165,7 +157,17 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai if value, ok := feeCapacity[testContractAddr]; ok { balanceTokenFee = value } - msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, balanceTokenFee)} + msg := &core.Message{ + To: &testBankAddress, + From: testContractAddr, + Nonce: 0, + Value: new(big.Int), + GasLimit: 100000, + GasPrice: new(big.Int), + Data: data, + SkipAccountChecks: false, + BalanceTokenFee: balanceTokenFee, + } context := core.NewEVMContext(msg, header, lc, nil) vmenv := vm.NewEVM(context, statedb, nil, config, vm.Config{}) gp := new(core.GasPool).AddGas(math.MaxUint64) diff --git a/params/config.go b/params/config.go index 41aa1748ad..8a755f178e 100644 --- a/params/config.go +++ b/params/config.go @@ -111,7 +111,7 @@ var ( // adding flags to the config to also have to set these fields. AllPosvProtocolChanges = &ChainConfig{big.NewInt(89), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, &PosvConfig{Period: 0, Epoch: 30000}} AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil} - TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil, nil} + TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, big.NewInt(0), new(EthashConfig), nil, nil} TestRules = TestChainConfig.Rules(new(big.Int)) ) diff --git a/tests/block_test_util.go b/tests/block_test_util.go index b07f23b11d..e362095aa5 100644 --- a/tests/block_test_util.go +++ b/tests/block_test_util.go @@ -80,6 +80,7 @@ type btHeader struct { GasLimit uint64 GasUsed uint64 Timestamp *big.Int + BaseFeePerGas *big.Int } type btHeaderMarshaling struct { @@ -147,20 +148,22 @@ func (t *BlockTest) genesis(config *params.ChainConfig) *core.Genesis { Mixhash: t.json.Genesis.MixHash, Coinbase: t.json.Genesis.Coinbase, Alloc: t.json.Pre, + BaseFee: t.json.Genesis.BaseFeePerGas, } } -/* See https://github.com/ethereum/tests/wiki/Blockchain-Tests-II +/* +See https://github.com/ethereum/tests/wiki/Blockchain-Tests-II - Whether a block is valid or not is a bit subtle, it's defined by presence of - blockHeader, transactions and uncleHeaders fields. If they are missing, the block is - invalid and we must verify that we do not accept it. + Whether a block is valid or not is a bit subtle, it's defined by presence of + blockHeader, transactions and uncleHeaders fields. If they are missing, the block is + invalid and we must verify that we do not accept it. - Since some tests mix valid and invalid blocks we need to check this for every block. + Since some tests mix valid and invalid blocks we need to check this for every block. - If a block is invalid it does not necessarily fail the test, if it's invalidness is - expected we are expected to ignore it and continue processing and then validate the - post state. + If a block is invalid it does not necessarily fail the test, if it's invalidness is + expected we are expected to ignore it and continue processing and then validate the + post state. */ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error) { validBlocks := make([]btBlock, 0)