From 9e45c7b7df533fe75750ea8f0f9e22e9688ddda5 Mon Sep 17 00:00:00 2001 From: Shogo Hyodo Date: Mon, 27 Jan 2025 16:01:52 +0900 Subject: [PATCH 1/2] Remove gxhash global variable --- consensus/gxhash/consensus.go | 5 ----- tests/block_test_util.go | 25 ++++++++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/consensus/gxhash/consensus.go b/consensus/gxhash/consensus.go index 3d6b4f42c..00f6e4ded 100644 --- a/consensus/gxhash/consensus.go +++ b/consensus/gxhash/consensus.go @@ -392,12 +392,7 @@ func (gxhash *Gxhash) Prepare(chain consensus.ChainReader, header *types.Header) return nil } -var CustomInitialize func(chain consensus.ChainReader, header *types.Header, state *state.StateDB) - func (gxhash *Gxhash) Initialize(chain consensus.ChainReader, header *types.Header, state *state.StateDB) { - if CustomInitialize != nil { - CustomInitialize(chain, header, state) - } } // Finalize implements consensus.Engine, accumulating the block rewards, diff --git a/tests/block_test_util.go b/tests/block_test_util.go index cd338c277..bbc2adc8b 100644 --- a/tests/block_test_util.go +++ b/tests/block_test_util.go @@ -111,6 +111,21 @@ type btHeaderMarshaling struct { ExcessBlobGas *math.HexOrDecimal64 } +type eestEngine struct { + *gxhash.Gxhash + baseFee *big.Int +} + +var _ consensus.Engine = &eestEngine{} + +func (e *eestEngine) Initialize(chain consensus.ChainReader, header *types.Header, state *state.StateDB) { + if chain.Config().IsPragueForkEnabled(header.Number) { + context := blockchain.NewEVMBlockContext(header, chain, nil) + vmenv := vm.NewEVM(context, vm.TxContext{}, state, chain.Config(), &vm.Config{}) + blockchain.ProcessParentBlockHash(header, vmenv, state, chain.Config().Rules(header.Number)) + } +} + func (t *BlockTest) Run() error { config, ok := Forks[t.json.Network] if !ok { @@ -143,16 +158,8 @@ func (t *BlockTest) Run() error { return fmt.Errorf("genesis block state root does not match test: computed=%x, test=%x", gblock.Root().Bytes()[:6], t.json.Genesis.StateRoot[:6]) } - // TODO-Kaia: Replace gxhash with istanbul tracer := vm.NewStructLogger(nil) - gxhash.CustomInitialize = func(chain consensus.ChainReader, header *types.Header, state *state.StateDB) { - if chain.Config().IsPragueForkEnabled(header.Number) { - context := blockchain.NewEVMBlockContext(header, chain, nil) - vmenv := vm.NewEVM(context, vm.TxContext{}, state, chain.Config(), &vm.Config{}) - blockchain.ProcessParentBlockHash(header, vmenv, state, chain.Config().Rules(header.Number)) - } - } - chain, err := blockchain.NewBlockChain(db, nil, config, gxhash.NewShared(), vm.Config{Debug: true, Tracer: tracer, ComputationCostLimit: params.OpcodeComputationCostLimitInfinite}) + chain, err := blockchain.NewBlockChain(db, nil, config, &eestEngine{Gxhash: gxhash.NewShared()}, vm.Config{Debug: true, Tracer: tracer, ComputationCostLimit: params.OpcodeComputationCostLimitInfinite}) if err != nil { return err } From 396a7432f0832005681f7d0add76b92f81cde376 Mon Sep 17 00:00:00 2001 From: Shogo Hyodo Date: Mon, 27 Jan 2025 16:06:46 +0900 Subject: [PATCH 2/2] Remove unused code --- tests/block_test.go | 2 -- tests/block_test_util.go | 1 - 2 files changed, 3 deletions(-) diff --git a/tests/block_test.go b/tests/block_test.go index 0e584f292..612aedad4 100644 --- a/tests/block_test.go +++ b/tests/block_test.go @@ -28,7 +28,6 @@ import ( "github.com/kaiachain/kaia/blockchain" "github.com/kaiachain/kaia/blockchain/types" "github.com/kaiachain/kaia/common" - "github.com/kaiachain/kaia/consensus/gxhash" "github.com/stretchr/testify/suite" ) @@ -76,7 +75,6 @@ func (suite *ExecutionSpecBlockTestSuite) TearDownSuite() { blockchain.GasLimitInExecutionSpecTest = 0 blockchain.CreateContractWithCodeFormatInExecutionSpecTest = false types.IsPragueInExecutionSpecTest = false - gxhash.CustomInitialize = nil } func (suite *ExecutionSpecBlockTestSuite) TestExecutionSpecBlock() { diff --git a/tests/block_test_util.go b/tests/block_test_util.go index bbc2adc8b..0e149760d 100644 --- a/tests/block_test_util.go +++ b/tests/block_test_util.go @@ -113,7 +113,6 @@ type btHeaderMarshaling struct { type eestEngine struct { *gxhash.Gxhash - baseFee *big.Int } var _ consensus.Engine = &eestEngine{}