From ff7c33488e9c06fd5b1cb0838ccbf210985fb156 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Tue, 25 Feb 2025 16:38:34 +0300 Subject: [PATCH] Revert format changes --- core/txpool/validation.go | 8 +++++--- nativeasset/contract.go | 1 + plugin/evm/atomic/state/atomic_backend.go | 10 +++++----- plugin/evm/atomic/state/atomic_trie_test.go | 8 ++++---- plugin/evm/atomic/vm/vm.go | 5 +++-- precompile/contracts/warp/contract_warp_handler.go | 1 - 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/core/txpool/validation.go b/core/txpool/validation.go index f39a6e71b2..fad1d39ad3 100644 --- a/core/txpool/validation.go +++ b/core/txpool/validation.go @@ -41,9 +41,11 @@ import ( "github.com/ava-labs/libevm/log" ) -// blobTxMinBlobGasPrice is the big.Int version of the configured protocol -// parameter to avoid constucting a new big integer for every transaction. -var blobTxMinBlobGasPrice = big.NewInt(params.BlobTxMinBlobGasprice) +var ( + // blobTxMinBlobGasPrice is the big.Int version of the configured protocol + // parameter to avoid constucting a new big integer for every transaction. + blobTxMinBlobGasPrice = big.NewInt(params.BlobTxMinBlobGasprice) +) // ValidationOptions define certain differences between transaction validation // across the different pools without having to duplicate those checks. diff --git a/nativeasset/contract.go b/nativeasset/contract.go index 632bff88af..ae14618605 100644 --- a/nativeasset/contract.go +++ b/nativeasset/contract.go @@ -152,6 +152,7 @@ func (c *NativeAssetCall) run(env vm.PrecompileEnvironment, stateDB contract.Sta stateDB.AddBalanceMultiCoin(to, assetID, assetAmount) ret, err = env.Call(to, callData, env.Gas(), new(uint256.Int), vm.WithUNSAFECallerAddressProxying()) + // When an error was returned by the EVM or when setting the creation code // above we revert to the snapshot and consume any gas remaining. Additionally // when we're in homestead this also counts for code storage gas errors. diff --git a/plugin/evm/atomic/state/atomic_backend.go b/plugin/evm/atomic/state/atomic_backend.go index 416b5ced88..24bdb02652 100644 --- a/plugin/evm/atomic/state/atomic_backend.go +++ b/plugin/evm/atomic/state/atomic_backend.go @@ -32,7 +32,7 @@ type AtomicBackend struct { sharedMemory avalancheatomic.SharedMemory repo *AtomicRepository - atomicTrie *AtomicTrie + atomicTrie *atomicTrie lastAcceptedHash common.Hash verifiedRoots map[common.Hash]*atomicState @@ -50,6 +50,9 @@ func NewAtomicBackend( if err != nil { return nil, err } + if bonusBlocks == nil { + bonusBlocks = make(map[uint64]ids.ID) // Ensure it's always non-nil + } atomicBackend := &AtomicBackend{ codec: codec, sharedMemory: sharedMemory, @@ -398,7 +401,7 @@ func (a *AtomicBackend) IsBonus(blockHeight uint64, blockHash common.Hash) bool return false } -func (a *AtomicBackend) AtomicTrie() *AtomicTrie { +func (a *AtomicBackend) AtomicTrie() *atomicTrie { return a.atomicTrie } @@ -437,8 +440,5 @@ func mergeAtomicOpsToMap(output map[ids.ID]*avalancheatomic.Requests, chainID id // AddBonusBlock adds a bonus block to the atomic backend func (a *AtomicBackend) AddBonusBlock(height uint64, blockID ids.ID) { - if a.bonusBlocks == nil { - a.bonusBlocks = make(map[uint64]ids.ID) - } a.bonusBlocks[height] = blockID } diff --git a/plugin/evm/atomic/state/atomic_trie_test.go b/plugin/evm/atomic/state/atomic_trie_test.go index ebc72245de..652ec15623 100644 --- a/plugin/evm/atomic/state/atomic_trie_test.go +++ b/plugin/evm/atomic/state/atomic_trie_test.go @@ -38,7 +38,7 @@ const testCommitInterval = 100 // indexAtomicTxs updates [tr] with entries in [atomicOps] at height by creating // a new snapshot, calculating a new root, and calling InsertTrie followed // by AcceptTrie on the new root. -func indexAtomicTxs(tr *AtomicTrie, height uint64, atomicOps map[ids.ID]*avalancheatomic.Requests) error { +func indexAtomicTxs(tr *atomicTrie, height uint64, atomicOps map[ids.ID]*avalancheatomic.Requests) error { snapshot, err := tr.OpenTrie(tr.LastAcceptedRoot()) if err != nil { return err @@ -255,7 +255,7 @@ func TestIndexerInitializesOnlyOnce(t *testing.T) { assert.Equal(t, hash, newHash, "hash should be the same") } -func newTestAtomicTrie(t *testing.T) *AtomicTrie { +func newTestAtomicTrie(t *testing.T) *atomicTrie { db := versiondb.New(memdb.New()) repo, err := NewAtomicTxRepository(db, atomictest.TestTxCodec, 0) if err != nil { @@ -692,7 +692,7 @@ func BenchmarkAtomicTrieInit(b *testing.B) { writeTxs(b, repo, 1, lastAcceptedHeight, constTxsPerHeight(3), nil, operationsMap) var ( - atomicTrie *AtomicTrie + atomicTrie *atomicTrie hash common.Hash height uint64 ) @@ -828,7 +828,7 @@ func benchmarkApplyToSharedMemory(b *testing.B, disk database.Database, blocks u // verifyOperations creates an iterator over the atomicTrie at [rootHash] and verifies that the all of the operations in the trie in the interval [from, to] are identical to // the atomic operations contained in [operationsMap] on the same interval. -func verifyOperations(t testing.TB, atomicTrie *AtomicTrie, codec codec.Manager, rootHash common.Hash, from, to uint64, operationsMap map[uint64]map[ids.ID]*avalancheatomic.Requests) { +func verifyOperations(t testing.TB, atomicTrie *atomicTrie, codec codec.Manager, rootHash common.Hash, from, to uint64, operationsMap map[uint64]map[ids.ID]*avalancheatomic.Requests) { t.Helper() // Start the iterator at [from] diff --git a/plugin/evm/atomic/vm/vm.go b/plugin/evm/atomic/vm/vm.go index 263039a5e4..01005e37e5 100644 --- a/plugin/evm/atomic/vm/vm.go +++ b/plugin/evm/atomic/vm/vm.go @@ -673,8 +673,9 @@ func (vm *VM) onExtraStateChange(block *types.Block, state *state.StateDB, chain batchContribution *big.Int = big.NewInt(0) batchGasUsed *big.Int = big.NewInt(0) header = block.Header() - rules = chainConfig.Rules(header.Number, params.IsMergeTODO, header.Time) - rulesExtra = *params.GetRulesExtra(rules) + // We cannot use chain config from InnerVM since it's not available when this function is called for the first time (bc.loadLastState). + rules = chainConfig.Rules(header.Number, params.IsMergeTODO, header.Time) + rulesExtra = *params.GetRulesExtra(rules) ) txs, err := atomic.ExtractAtomicTxs(block.ExtData(), rulesExtra.IsApricotPhase5, atomic.Codec) diff --git a/precompile/contracts/warp/contract_warp_handler.go b/precompile/contracts/warp/contract_warp_handler.go index 2b8a4c2113..a28afc9ef1 100644 --- a/precompile/contracts/warp/contract_warp_handler.go +++ b/precompile/contracts/warp/contract_warp_handler.go @@ -9,7 +9,6 @@ import ( "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload" - "github.com/ava-labs/coreth/precompile/contract" "github.com/ava-labs/coreth/predicate" "github.com/ava-labs/coreth/vmerrs"