From 9f0d1d4a5832c2c5b716a1f8456b684ae1f2eb1c Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Fri, 3 Oct 2025 15:51:34 +0300 Subject: [PATCH 01/25] chore(customrawdb): delete customrawdb package and switch to avalanchego imports resolves #1302 Signed-off-by: Tsvetan Dimitrov (tsvetan.dimitrov23@gmail.com) --- go.sum | 9 +- graft/coreth/core/blockchain.go | 9 +- graft/coreth/core/blockchain_repair_test.go | 2 +- graft/coreth/core/blockchain_test.go | 2 +- graft/coreth/core/genesis_test.go | 2 +- graft/coreth/core/state/pruner/pruner.go | 4 +- .../core/state/snapshot/disklayer_test.go | 2 +- graft/coreth/core/state/snapshot/generate.go | 2 +- graft/coreth/core/state/snapshot/journal.go | 7 +- graft/coreth/core/state/snapshot/snapshot.go | 2 +- graft/coreth/core/state/snapshot/wipe.go | 2 +- graft/coreth/core/state/snapshot/wipe_test.go | 8 +- graft/coreth/core/state_manager.go | 2 +- graft/coreth/eth/api_debug.go | 2 +- graft/coreth/eth/backend.go | 4 +- .../coreth/eth/filters/filter_system_test.go | 2 +- graft/coreth/eth/filters/filter_test.go | 2 +- graft/coreth/eth/state_accessor.go | 2 +- graft/coreth/eth/tracers/api_test.go | 2 +- graft/coreth/eth/tracers/tracers_test.go | 2 +- graft/coreth/go.mod | 3 +- graft/coreth/go.sum | 3 + .../evm/customrawdb/accessors_metadata_ext.go | 114 --------------- .../evm/customrawdb/accessors_snapshot_ext.go | 46 ------ .../customrawdb/accessors_state_sync_test.go | 35 ----- .../plugin/evm/customrawdb/database_ext.go | 80 ----------- .../evm/customrawdb/database_ext_test.go | 135 ------------------ .../plugin/evm/customtypes/block_test.go | 3 + .../gen_header_serializable_rlp.go | 7 +- .../plugin/evm/customtypes/hashing_test.go | 3 +- graft/coreth/plugin/evm/vm.go | 2 +- graft/coreth/plugin/evm/vm_test.go | 1 + .../coreth/plugin/evm/vmtest/test_syncervm.go | 25 ++-- graft/coreth/plugin/evm/vmtest/test_vm.go | 9 +- graft/coreth/sync/statesync/code_queue.go | 5 +- .../coreth/sync/statesync/code_queue_test.go | 7 +- graft/coreth/sync/statesync/code_syncer.go | 2 +- .../coreth/sync/statesync/code_syncer_test.go | 8 +- graft/coreth/sync/statesync/sync_test.go | 2 +- graft/coreth/sync/statesync/trie_queue.go | 7 +- graft/coreth/sync/statesync/trie_segments.go | 6 +- graft/coreth/tests/state_test_util.go | 2 +- 42 files changed, 87 insertions(+), 487 deletions(-) delete mode 100644 graft/coreth/plugin/evm/customrawdb/accessors_metadata_ext.go delete mode 100644 graft/coreth/plugin/evm/customrawdb/accessors_snapshot_ext.go delete mode 100644 graft/coreth/plugin/evm/customrawdb/accessors_state_sync_test.go delete mode 100644 graft/coreth/plugin/evm/customrawdb/database_ext.go delete mode 100644 graft/coreth/plugin/evm/customrawdb/database_ext_test.go diff --git a/go.sum b/go.sum index c0068716ca84..af2c7ae50090 100644 --- a/go.sum +++ b/go.sum @@ -43,8 +43,8 @@ connectrpc.com/grpcreflect v1.3.0/go.mod h1:nfloOtCS8VUQOQ1+GTdFzVg2CJo4ZGaat8JI dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= -github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno= github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo= @@ -71,6 +71,8 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmV github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +github.com/ava-labs/coreth v0.16.0 h1:0AcmiIR3118JrnoePO3ho2EyaySmEMvlbCmk3RcYRxk= +github.com/ava-labs/coreth v0.16.0/go.mod h1:uGr1C7BP0+dWhvsIouhuH0yCyI8YDgS6sfEFIExs0iI= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15 h1:NAVjEu508HwdgbxH/xQxMQoBUgYUn9RQf0VeCrhtYMY= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15/go.mod h1:hR/JSGXxST9B9olwu/NpLXHAykfAyNGfyKnYQqiiOeE= github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2 h1:hQ15IJxY7WOKqeJqCXawsiXh0NZTzmoQOemkWHz7rr4= @@ -99,9 +101,8 @@ github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUB github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipusjXSohQ= github.com/btcsuite/btcd/btcutil v1.1.3/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= -github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ= -github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= diff --git a/graft/coreth/core/blockchain.go b/graft/coreth/core/blockchain.go index f39e82e05bdb..44efd6db5b53 100644 --- a/graft/coreth/core/blockchain.go +++ b/graft/coreth/core/blockchain.go @@ -45,12 +45,12 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/core/state/snapshot" "github.com/ava-labs/avalanchego/graft/coreth/internal/version" "github.com/ava-labs/avalanchego/graft/coreth/params" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customtypes" "github.com/ava-labs/avalanchego/graft/coreth/triedb/firewood" "github.com/ava-labs/avalanchego/graft/coreth/triedb/hashdb" "github.com/ava-labs/avalanchego/graft/coreth/triedb/pathdb" "github.com/ava-labs/avalanchego/vms/evm/acp176" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/common/lru" "github.com/ava-labs/libevm/consensus/misc/eip4844" @@ -488,7 +488,10 @@ func NewBlockChain( // if txlookup limit is 0 (uindexing disabled), we don't need to repair the tx index tail. if bc.cacheConfig.TransactionHistory != 0 { - latestStateSynced := customrawdb.GetLatestSyncPerformed(bc.db) + latestStateSynced, err := customrawdb.GetLatestSyncPerformed(bc.db) + if err != nil { + return nil, err + } bc.repairTxIndexTail(latestStateSynced) } @@ -2060,7 +2063,7 @@ func (bc *BlockChain) populateMissingTries() error { // Write marker to DB to indicate populate missing tries finished successfully. // Note: writing the marker here means that we do allow consecutive runs of re-populating // missing tries if it does not finish during the prior run. - if err := customrawdb.WritePopulateMissingTries(bc.db); err != nil { + if err := customrawdb.WritePopulateMissingTries(bc.db, time.Now()); err != nil { return fmt.Errorf("failed to write offline pruning success marker: %w", err) } diff --git a/graft/coreth/core/blockchain_repair_test.go b/graft/coreth/core/blockchain_repair_test.go index 0f72012b70d4..817e3f997564 100644 --- a/graft/coreth/core/blockchain_repair_test.go +++ b/graft/coreth/core/blockchain_repair_test.go @@ -37,8 +37,8 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/consensus/dummy" "github.com/ava-labs/avalanchego/graft/coreth/params" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap3" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/types" diff --git a/graft/coreth/core/blockchain_test.go b/graft/coreth/core/blockchain_test.go index 64765e2e2c44..7c5b2639c672 100644 --- a/graft/coreth/core/blockchain_test.go +++ b/graft/coreth/core/blockchain_test.go @@ -36,9 +36,9 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/consensus/dummy" "github.com/ava-labs/avalanchego/graft/coreth/core/state/pruner" "github.com/ava-labs/avalanchego/graft/coreth/params" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap3" "github.com/ava-labs/avalanchego/upgrade" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/types" diff --git a/graft/coreth/core/genesis_test.go b/graft/coreth/core/genesis_test.go index 3861254fab74..cb8aa520c314 100644 --- a/graft/coreth/core/genesis_test.go +++ b/graft/coreth/core/genesis_test.go @@ -38,12 +38,12 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/consensus/dummy" "github.com/ava-labs/avalanchego/graft/coreth/params" "github.com/ava-labs/avalanchego/graft/coreth/params/extras" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap3" "github.com/ava-labs/avalanchego/graft/coreth/precompile/contracts/warp" "github.com/ava-labs/avalanchego/graft/coreth/triedb/firewood" "github.com/ava-labs/avalanchego/graft/coreth/triedb/pathdb" "github.com/ava-labs/avalanchego/graft/coreth/utils" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/types" diff --git a/graft/coreth/core/state/pruner/pruner.go b/graft/coreth/core/state/pruner/pruner.go index c71e91bc36b6..2fa9e51b1125 100644 --- a/graft/coreth/core/state/pruner/pruner.go +++ b/graft/coreth/core/state/pruner/pruner.go @@ -39,7 +39,7 @@ import ( "time" "github.com/ava-labs/avalanchego/graft/coreth/core/state/snapshot" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/types" @@ -219,7 +219,7 @@ func prune(maindb ethdb.Database, stateBloom *stateBloom, bloomPath string, star // Write marker to DB to indicate offline pruning finished successfully. We write before calling os.RemoveAll // to guarantee that if the node dies midway through pruning, then this will run during RecoverPruning. - if err := customrawdb.WriteOfflinePruning(maindb); err != nil { + if err := customrawdb.WriteOfflinePruning(maindb, time.Now()); err != nil { return fmt.Errorf("failed to write offline pruning success marker: %w", err) } diff --git a/graft/coreth/core/state/snapshot/disklayer_test.go b/graft/coreth/core/state/snapshot/disklayer_test.go index 035b5cf3c718..73545d9c1b98 100644 --- a/graft/coreth/core/state/snapshot/disklayer_test.go +++ b/graft/coreth/core/state/snapshot/disklayer_test.go @@ -31,7 +31,7 @@ import ( "bytes" "testing" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/ethdb/memorydb" diff --git a/graft/coreth/core/state/snapshot/generate.go b/graft/coreth/core/state/snapshot/generate.go index eb696d1fabaa..2c9693f4acbe 100644 --- a/graft/coreth/core/state/snapshot/generate.go +++ b/graft/coreth/core/state/snapshot/generate.go @@ -32,7 +32,7 @@ import ( "fmt" "time" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/utils" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" diff --git a/graft/coreth/core/state/snapshot/journal.go b/graft/coreth/core/state/snapshot/journal.go index c3116160a18c..56f6b44b6b31 100644 --- a/graft/coreth/core/state/snapshot/journal.go +++ b/graft/coreth/core/state/snapshot/journal.go @@ -33,7 +33,7 @@ import ( "fmt" "time" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/ethdb" @@ -61,7 +61,10 @@ type journalGenerator struct { func loadSnapshot(diskdb ethdb.KeyValueStore, triedb *triedb.Database, cache int, blockHash, root common.Hash, noBuild bool) (snapshot, bool, error) { // Retrieve the block number and hash of the snapshot, failing if no snapshot // is present in the database (or crashed mid-update). - baseBlockHash := customrawdb.ReadSnapshotBlockHash(diskdb) + baseBlockHash, err := customrawdb.ReadSnapshotBlockHash(diskdb) + if err != nil { + return nil, false, errors.New("missing or corrupted snapshot, no snapshot block hash") + } if baseBlockHash == (common.Hash{}) { return nil, false, errors.New("missing or corrupted snapshot, no snapshot block hash") } diff --git a/graft/coreth/core/state/snapshot/snapshot.go b/graft/coreth/core/state/snapshot/snapshot.go index 6bc7a3dc6188..dc66972d5a04 100644 --- a/graft/coreth/core/state/snapshot/snapshot.go +++ b/graft/coreth/core/state/snapshot/snapshot.go @@ -35,7 +35,7 @@ import ( "sync" "time" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" ethsnapshot "github.com/ava-labs/libevm/core/state/snapshot" diff --git a/graft/coreth/core/state/snapshot/wipe.go b/graft/coreth/core/state/snapshot/wipe.go index 5a27ab92ea28..d42723107999 100644 --- a/graft/coreth/core/state/snapshot/wipe.go +++ b/graft/coreth/core/state/snapshot/wipe.go @@ -31,7 +31,7 @@ import ( "bytes" "time" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/ethdb" diff --git a/graft/coreth/core/state/snapshot/wipe_test.go b/graft/coreth/core/state/snapshot/wipe_test.go index 2ff04b74ea10..3d5b1dc5bb0b 100644 --- a/graft/coreth/core/state/snapshot/wipe_test.go +++ b/graft/coreth/core/state/snapshot/wipe_test.go @@ -31,7 +31,7 @@ import ( "math/rand" "testing" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/ethdb/memorydb" @@ -72,7 +72,8 @@ func TestWipe(t *testing.T) { if items := count(); items != 128 { t.Fatalf("snapshot size mismatch: have %d, want %d", items, 128) } - if hash := customrawdb.ReadSnapshotBlockHash(db); hash == (common.Hash{}) { + hash, err := customrawdb.ReadSnapshotBlockHash(db) + if err != nil || hash == (common.Hash{}) { t.Errorf("snapshot block hash marker mismatch: have %#x, want ", hash) } if hash := rawdb.ReadSnapshotRoot(db); hash == (common.Hash{}) { @@ -96,7 +97,8 @@ func TestWipe(t *testing.T) { t.Fatalf("misc item count mismatch: have %d, want %d", items, 1000) } - if hash := customrawdb.ReadSnapshotBlockHash(db); hash != (common.Hash{}) { + hash, err := customrawdb.ReadSnapshotBlockHash(db) + if err == nil && hash != (common.Hash{}) { t.Errorf("snapshot block hash marker remained after wipe: %#x", hash) } if hash := rawdb.ReadSnapshotRoot(db); hash != (common.Hash{}) { diff --git a/graft/coreth/core/state_manager.go b/graft/coreth/core/state_manager.go index f66809b03395..d83302ffbc53 100644 --- a/graft/coreth/core/state_manager.go +++ b/graft/coreth/core/state_manager.go @@ -30,7 +30,7 @@ package core import ( "fmt" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/types" "github.com/ava-labs/libevm/ethdb" diff --git a/graft/coreth/eth/api_debug.go b/graft/coreth/eth/api_debug.go index f94748e9399e..742da486d195 100644 --- a/graft/coreth/eth/api_debug.go +++ b/graft/coreth/eth/api_debug.go @@ -34,8 +34,8 @@ import ( "time" "github.com/ava-labs/avalanchego/graft/coreth/internal/ethapi" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/rpc" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/common/hexutil" "github.com/ava-labs/libevm/core/rawdb" diff --git a/graft/coreth/eth/backend.go b/graft/coreth/eth/backend.go index 5052055b431f..e1cfa77acf4d 100644 --- a/graft/coreth/eth/backend.go +++ b/graft/coreth/eth/backend.go @@ -49,9 +49,9 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/miner" "github.com/ava-labs/avalanchego/graft/coreth/node" "github.com/ava-labs/avalanchego/graft/coreth/params" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/rpc" "github.com/ava-labs/avalanchego/utils/timer/mockable" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/accounts" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/bloombits" @@ -151,7 +151,7 @@ func New( "snapshot clean", common.StorageSize(config.SnapshotCache)*1024*1024, ) - scheme, err := customrawdb.ParseStateSchemeExt(config.StateScheme, chainDb) + scheme, err := customrawdb.ParseStateScheme(config.StateScheme, chainDb) if err != nil { return nil, err } diff --git a/graft/coreth/eth/filters/filter_system_test.go b/graft/coreth/eth/filters/filter_system_test.go index c5822fefbdf6..8c201efa5340 100644 --- a/graft/coreth/eth/filters/filter_system_test.go +++ b/graft/coreth/eth/filters/filter_system_test.go @@ -43,9 +43,9 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/core" "github.com/ava-labs/avalanchego/graft/coreth/internal/ethapi" "github.com/ava-labs/avalanchego/graft/coreth/params" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customtypes" "github.com/ava-labs/avalanchego/graft/coreth/rpc" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" ethereum "github.com/ava-labs/libevm" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/bloombits" diff --git a/graft/coreth/eth/filters/filter_test.go b/graft/coreth/eth/filters/filter_test.go index 95b2c9177d58..086ff4883557 100644 --- a/graft/coreth/eth/filters/filter_test.go +++ b/graft/coreth/eth/filters/filter_test.go @@ -39,8 +39,8 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/consensus/dummy" "github.com/ava-labs/avalanchego/graft/coreth/core" "github.com/ava-labs/avalanchego/graft/coreth/params" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/rpc" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/types" diff --git a/graft/coreth/eth/state_accessor.go b/graft/coreth/eth/state_accessor.go index be6f4eaa30d5..d3fd5dfb9461 100644 --- a/graft/coreth/eth/state_accessor.go +++ b/graft/coreth/eth/state_accessor.go @@ -36,7 +36,7 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/core" "github.com/ava-labs/avalanchego/graft/coreth/core/extstate" "github.com/ava-labs/avalanchego/graft/coreth/eth/tracers" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/state" diff --git a/graft/coreth/eth/tracers/api_test.go b/graft/coreth/eth/tracers/api_test.go index 44ffb7a20483..782b58bf95e6 100644 --- a/graft/coreth/eth/tracers/api_test.go +++ b/graft/coreth/eth/tracers/api_test.go @@ -43,8 +43,8 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/core" "github.com/ava-labs/avalanchego/graft/coreth/internal/ethapi" "github.com/ava-labs/avalanchego/graft/coreth/params" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/rpc" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/common/hexutil" "github.com/ava-labs/libevm/core/rawdb" diff --git a/graft/coreth/eth/tracers/tracers_test.go b/graft/coreth/eth/tracers/tracers_test.go index 776f1017bdf2..f3a70fdc4baf 100644 --- a/graft/coreth/eth/tracers/tracers_test.go +++ b/graft/coreth/eth/tracers/tracers_test.go @@ -34,9 +34,9 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/core" "github.com/ava-labs/avalanchego/graft/coreth/params" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customtypes" "github.com/ava-labs/avalanchego/graft/coreth/tests" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/types" diff --git a/graft/coreth/go.mod b/graft/coreth/go.mod index 8ed6774b6dc6..b0ff41a1f9a7 100644 --- a/graft/coreth/go.mod +++ b/graft/coreth/go.mod @@ -16,6 +16,7 @@ go 1.24.9 require ( github.com/VictoriaMetrics/fastcache v1.12.1 github.com/ava-labs/avalanchego v1.14.1-0.20251120155522-df4a8e531761 + github.com/ava-labs/coreth v0.16.0 github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15 github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc @@ -53,7 +54,6 @@ require ( require ( connectrpc.com/connect v1.18.1 // indirect connectrpc.com/grpcreflect v1.3.0 // indirect - github.com/BurntSushi/toml v1.5.0 // indirect github.com/DataDog/zstd v1.5.2 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/StephenButtolph/canoto v0.17.3 // indirect @@ -61,7 +61,6 @@ require ( github.com/bits-and-blooms/bitset v1.20.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.5 // indirect github.com/btcsuite/btcd/btcutil v1.1.3 // indirect - github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cenkalti/backoff/v5 v5.0.2 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect diff --git a/graft/coreth/go.sum b/graft/coreth/go.sum index 230d9e5312f9..a7e85a385d22 100644 --- a/graft/coreth/go.sum +++ b/graft/coreth/go.sum @@ -26,6 +26,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +github.com/ava-labs/coreth v0.16.0 h1:0AcmiIR3118JrnoePO3ho2EyaySmEMvlbCmk3RcYRxk= +github.com/ava-labs/coreth v0.16.0/go.mod h1:uGr1C7BP0+dWhvsIouhuH0yCyI8YDgS6sfEFIExs0iI= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15 h1:NAVjEu508HwdgbxH/xQxMQoBUgYUn9RQf0VeCrhtYMY= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15/go.mod h1:hR/JSGXxST9B9olwu/NpLXHAykfAyNGfyKnYQqiiOeE= github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2 h1:hQ15IJxY7WOKqeJqCXawsiXh0NZTzmoQOemkWHz7rr4= @@ -37,6 +39,7 @@ github.com/bits-and-blooms/bitset v1.20.0 h1:2F+rfL86jE2d/bmw7OhqUg2Sj/1rURkBn3M github.com/bits-and-blooms/bitset v1.20.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M= +github.com/btcsuite/btcd v0.23.0 h1:V2/ZgjfDFIygAX3ZapeigkVBoVUtOJKSwrhZdlpSvaA= github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA= github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= diff --git a/graft/coreth/plugin/evm/customrawdb/accessors_metadata_ext.go b/graft/coreth/plugin/evm/customrawdb/accessors_metadata_ext.go deleted file mode 100644 index 709ea157ffdb..000000000000 --- a/graft/coreth/plugin/evm/customrawdb/accessors_metadata_ext.go +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package customrawdb - -import ( - "fmt" - "time" - - "github.com/ava-labs/libevm/common" - "github.com/ava-labs/libevm/ethdb" - "github.com/ava-labs/libevm/rlp" -) - -// writeCurrentTimeMarker writes a marker of the current time in the db at `key`. -func writeCurrentTimeMarker(db ethdb.KeyValueStore, key []byte) error { - data, err := rlp.EncodeToBytes(uint64(time.Now().Unix())) - if err != nil { - return err - } - return db.Put(key, data) -} - -// readTimeMarker reads the timestamp stored at `key` -func readTimeMarker(db ethdb.KeyValueStore, key []byte) (time.Time, error) { - data, err := db.Get(key) - if err != nil { - return time.Time{}, err - } - - var unix uint64 - if err := rlp.DecodeBytes(data, &unix); err != nil { - return time.Time{}, err - } - - return time.Unix(int64(unix), 0), nil -} - -// WriteOfflinePruning writes a time marker of the last attempt to run offline pruning. -// The marker is written when offline pruning completes and is deleted when the node -// is started successfully with offline pruning disabled. This ensures users must -// disable offline pruning and start their node successfully between runs of offline -// pruning. -func WriteOfflinePruning(db ethdb.KeyValueStore) error { - return writeCurrentTimeMarker(db, offlinePruningKey) -} - -// ReadOfflinePruning reads the most recent timestamp of an attempt to run offline -// pruning if present. -func ReadOfflinePruning(db ethdb.KeyValueStore) (time.Time, error) { - return readTimeMarker(db, offlinePruningKey) -} - -// DeleteOfflinePruning deletes any marker of the last attempt to run offline pruning. -func DeleteOfflinePruning(db ethdb.KeyValueStore) error { - return db.Delete(offlinePruningKey) -} - -// WritePopulateMissingTries writes a marker for the current attempt to populate -// missing tries. -func WritePopulateMissingTries(db ethdb.KeyValueStore) error { - return writeCurrentTimeMarker(db, populateMissingTriesKey) -} - -// ReadPopulateMissingTries reads the most recent timestamp of an attempt to -// re-populate missing trie nodes. -func ReadPopulateMissingTries(db ethdb.KeyValueStore) (time.Time, error) { - return readTimeMarker(db, populateMissingTriesKey) -} - -// DeletePopulateMissingTries deletes any marker of the last attempt to -// re-populate missing trie nodes. -func DeletePopulateMissingTries(db ethdb.KeyValueStore) error { - return db.Delete(populateMissingTriesKey) -} - -// WritePruningDisabled writes a marker to track whether the node has ever run -// with pruning disabled. -func WritePruningDisabled(db ethdb.KeyValueStore) error { - return db.Put(pruningDisabledKey, nil) -} - -// HasPruningDisabled returns true if there is a marker present indicating that -// the node has run with pruning disabled at some pooint. -func HasPruningDisabled(db ethdb.KeyValueStore) (bool, error) { - return db.Has(pruningDisabledKey) -} - -// WriteAcceptorTip writes `hash` as the last accepted block that has been fully processed. -func WriteAcceptorTip(db ethdb.KeyValueWriter, hash common.Hash) error { - return db.Put(acceptorTipKey, hash[:]) -} - -// ReadAcceptorTip reads the hash of the last accepted block that was fully processed. -// If there is no value present (the index is being initialized for the first time), then the -// empty hash is returned. -func ReadAcceptorTip(db ethdb.KeyValueReader) (common.Hash, error) { - has, err := db.Has(acceptorTipKey) - if err != nil { - return common.Hash{}, err - } - if !has { - // If the index is not present on disk, the [acceptorTipKey] index has not been initialized yet. - return common.Hash{}, nil - } - h, err := db.Get(acceptorTipKey) - if err != nil { - return common.Hash{}, err - } - if len(h) != common.HashLength { - return common.Hash{}, fmt.Errorf("value has incorrect length %d", len(h)) - } - return common.BytesToHash(h), nil -} diff --git a/graft/coreth/plugin/evm/customrawdb/accessors_snapshot_ext.go b/graft/coreth/plugin/evm/customrawdb/accessors_snapshot_ext.go deleted file mode 100644 index cd1ab1a92651..000000000000 --- a/graft/coreth/plugin/evm/customrawdb/accessors_snapshot_ext.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package customrawdb - -import ( - "github.com/ava-labs/libevm/common" - "github.com/ava-labs/libevm/core/rawdb" - "github.com/ava-labs/libevm/ethdb" - "github.com/ava-labs/libevm/log" -) - -// ReadSnapshotBlockHash retrieves the hash of the block whose state is contained in -// the persisted snapshot. -func ReadSnapshotBlockHash(db ethdb.KeyValueReader) common.Hash { - data, _ := db.Get(snapshotBlockHashKey) - if len(data) != common.HashLength { - return common.Hash{} - } - return common.BytesToHash(data) -} - -// WriteSnapshotBlockHash stores the root of the block whose state is contained in -// the persisted snapshot. -func WriteSnapshotBlockHash(db ethdb.KeyValueWriter, blockHash common.Hash) { - if err := db.Put(snapshotBlockHashKey, blockHash[:]); err != nil { - log.Crit("Failed to store snapshot block hash", "err", err) - } -} - -// DeleteSnapshotBlockHash deletes the hash of the block whose state is contained in -// the persisted snapshot. Since snapshots are not immutable, this method can -// be used during updates, so a crash or failure will mark the entire snapshot -// invalid. -func DeleteSnapshotBlockHash(db ethdb.KeyValueWriter) { - if err := db.Delete(snapshotBlockHashKey); err != nil { - log.Crit("Failed to remove snapshot block hash", "err", err) - } -} - -// IterateAccountSnapshots returns an iterator for walking all of the accounts in the snapshot -func IterateAccountSnapshots(db ethdb.Iteratee) ethdb.Iterator { - it := db.NewIterator(rawdb.SnapshotAccountPrefix, nil) - keyLen := len(rawdb.SnapshotAccountPrefix) + common.HashLength - return rawdb.NewKeyLengthIterator(it, keyLen) -} diff --git a/graft/coreth/plugin/evm/customrawdb/accessors_state_sync_test.go b/graft/coreth/plugin/evm/customrawdb/accessors_state_sync_test.go deleted file mode 100644 index 6a57572e4f0a..000000000000 --- a/graft/coreth/plugin/evm/customrawdb/accessors_state_sync_test.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package customrawdb - -import ( - "slices" - "testing" - - "github.com/ava-labs/libevm/common" - "github.com/ava-labs/libevm/core/rawdb" - "github.com/stretchr/testify/require" -) - -func TestClearPrefix(t *testing.T) { - require := require.New(t) - db := rawdb.NewMemoryDatabase() - // add a key that should be cleared - require.NoError(WriteSyncSegment(db, common.Hash{1}, common.Hash{})) - - // add a key that should not be cleared - key := slices.Concat(syncSegmentsPrefix, []byte("foo")) - require.NoError(db.Put(key, []byte("bar"))) - - require.NoError(ClearAllSyncSegments(db)) - - count := 0 - it := db.NewIterator(syncSegmentsPrefix, nil) - defer it.Release() - for it.Next() { - count++ - } - require.NoError(it.Error()) - require.Equal(1, count) -} diff --git a/graft/coreth/plugin/evm/customrawdb/database_ext.go b/graft/coreth/plugin/evm/customrawdb/database_ext.go deleted file mode 100644 index c301a5bfff54..000000000000 --- a/graft/coreth/plugin/evm/customrawdb/database_ext.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package customrawdb - -import ( - "bytes" - "fmt" - - "github.com/ava-labs/libevm/common" - "github.com/ava-labs/libevm/core/rawdb" - "github.com/ava-labs/libevm/ethdb" -) - -// InspectDatabase traverses the entire database and checks the size -// of all different categories of data. -func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { - type stat = rawdb.DatabaseStat - stats := []struct { - name string - keyLen int - keyPrefix []byte - stat *stat - }{ - {"Trie segments", syncSegmentsKeyLength, syncSegmentsPrefix, &stat{}}, - {"Storage tries to fetch", syncStorageTriesKeyLength, syncStorageTriesPrefix, &stat{}}, - {"Code to fetch", codeToFetchKeyLength, CodeToFetchPrefix, &stat{}}, - {"Block numbers synced to", syncPerformedKeyLength, syncPerformedPrefix, &stat{}}, - } - - options := []rawdb.InspectDatabaseOption{ - rawdb.WithDatabaseMetadataKeys(func(key []byte) bool { - return bytes.Equal(key, snapshotBlockHashKey) || - bytes.Equal(key, syncRootKey) - }), - rawdb.WithDatabaseStatRecorder(func(key []byte, size common.StorageSize) bool { - for _, s := range stats { - if len(key) == s.keyLen && bytes.HasPrefix(key, s.keyPrefix) { - s.stat.Add(size) - return true - } - } - return false - }), - rawdb.WithDatabaseStatsTransformer(func(rows [][]string) [][]string { - newRows := make([][]string, 0, len(rows)) - for _, row := range rows { - switch db, cat := row[0], row[1]; { - // Discard rows specific to libevm (geth) but irrelevant to coreth. - case db == "Key-Value store" && (cat == "Difficulties" || cat == "Beacon sync headers"): - case db == "Ancient store (Chain)": - default: - newRows = append(newRows, row) - } - } - for _, s := range stats { - newRows = append(newRows, []string{"State sync", s.name, s.stat.Size(), s.stat.Count()}) - } - return newRows - }), - } - - return rawdb.InspectDatabase(db, keyPrefix, keyStart, options...) -} - -// ParseStateSchemeExt parses the state scheme from the provided string. -func ParseStateSchemeExt(provided string, disk ethdb.Database) (string, error) { - // Check for custom scheme - if provided == FirewoodScheme { - if diskScheme := rawdb.ReadStateScheme(disk); diskScheme != "" { - // Valid scheme on disk mismatched - return "", fmt.Errorf("state scheme %s already set on disk, can't use Firewood", diskScheme) - } - // If no conflicting scheme is found, is valid. - return FirewoodScheme, nil - } - - // Check for valid eth scheme - return rawdb.ParseStateScheme(provided, disk) -} diff --git a/graft/coreth/plugin/evm/customrawdb/database_ext_test.go b/graft/coreth/plugin/evm/customrawdb/database_ext_test.go deleted file mode 100644 index 2b786b7f8177..000000000000 --- a/graft/coreth/plugin/evm/customrawdb/database_ext_test.go +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package customrawdb - -import ( - "fmt" - - "github.com/ava-labs/libevm/common" - "github.com/ava-labs/libevm/core/rawdb" - "github.com/ava-labs/libevm/ethdb" -) - -func ExampleInspectDatabase() { - db := &stubDatabase{ - iterator: &stubIterator{}, - } - - // Extra metadata keys: (17 + 32) + (12 + 32) = 93 bytes - WriteSnapshotBlockHash(db, common.Hash{}) - rawdb.WriteSnapshotRoot(db, common.Hash{}) - // Trie segments: (77 + 2) + 1 = 80 bytes - _ = WriteSyncSegment(db, common.Hash{}, common.Hash{}) - // Storage tries to fetch: 76 + 1 = 77 bytes - _ = WriteSyncStorageTrie(db, common.Hash{}, common.Hash{}) - // Code to fetch: 34 + 0 = 34 bytes - AddCodeToFetch(db, common.Hash{}) - // Block numbers synced to: 22 + 1 = 23 bytes - _ = WriteSyncPerformed(db, 0) - - keyPrefix := []byte(nil) - keyStart := []byte(nil) - - err := InspectDatabase(db, keyPrefix, keyStart) - if err != nil { - fmt.Println(err) - } - // Output: - // +-----------------+-------------------------+----------+-------+ - // | DATABASE | CATEGORY | SIZE | ITEMS | - // +-----------------+-------------------------+----------+-------+ - // | Key-Value store | Headers | 0.00 B | 0 | - // | Key-Value store | Bodies | 0.00 B | 0 | - // | Key-Value store | Receipt lists | 0.00 B | 0 | - // | Key-Value store | Block number->hash | 0.00 B | 0 | - // | Key-Value store | Block hash->number | 0.00 B | 0 | - // | Key-Value store | Transaction index | 0.00 B | 0 | - // | Key-Value store | Bloombit index | 0.00 B | 0 | - // | Key-Value store | Contract codes | 0.00 B | 0 | - // | Key-Value store | Hash trie nodes | 0.00 B | 0 | - // | Key-Value store | Path trie state lookups | 0.00 B | 0 | - // | Key-Value store | Path trie account nodes | 0.00 B | 0 | - // | Key-Value store | Path trie storage nodes | 0.00 B | 0 | - // | Key-Value store | Trie preimages | 0.00 B | 0 | - // | Key-Value store | Account snapshot | 0.00 B | 0 | - // | Key-Value store | Storage snapshot | 0.00 B | 0 | - // | Key-Value store | Clique snapshots | 0.00 B | 0 | - // | Key-Value store | Singleton metadata | 93.00 B | 2 | - // | Light client | CHT trie nodes | 0.00 B | 0 | - // | Light client | Bloom trie nodes | 0.00 B | 0 | - // | State sync | Trie segments | 78.00 B | 1 | - // | State sync | Storage tries to fetch | 77.00 B | 1 | - // | State sync | Code to fetch | 34.00 B | 1 | - // | State sync | Block numbers synced to | 23.00 B | 1 | - // +-----------------+-------------------------+----------+-------+ - // | TOTAL | 305.00 B | | - // +-----------------+-------------------------+----------+-------+ -} - -type stubDatabase struct { - ethdb.Database - iterator *stubIterator -} - -func (s *stubDatabase) NewIterator(_, _ []byte) ethdb.Iterator { - return s.iterator -} - -// AncientSize is used in [InspectDatabase] to determine the ancient sizes. -func (*stubDatabase) AncientSize(string) (uint64, error) { - return 0, nil -} - -func (*stubDatabase) Ancients() (uint64, error) { - return 0, nil -} - -func (*stubDatabase) Tail() (uint64, error) { - return 0, nil -} - -func (s *stubDatabase) Put(key, value []byte) error { - s.iterator.kvs = append(s.iterator.kvs, keyValue{key: key, value: value}) - return nil -} - -func (*stubDatabase) Get([]byte) ([]byte, error) { - return nil, nil -} - -func (*stubDatabase) ReadAncients(func(ethdb.AncientReaderOp) error) error { - return nil -} - -type stubIterator struct { - ethdb.Iterator - i int // see [stubIterator.pos] - kvs []keyValue -} - -type keyValue struct { - key []byte - value []byte -} - -// pos returns the true iterator position, which is otherwise off by one because -// Next() is called _before_ usage. -func (s *stubIterator) pos() int { - return s.i - 1 -} - -func (s *stubIterator) Next() bool { - s.i++ - return s.pos() < len(s.kvs) -} - -func (*stubIterator) Release() {} - -func (s *stubIterator) Key() []byte { - return s.kvs[s.pos()].key -} - -func (s *stubIterator) Value() []byte { - return s.kvs[s.pos()].value -} diff --git a/graft/coreth/plugin/evm/customtypes/block_test.go b/graft/coreth/plugin/evm/customtypes/block_test.go index 499d2f372830..7ddbdf2ba689 100644 --- a/graft/coreth/plugin/evm/customtypes/block_test.go +++ b/graft/coreth/plugin/evm/customtypes/block_test.go @@ -42,6 +42,9 @@ import ( "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/rlp" + "github.com/ava-labs/coreth/internal/blocktest" + "github.com/ava-labs/coreth/params" + // This test file has to be in package types_test to avoid a circular // dependency when importing `params`. We dot-import the package to mimic // regular same-package behaviour. diff --git a/graft/coreth/plugin/evm/customtypes/gen_header_serializable_rlp.go b/graft/coreth/plugin/evm/customtypes/gen_header_serializable_rlp.go index 69ba9c15e900..08d6e7edec42 100644 --- a/graft/coreth/plugin/evm/customtypes/gen_header_serializable_rlp.go +++ b/graft/coreth/plugin/evm/customtypes/gen_header_serializable_rlp.go @@ -2,8 +2,11 @@ package customtypes -import "github.com/ava-labs/libevm/rlp" -import "io" +import ( + "io" + + "github.com/ava-labs/libevm/rlp" +) func (obj *HeaderSerializable) EncodeRLP(_w io.Writer) error { w := rlp.NewEncoderBuffer(_w) diff --git a/graft/coreth/plugin/evm/customtypes/hashing_test.go b/graft/coreth/plugin/evm/customtypes/hashing_test.go index ca1958e043ee..71fd7a161881 100644 --- a/graft/coreth/plugin/evm/customtypes/hashing_test.go +++ b/graft/coreth/plugin/evm/customtypes/hashing_test.go @@ -32,7 +32,6 @@ import ( "fmt" "io" "math/big" - mrand "math/rand" "testing" "github.com/ava-labs/libevm/common" @@ -43,6 +42,8 @@ import ( "github.com/ava-labs/libevm/rlp" "github.com/ava-labs/libevm/trie" "github.com/ava-labs/libevm/triedb" + + mrand "math/rand" ) func TestDeriveSha(t *testing.T) { diff --git a/graft/coreth/plugin/evm/vm.go b/graft/coreth/plugin/evm/vm.go index 44fac1fa0d31..63e8642c7f8d 100644 --- a/graft/coreth/plugin/evm/vm.go +++ b/graft/coreth/plugin/evm/vm.go @@ -54,7 +54,6 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/params" "github.com/ava-labs/avalanchego/graft/coreth/params/extras" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/config" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/extension" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/gossip" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/message" @@ -80,6 +79,7 @@ import ( "github.com/ava-labs/avalanchego/vms/components/gas" "github.com/ava-labs/avalanchego/vms/evm/acp176" "github.com/ava-labs/avalanchego/vms/evm/acp226" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" corethlog "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/log" warpcontract "github.com/ava-labs/avalanchego/graft/coreth/precompile/contracts/warp" diff --git a/graft/coreth/plugin/evm/vm_test.go b/graft/coreth/plugin/evm/vm_test.go index 157ece7c1513..c9fd54fd03d5 100644 --- a/graft/coreth/plugin/evm/vm_test.go +++ b/graft/coreth/plugin/evm/vm_test.go @@ -56,6 +56,7 @@ import ( "github.com/ava-labs/avalanchego/vms/evm/acp176" "github.com/ava-labs/avalanchego/vms/evm/acp226" "github.com/ava-labs/avalanchego/vms/evm/predicate" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload" warpcontract "github.com/ava-labs/avalanchego/graft/coreth/precompile/contracts/warp" diff --git a/graft/coreth/plugin/evm/vmtest/test_syncervm.go b/graft/coreth/plugin/evm/vmtest/test_syncervm.go index b39703d99cca..d41e9e7b21cf 100644 --- a/graft/coreth/plugin/evm/vmtest/test_syncervm.go +++ b/graft/coreth/plugin/evm/vmtest/test_syncervm.go @@ -12,6 +12,8 @@ import ( "testing" "time" + "github.com/ava-labs/avalanchego/database/prefixdb" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/types" @@ -20,14 +22,11 @@ import ( "github.com/ava-labs/libevm/rlp" "github.com/ava-labs/libevm/trie" "github.com/stretchr/testify/require" - - "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/graft/coreth/consensus/dummy" "github.com/ava-labs/avalanchego/graft/coreth/constants" "github.com/ava-labs/avalanchego/graft/coreth/core" "github.com/ava-labs/avalanchego/graft/coreth/core/coretest" "github.com/ava-labs/avalanchego/graft/coreth/params/paramstest" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customtypes" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/extension" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/vmsync" @@ -43,6 +42,7 @@ import ( "github.com/ava-labs/avalanchego/vms/components/chain" "github.com/ava-labs/avalanchego/vms/evm/database" "github.com/ava-labs/avalanchego/vms/evm/predicate" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" avalancheatomic "github.com/ava-labs/avalanchego/chains/atomic" avalanchedatabase "github.com/ava-labs/avalanchego/database" @@ -653,16 +653,11 @@ func generateAndAcceptBlocks(t *testing.T, vm extension.InnerVM, numBlocks int, vm.Ethereum().BlockChain().DrainAcceptorQueue() } -// requireSyncPerformedHeights iterates over all heights the VM has synced to and -// verifies they all match the heights present in `expected`. -func requireSyncPerformedHeights(t *testing.T, db ethdb.Iteratee, expected map[uint64]struct{}) { - it := customrawdb.NewSyncPerformedIterator(db) - defer it.Release() - - found := make(map[uint64]struct{}, len(expected)) - for it.Next() { - found[customrawdb.UnpackSyncPerformedKey(it.Key())] = struct{}{} - } - require.NoError(t, it.Error()) - require.Equal(t, expected, found) +// requireSyncPerformedHeight verifies the latest sync performed height matches expectations. +// Pass 0 to verify no sync was performed. +func requireSyncPerformedHeight(t *testing.T, db ethdb.KeyValueStore, expected uint64) { + t.Helper() + latest, err := customrawdb.GetLatestSyncPerformed(db) + require.NoError(t, err) + require.Equal(t, expected, latest, "sync performed height mismatch: expected %d, got %d", expected, latest) } diff --git a/graft/coreth/plugin/evm/vmtest/test_vm.go b/graft/coreth/plugin/evm/vmtest/test_vm.go index abea48c7734e..81e1ce1f0b3e 100644 --- a/graft/coreth/plugin/evm/vmtest/test_vm.go +++ b/graft/coreth/plugin/evm/vmtest/test_vm.go @@ -9,18 +9,17 @@ import ( "fmt" "testing" - "github.com/ava-labs/libevm/core/rawdb" - "github.com/ava-labs/libevm/core/types" - "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/api/metrics" "github.com/ava-labs/avalanchego/database/prefixdb" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/extension" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/engine/enginetest" "github.com/ava-labs/avalanchego/upgrade/upgradetest" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" + "github.com/ava-labs/libevm/core/rawdb" + "github.com/ava-labs/libevm/core/types" + "github.com/stretchr/testify/require" avalancheatomic "github.com/ava-labs/avalanchego/chains/atomic" commoneng "github.com/ava-labs/avalanchego/snow/engine/common" diff --git a/graft/coreth/sync/statesync/code_queue.go b/graft/coreth/sync/statesync/code_queue.go index e61ff321f75a..74123630ad85 100644 --- a/graft/coreth/sync/statesync/code_queue.go +++ b/graft/coreth/sync/statesync/code_queue.go @@ -9,12 +9,11 @@ import ( "fmt" "sync" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/ethdb" "github.com/ava-labs/libevm/libevm/options" - - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" ) const defaultQueueCapacity = 5000 @@ -136,7 +135,7 @@ func (q *CodeQueue) AddCode(ctx context.Context, codeHashes []common.Hash) error // key rather than growing DB usage. The consumer deletes the marker after // fulfilling the request (or when it detects code is already present). for _, codeHash := range codeHashes { - customrawdb.AddCodeToFetch(batch, codeHash) + customrawdb.WriteCodeToFetch(batch, codeHash) } if err := batch.Write(); err != nil { diff --git a/graft/coreth/sync/statesync/code_queue_test.go b/graft/coreth/sync/statesync/code_queue_test.go index f0f3b6437d5d..147b7c96033e 100644 --- a/graft/coreth/sync/statesync/code_queue_test.go +++ b/graft/coreth/sync/statesync/code_queue_test.go @@ -9,15 +9,14 @@ import ( "testing" "time" + "github.com/ava-labs/avalanchego/utils/set" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/crypto" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" "go.uber.org/goleak" - - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" - "github.com/ava-labs/avalanchego/utils/set" ) func TestCodeQueue(t *testing.T) { @@ -86,7 +85,7 @@ func TestCodeQueue(t *testing.T) { rawdb.WriteCode(db, hash, code) } for hash := range tt.alreadyToFetch { - customrawdb.AddCodeToFetch(db, hash) + customrawdb.WriteCodeToFetch(db, hash) } quit := make(chan struct{}) diff --git a/graft/coreth/sync/statesync/code_syncer.go b/graft/coreth/sync/statesync/code_syncer.go index 1ac8c47b5d71..adb79f1edb4d 100644 --- a/graft/coreth/sync/statesync/code_syncer.go +++ b/graft/coreth/sync/statesync/code_syncer.go @@ -8,13 +8,13 @@ import ( "fmt" "sync" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/ethdb" "github.com/ava-labs/libevm/libevm/options" "golang.org/x/sync/errgroup" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/message" syncpkg "github.com/ava-labs/avalanchego/graft/coreth/sync" diff --git a/graft/coreth/sync/statesync/code_syncer_test.go b/graft/coreth/sync/statesync/code_syncer_test.go index b285f4f4005e..c0828f7b84d9 100644 --- a/graft/coreth/sync/statesync/code_syncer_test.go +++ b/graft/coreth/sync/statesync/code_syncer_test.go @@ -8,6 +8,8 @@ import ( "errors" "testing" + "github.com/ava-labs/avalanchego/utils" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/crypto" @@ -15,10 +17,8 @@ import ( "github.com/ava-labs/libevm/ethdb/memorydb" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/message" "github.com/ava-labs/avalanchego/graft/coreth/sync/handlers" - "github.com/ava-labs/avalanchego/utils" statesyncclient "github.com/ava-labs/avalanchego/graft/coreth/sync/client" handlerstats "github.com/ava-labs/avalanchego/graft/coreth/sync/handlers/stats" @@ -144,7 +144,7 @@ func TestCodeSyncerAddsInProgressCodeHashes(t *testing.T) { codeBytes := utils.RandomBytes(100) codeHash := crypto.Keccak256Hash(codeBytes) clientDB := rawdb.NewMemoryDatabase() - customrawdb.AddCodeToFetch(clientDB, codeHash) + customrawdb.WriteCodeToFetch(clientDB, codeHash) testCodeSyncer(t, codeSyncerTest{ clientDB: clientDB, codeRequestHashes: nil, @@ -166,7 +166,7 @@ func TestCodeSyncerAddsMoreInProgressThanQueueSize(t *testing.T) { db := rawdb.NewMemoryDatabase() for _, codeHash := range codeHashes { - customrawdb.AddCodeToFetch(db, codeHash) + customrawdb.WriteCodeToFetch(db, codeHash) } testCodeSyncer(t, codeSyncerTest{ diff --git a/graft/coreth/sync/statesync/sync_test.go b/graft/coreth/sync/statesync/sync_test.go index c00483a94d4d..69beb505e9a4 100644 --- a/graft/coreth/sync/statesync/sync_test.go +++ b/graft/coreth/sync/statesync/sync_test.go @@ -11,6 +11,7 @@ import ( "sync/atomic" "testing" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/types" @@ -23,7 +24,6 @@ import ( "golang.org/x/sync/errgroup" "github.com/ava-labs/avalanchego/graft/coreth/core/state/snapshot" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/message" "github.com/ava-labs/avalanchego/graft/coreth/sync/handlers" "github.com/ava-labs/avalanchego/graft/coreth/sync/statesync/statesynctest" diff --git a/graft/coreth/sync/statesync/trie_queue.go b/graft/coreth/sync/statesync/trie_queue.go index 8f6e8b0df6c8..210cfd6a048f 100644 --- a/graft/coreth/sync/statesync/trie_queue.go +++ b/graft/coreth/sync/statesync/trie_queue.go @@ -4,10 +4,9 @@ package statesync import ( + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/ethdb" - - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" ) // trieQueue persists storage trie roots with their associated @@ -76,7 +75,7 @@ func (t *trieQueue) getNextTrie() (common.Hash, []common.Hash, bool, error) { // Iterate over the keys to find the next storage trie root and all of the account hashes that contain the same storage root. for it.Next() { // Unpack the state root and account hash from the current key - nextRoot, nextAccount := customrawdb.UnpackSyncStorageTrieKey(it.Key()) + nextRoot, nextAccount := customrawdb.ParseSyncStorageTrieKey(it.Key()) // Set the root for the first pass if root == (common.Hash{}) { root = nextRoot @@ -105,7 +104,7 @@ func (t *trieQueue) countTries() (int, error) { ) for it.Next() { - nextRoot, _ := customrawdb.UnpackSyncStorageTrieKey(it.Key()) + nextRoot, _ := customrawdb.ParseSyncStorageTrieKey(it.Key()) if root == (common.Hash{}) || root != nextRoot { root = nextRoot tries++ diff --git a/graft/coreth/sync/statesync/trie_segments.go b/graft/coreth/sync/statesync/trie_segments.go index 29bcec64c48b..b314ec4981f3 100644 --- a/graft/coreth/sync/statesync/trie_segments.go +++ b/graft/coreth/sync/statesync/trie_segments.go @@ -10,16 +10,16 @@ import ( "fmt" "sync" + "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/ethdb" "github.com/ava-labs/libevm/log" "github.com/ava-labs/libevm/trie" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/message" "github.com/ava-labs/avalanchego/graft/coreth/utils" - "github.com/ava-labs/avalanchego/utils/wrappers" syncclient "github.com/ava-labs/avalanchego/graft/coreth/sync/client" ) @@ -102,7 +102,7 @@ func (t *trieToSync) loadSegments() error { // key immediately prior to the segment we found on disk. // This is because we do not persist the beginning of // the first segment. - _, segmentStart := customrawdb.UnpackSyncSegmentKey(it.Key()) + _, segmentStart := customrawdb.ParseSyncSegmentKey(it.Key()) segmentStartPos := binary.BigEndian.Uint16(segmentStart[:wrappers.ShortLen]) t.addSegment(prevSegmentStart, addPadding(segmentStartPos-1, 0xff)) diff --git a/graft/coreth/tests/state_test_util.go b/graft/coreth/tests/state_test_util.go index 69bd22581b61..fd805da620ae 100644 --- a/graft/coreth/tests/state_test_util.go +++ b/graft/coreth/tests/state_test_util.go @@ -32,10 +32,10 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/core/extstate" "github.com/ava-labs/avalanchego/graft/coreth/core/state/snapshot" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/triedb/firewood" "github.com/ava-labs/avalanchego/graft/coreth/triedb/hashdb" "github.com/ava-labs/avalanchego/graft/coreth/triedb/pathdb" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/state" From 96d4893ef3e2f0ad8ba32b6e27ac85dd9b08a581 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Mon, 6 Oct 2025 13:34:43 +0300 Subject: [PATCH 02/25] fix: rlpgen import issue and update to latest avalanchego version --- graft/coreth/go.mod | 1 + graft/coreth/go.sum | 18 ++++++++++++++++++ .../customtypes/gen_header_serializable_rlp.go | 7 ++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/graft/coreth/go.mod b/graft/coreth/go.mod index b0ff41a1f9a7..d1c2b142ef58 100644 --- a/graft/coreth/go.mod +++ b/graft/coreth/go.mod @@ -78,6 +78,7 @@ require ( github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/ethereum/c-kzg-4844 v1.0.0 // indirect + github.com/fatih/structtag v1.2.0 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect diff --git a/graft/coreth/go.sum b/graft/coreth/go.sum index a7e85a385d22..8b519b59b5a3 100644 --- a/graft/coreth/go.sum +++ b/graft/coreth/go.sum @@ -26,12 +26,23 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +<<<<<<< HEAD github.com/ava-labs/coreth v0.16.0 h1:0AcmiIR3118JrnoePO3ho2EyaySmEMvlbCmk3RcYRxk= github.com/ava-labs/coreth v0.16.0/go.mod h1:uGr1C7BP0+dWhvsIouhuH0yCyI8YDgS6sfEFIExs0iI= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15 h1:NAVjEu508HwdgbxH/xQxMQoBUgYUn9RQf0VeCrhtYMY= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15/go.mod h1:hR/JSGXxST9B9olwu/NpLXHAykfAyNGfyKnYQqiiOeE= github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2 h1:hQ15IJxY7WOKqeJqCXawsiXh0NZTzmoQOemkWHz7rr4= github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2/go.mod h1:DqSotSn4Dx/UJV+d3svfW8raR+cH7+Ohl9BpsQ5HlGU= +======= +github.com/ava-labs/avalanchego v1.13.6-0.20251003124158-f1854079a644 h1:6evg50kddMsGxWDXtBAcnGet9UjWx93hliJZnowSqVg= +github.com/ava-labs/avalanchego v1.13.6-0.20251003124158-f1854079a644/go.mod h1:4kotB9pnVuXpwZDVdcB48cSGzRLcanEZ1ZJj2gJo73o= +github.com/ava-labs/avalanchego v1.13.6-0.20251006102538-b79eeab14be3 h1:9Kb7wGBKkhB/fxIdgclXmmw+PaS6ZeKAgAutvoRs0LA= +github.com/ava-labs/avalanchego v1.13.6-0.20251006102538-b79eeab14be3/go.mod h1:yplWYV/FzAZeYAhy0yOj8wjJA1PCdTPxQf8Wzpwg6DY= +github.com/ava-labs/firewood-go-ethhash/ffi v0.0.12 h1:aMcrLbpJ/dyu2kZDf/Di/4JIWsUcYPyTDKymiHpejt0= +github.com/ava-labs/firewood-go-ethhash/ffi v0.0.12/go.mod h1:cq89ua3iiZ5wPBALTEQS5eG8DIZcs7ov6OiL4YR1BVY= +github.com/ava-labs/libevm v1.13.15-0.20251002164226-35926db4d661 h1:lt4yQE1HMvxWrdD5RFj+h9kWUsZK2rmNohvkeQsbG9M= +github.com/ava-labs/libevm v1.13.15-0.20251002164226-35926db4d661/go.mod h1:ivRC/KojP8sai7j8WnpXIReQpcRklL2bIzoysnjpARQ= +>>>>>>> dd36d2f075 (fix: rlpgen import issue and update to latest avalanchego version) github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= @@ -145,6 +156,13 @@ github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHE github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= +<<<<<<< HEAD +======= +github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= +github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= +github.com/fjl/gencodec v0.1.1 h1:DhQY29Q6JLXB/GgMqE86NbOEuvckiYcJCbXFu02toms= +github.com/fjl/gencodec v0.1.1/go.mod h1:chDHL3wKXuBgauP8x3XNZkl5EIAR5SoCTmmmDTZRzmw= +>>>>>>> dd36d2f075 (fix: rlpgen import issue and update to latest avalanchego version) github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= diff --git a/graft/coreth/plugin/evm/customtypes/gen_header_serializable_rlp.go b/graft/coreth/plugin/evm/customtypes/gen_header_serializable_rlp.go index 08d6e7edec42..69ba9c15e900 100644 --- a/graft/coreth/plugin/evm/customtypes/gen_header_serializable_rlp.go +++ b/graft/coreth/plugin/evm/customtypes/gen_header_serializable_rlp.go @@ -2,11 +2,8 @@ package customtypes -import ( - "io" - - "github.com/ava-labs/libevm/rlp" -) +import "github.com/ava-labs/libevm/rlp" +import "io" func (obj *HeaderSerializable) EncodeRLP(_w io.Writer) error { w := rlp.NewEncoderBuffer(_w) From 74692e4ad88218309733362884be2319c0aea6dc Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Mon, 6 Oct 2025 14:11:58 +0300 Subject: [PATCH 03/25] ci: update ci.yml with the updated avalanchego version --- graft/coreth/.github/workflows/ci.yml | 146 ++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 graft/coreth/.github/workflows/ci.yml diff --git a/graft/coreth/.github/workflows/ci.yml b/graft/coreth/.github/workflows/ci.yml new file mode 100644 index 000000000000..40b49d5bc9ef --- /dev/null +++ b/graft/coreth/.github/workflows/ci.yml @@ -0,0 +1,146 @@ +name: CI +on: + push: + branches: + - master + pull_request: + merge_group: + types: [checks_requested] + workflow_dispatch: + inputs: + avalanchegoRepo: + description: "avalanchego github repository" + required: true + default: "ava-labs/avalanchego" + avalanchegoBranch: + description: "avalanchego branch" + required: true + default: "master" + +jobs: + lint_test: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: check out ${{ github.event.inputs.avalanchegoRepo }} ${{ github.event.inputs.avalanchegoBranch }} + if: ${{ github.event_name == 'workflow_dispatch' }} + uses: actions/checkout@v4 + with: + repository: ${{ github.event.inputs.avalanchegoRepo }} + ref: ${{ github.event.inputs.avalanchegoBranch }} + path: avalanchego + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + cache-dependency-path: | + go.sum + tools/go.sum + tools/legacy-golangci-lint.sum + - name: change avalanchego dep + if: ${{ github.event_name == 'workflow_dispatch' }} + run: | + go mod edit -replace github.com/ava-labs/avalanchego=./avalanchego + go mod tidy + go clean -modcache + - name: Run all lint checks + run: ./scripts/run_task.sh lint-all-ci + - name: Check go.mod and go.sum are up-to-date + run: ./scripts/run_task.sh check-go-mod-tidy + - name: Ensure consistent avalanchego version + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./scripts/run_task.sh check-avalanchego-version + + unit_test: + name: Golang Unit Tests (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-22.04, ubuntu-latest] + steps: + - uses: actions/checkout@v4 + - name: check out ${{ github.event.inputs.avalanchegoRepo }} ${{ github.event.inputs.avalanchegoBranch }} + if: ${{ github.event_name == 'workflow_dispatch' }} + uses: actions/checkout@v4 + with: + repository: ${{ github.event.inputs.avalanchegoRepo }} + ref: ${{ github.event.inputs.avalanchegoBranch }} + path: avalanchego + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + cache-dependency-path: | + go.sum + tools/go.sum + - name: change avalanchego dep + if: ${{ github.event_name == 'workflow_dispatch' }} + run: | + go mod edit -replace github.com/ava-labs/avalanchego=./avalanchego + go mod tidy + - run: go mod download + - name: Check generated codec files are up to date + run: ./scripts/run_task.sh check-generate-codec + - name: Check generated mocks are up to date + run: ./scripts/run_task.sh check-generate-mocks + - run: ./scripts/run_task.sh build + - run: ./scripts/run_task.sh build-test + env: + TIMEOUT: ${{ env.TIMEOUT }} + - run: ./scripts/run_task.sh coverage + + avalanchego_e2e: + name: AvalancheGo E2E Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: check out ${{ github.event.inputs.avalanchegoRepo }} ${{ github.event.inputs.avalanchegoBranch }} + if: ${{ github.event_name == 'workflow_dispatch' }} + uses: actions/checkout@v4 + with: + repository: ${{ github.event.inputs.avalanchegoRepo }} + ref: ${{ github.event.inputs.avalanchegoBranch }} + path: avalanchego + token: ${{ secrets.AVALANCHE_PAT }} + - name: Run e2e tests + uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@b79eeab14be3b06041d8e3a33c87a29d22ec1154 + with: + run: ./scripts/run_task.sh test-e2e-ci + prometheus_url: ${{ secrets.PROMETHEUS_URL || '' }} + prometheus_push_url: ${{ secrets.PROMETHEUS_PUSH_URL || '' }} + prometheus_username: ${{ secrets.PROMETHEUS_ID || '' }} + prometheus_password: ${{ secrets.PROMETHEUS_PASSWORD || '' }} + loki_url: ${{ secrets.LOKI_URL || '' }} + loki_push_url: ${{ secrets.LOKI_PUSH_URL || '' }} + loki_username: ${{ secrets.LOKI_ID || '' }} + loki_password: ${{ secrets.LOKI_PASSWORD || '' }} + + e2e_warp: + name: e2e warp tests + runs-on: ubuntu-latest + steps: + - name: Git checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: check out ${{ github.event.inputs.avalanchegoRepo }} ${{ github.event.inputs.avalanchegoBranch }} + if: ${{ github.event_name == 'workflow_dispatch' }} + uses: actions/checkout@v4 + with: + repository: ${{ github.event.inputs.avalanchegoRepo }} + ref: ${{ github.event.inputs.avalanchegoBranch }} + path: avalanchego + - name: Run Warp E2E Tests + uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@b79eeab14be3b06041d8e3a33c87a29d22ec1154 + with: + run: ./scripts/run_task.sh test-e2e-warp-ci + artifact_prefix: warp + prometheus_url: ${{ secrets.PROMETHEUS_URL || '' }} + prometheus_push_url: ${{ secrets.PROMETHEUS_PUSH_URL || '' }} + prometheus_username: ${{ secrets.PROMETHEUS_ID || '' }} + prometheus_password: ${{ secrets.PROMETHEUS_PASSWORD || '' }} + loki_url: ${{ secrets.LOKI_URL || '' }} + loki_push_url: ${{ secrets.LOKI_PUSH_URL || '' }} + loki_username: ${{ secrets.LOKI_ID || '' }} + loki_password: ${{ secrets.LOKI_PASSWORD || '' }} From 93eb1e6160e580e8e889c0b1f719247f2768f945 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Wed, 8 Oct 2025 15:09:34 +0300 Subject: [PATCH 04/25] chore: update to latest avalanchego version --- graft/coreth/.github/workflows/ci.yml | 4 ++-- graft/coreth/go.sum | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/graft/coreth/.github/workflows/ci.yml b/graft/coreth/.github/workflows/ci.yml index 40b49d5bc9ef..895cb4884c4d 100644 --- a/graft/coreth/.github/workflows/ci.yml +++ b/graft/coreth/.github/workflows/ci.yml @@ -104,7 +104,7 @@ jobs: path: avalanchego token: ${{ secrets.AVALANCHE_PAT }} - name: Run e2e tests - uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@b79eeab14be3b06041d8e3a33c87a29d22ec1154 + uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@fff1df9564d3fa86899780d73e887d9ee5b9b54e with: run: ./scripts/run_task.sh test-e2e-ci prometheus_url: ${{ secrets.PROMETHEUS_URL || '' }} @@ -132,7 +132,7 @@ jobs: ref: ${{ github.event.inputs.avalanchegoBranch }} path: avalanchego - name: Run Warp E2E Tests - uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@b79eeab14be3b06041d8e3a33c87a29d22ec1154 + uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@fff1df9564d3fa86899780d73e887d9ee5b9b54e with: run: ./scripts/run_task.sh test-e2e-warp-ci artifact_prefix: warp diff --git a/graft/coreth/go.sum b/graft/coreth/go.sum index 8b519b59b5a3..11fcbc9ef62f 100644 --- a/graft/coreth/go.sum +++ b/graft/coreth/go.sum @@ -27,6 +27,7 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5 github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= <<<<<<< HEAD +<<<<<<< HEAD github.com/ava-labs/coreth v0.16.0 h1:0AcmiIR3118JrnoePO3ho2EyaySmEMvlbCmk3RcYRxk= github.com/ava-labs/coreth v0.16.0/go.mod h1:uGr1C7BP0+dWhvsIouhuH0yCyI8YDgS6sfEFIExs0iI= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15 h1:NAVjEu508HwdgbxH/xQxMQoBUgYUn9RQf0VeCrhtYMY= @@ -38,6 +39,10 @@ github.com/ava-labs/avalanchego v1.13.6-0.20251003124158-f1854079a644 h1:6evg50k github.com/ava-labs/avalanchego v1.13.6-0.20251003124158-f1854079a644/go.mod h1:4kotB9pnVuXpwZDVdcB48cSGzRLcanEZ1ZJj2gJo73o= github.com/ava-labs/avalanchego v1.13.6-0.20251006102538-b79eeab14be3 h1:9Kb7wGBKkhB/fxIdgclXmmw+PaS6ZeKAgAutvoRs0LA= github.com/ava-labs/avalanchego v1.13.6-0.20251006102538-b79eeab14be3/go.mod h1:yplWYV/FzAZeYAhy0yOj8wjJA1PCdTPxQf8Wzpwg6DY= +======= +github.com/ava-labs/avalanchego v1.13.6-0.20251008120019-fff1df9564d3 h1:PExdlCEpGaAg75iIlWYBYFtUeqiyBityzAjRiZ5nm4M= +github.com/ava-labs/avalanchego v1.13.6-0.20251008120019-fff1df9564d3/go.mod h1:EL0MGbL2liE9jp4QtCHR2thkNl8hCkD26DJ+7cmcaqs= +>>>>>>> eb25364b40 (chore: update to latest avalanchego version) github.com/ava-labs/firewood-go-ethhash/ffi v0.0.12 h1:aMcrLbpJ/dyu2kZDf/Di/4JIWsUcYPyTDKymiHpejt0= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.12/go.mod h1:cq89ua3iiZ5wPBALTEQS5eG8DIZcs7ov6OiL4YR1BVY= github.com/ava-labs/libevm v1.13.15-0.20251002164226-35926db4d661 h1:lt4yQE1HMvxWrdD5RFj+h9kWUsZK2rmNohvkeQsbG9M= From 52e191395bfd0f53e583511637d8edd2ed7b7a0b Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Fri, 21 Nov 2025 18:04:14 +0200 Subject: [PATCH 05/25] chore(go.mod) upgrade avalanchego to 3b08d6131a00bd55349321a58ae7e6cfcff8635e --- graft/coreth/go.sum | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/graft/coreth/go.sum b/graft/coreth/go.sum index 11fcbc9ef62f..6ca4982946d0 100644 --- a/graft/coreth/go.sum +++ b/graft/coreth/go.sum @@ -28,10 +28,17 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD github.com/ava-labs/coreth v0.16.0 h1:0AcmiIR3118JrnoePO3ho2EyaySmEMvlbCmk3RcYRxk= github.com/ava-labs/coreth v0.16.0/go.mod h1:uGr1C7BP0+dWhvsIouhuH0yCyI8YDgS6sfEFIExs0iI= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15 h1:NAVjEu508HwdgbxH/xQxMQoBUgYUn9RQf0VeCrhtYMY= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15/go.mod h1:hR/JSGXxST9B9olwu/NpLXHAykfAyNGfyKnYQqiiOeE= +======= +github.com/ava-labs/avalanchego v1.14.1-0.20251120202846-3b08d6131a00 h1:98u5W3kR/MIveMs4eZjH4rU3v/1Ux0imQW+oEAhyhDM= +github.com/ava-labs/avalanchego v1.14.1-0.20251120202846-3b08d6131a00/go.mod h1:Ntq3RBvDQzNjy14NU3RC2Jf1A9pzfM5RVQ30Gwx/6IM= +github.com/ava-labs/firewood-go-ethhash/ffi v0.0.14 h1:Be+LO61hwmo7XKNm57Yoqx7ld8SgBapjVBEPjUcgI8o= +github.com/ava-labs/firewood-go-ethhash/ffi v0.0.14/go.mod h1:hR/JSGXxST9B9olwu/NpLXHAykfAyNGfyKnYQqiiOeE= +>>>>>>> 78697167f9 (chore(go.mod) upgrade avalanchego to 3b08d6131a00bd55349321a58ae7e6cfcff8635e) github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2 h1:hQ15IJxY7WOKqeJqCXawsiXh0NZTzmoQOemkWHz7rr4= github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2/go.mod h1:DqSotSn4Dx/UJV+d3svfW8raR+cH7+Ohl9BpsQ5HlGU= ======= From 181e587a4bfd15e0c59ffd54d1901c3144dd20e1 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Fri, 21 Nov 2025 19:33:03 +0200 Subject: [PATCH 06/25] fix(statesync): handle ErrNotFound when reading sync root Handle database.ErrNotFound returned by ReadSyncRoot when there's no previous sync root. This is expected for fresh databases and should be treated as an empty hash (no previous sync) rather than an error. --- graft/coreth/sync/statesync/trie_queue.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/graft/coreth/sync/statesync/trie_queue.go b/graft/coreth/sync/statesync/trie_queue.go index 210cfd6a048f..7e8c9c70058b 100644 --- a/graft/coreth/sync/statesync/trie_queue.go +++ b/graft/coreth/sync/statesync/trie_queue.go @@ -4,6 +4,9 @@ package statesync import ( + "errors" + + "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/ethdb" @@ -28,7 +31,11 @@ func NewTrieQueue(db ethdb.Database) *trieQueue { func (t *trieQueue) clearIfRootDoesNotMatch(root common.Hash) error { persistedRoot, err := customrawdb.ReadSyncRoot(t.db) if err != nil { - return err + // If no sync root exists, treat it as empty hash (no previous sync). + if !errors.Is(err, database.ErrNotFound) { + return err + } + persistedRoot = common.Hash{} } if persistedRoot != (common.Hash{}) && persistedRoot != root { // if not resuming, clear all progress markers From fe381d04fc4acc40ec1f8a0a73ddf77b1af6d65e Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Fri, 21 Nov 2025 19:36:22 +0200 Subject: [PATCH 07/25] fix(vmtest): improve requireSyncPerformedHeight --- graft/coreth/plugin/evm/vmtest/test_syncervm.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/graft/coreth/plugin/evm/vmtest/test_syncervm.go b/graft/coreth/plugin/evm/vmtest/test_syncervm.go index d41e9e7b21cf..6956709fcb8a 100644 --- a/graft/coreth/plugin/evm/vmtest/test_syncervm.go +++ b/graft/coreth/plugin/evm/vmtest/test_syncervm.go @@ -497,7 +497,7 @@ func testSyncerVM(t *testing.T, testSyncVMSetup *testSyncVMSetup, test SyncTestP // TODO: this avoids circular dependencies but is not ideal. ethDBPrefix := []byte("ethdb") chaindb := database.New(prefixdb.NewNested(ethDBPrefix, testSyncVMSetup.syncerVM.DB)) - requireSyncPerformedHeights(t, chaindb, map[uint64]struct{}{}) + requireSyncPerformedHeight(t, chaindb, nil) return } require.NoError(err, "state sync failed") @@ -508,7 +508,8 @@ func testSyncerVM(t *testing.T, testSyncVMSetup *testSyncVMSetup, test SyncTestP require.Equal(serverVM.LastAcceptedExtendedBlock().Height(), syncerVM.LastAcceptedExtendedBlock().Height(), "block height mismatch between syncer and server") require.Equal(serverVM.LastAcceptedExtendedBlock().ID(), syncerVM.LastAcceptedExtendedBlock().ID(), "blockID mismatch between syncer and server") require.True(syncerVM.Ethereum().BlockChain().HasState(syncerVM.Ethereum().BlockChain().LastAcceptedBlock().Root()), "unavailable state for last accepted block") - requireSyncPerformedHeights(t, syncerVM.Ethereum().ChainDb(), map[uint64]struct{}{retrievedSummary.Height(): {}}) + expectedHeight := retrievedSummary.Height() + requireSyncPerformedHeight(t, syncerVM.Ethereum().ChainDb(), &expectedHeight) lastNumber := syncerVM.Ethereum().BlockChain().LastAcceptedBlock().NumberU64() // check the last block is indexed From 8ed20f7ecf8e32fd1072408e5bd3c75d9dc738fb Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Fri, 21 Nov 2025 19:41:10 +0200 Subject: [PATCH 08/25] fix(statesync): handle ErrNotFound when reading sync root --- graft/coreth/sync/statesync/trie_queue.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/graft/coreth/sync/statesync/trie_queue.go b/graft/coreth/sync/statesync/trie_queue.go index 7e8c9c70058b..5f999d126090 100644 --- a/graft/coreth/sync/statesync/trie_queue.go +++ b/graft/coreth/sync/statesync/trie_queue.go @@ -30,13 +30,14 @@ func NewTrieQueue(db ethdb.Database) *trieQueue { // the persisted root does not match the root we are syncing to. func (t *trieQueue) clearIfRootDoesNotMatch(root common.Hash) error { persistedRoot, err := customrawdb.ReadSyncRoot(t.db) - if err != nil { - // If no sync root exists, treat it as empty hash (no previous sync). - if !errors.Is(err, database.ErrNotFound) { - return err - } + // If no sync root exists, treat it as empty hash (no previous sync). + switch { + case errors.Is(err, database.ErrNotFound): persistedRoot = common.Hash{} + case err != nil: + return err } + if persistedRoot != (common.Hash{}) && persistedRoot != root { // if not resuming, clear all progress markers if err := customrawdb.ClearAllSyncStorageTries(t.db); err != nil { From 18a61ea286c2498ebdf9f50fc368d63dbc209b4b Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Fri, 21 Nov 2025 19:57:33 +0200 Subject: [PATCH 09/25] fix(core): handle ErrNotFound when reading acceptor tip Handle database.ErrNotFound from ReadAcceptorTip as expected case (empty hash) instead of error. This fixes VM initialization failures on fresh databases. --- graft/coreth/core/blockchain.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/graft/coreth/core/blockchain.go b/graft/coreth/core/blockchain.go index 44efd6db5b53..b1f6a70921c6 100644 --- a/graft/coreth/core/blockchain.go +++ b/graft/coreth/core/blockchain.go @@ -40,6 +40,7 @@ import ( "sync/atomic" "time" + "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/graft/coreth/consensus" "github.com/ava-labs/avalanchego/graft/coreth/core/extstate" "github.com/ava-labs/avalanchego/graft/coreth/core/state/snapshot" @@ -1835,7 +1836,11 @@ func (bc *BlockChain) initSnapshot(b *types.Header) { func (bc *BlockChain) reprocessState(current *types.Block, reexec uint64) error { origin := current.NumberU64() acceptorTip, err := customrawdb.ReadAcceptorTip(bc.db) - if err != nil { + // If no acceptor tip exists, treat it as empty hash (not initialized). + switch { + case errors.Is(err, database.ErrNotFound): + acceptorTip = common.Hash{} + case err != nil: return fmt.Errorf("%w: unable to get Acceptor tip", err) } log.Info("Loaded Acceptor tip", "hash", acceptorTip) From 591fc29d5336529cfcef4d088712e411d2b9c747 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Fri, 21 Nov 2025 20:19:14 +0200 Subject: [PATCH 10/25] fix(snapshot): handle ErrNotFound in wipe test Update TestWipe to accept database.ErrNotFound as valid result after wipe, since ReadSnapshotBlockHash returns ErrNotFound when the marker doesn't exist. --- graft/coreth/core/state/snapshot/wipe_test.go | 51 +++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/graft/coreth/core/state/snapshot/wipe_test.go b/graft/coreth/core/state/snapshot/wipe_test.go index 3d5b1dc5bb0b..fe1787840eee 100644 --- a/graft/coreth/core/state/snapshot/wipe_test.go +++ b/graft/coreth/core/state/snapshot/wipe_test.go @@ -28,9 +28,11 @@ package snapshot import ( + "errors" "math/rand" "testing" + "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" @@ -40,7 +42,7 @@ import ( // Tests that given a database with random data content, all parts of a snapshot // can be crrectly wiped without touching anything else. func TestWipe(t *testing.T) { - // Create a database with some random snapshot data + // Create a database with some random snapshot data. db := memorydb.New() for i := 0; i < 128; i++ { rawdb.WriteAccountSnapshot(db, randomHash(), randomHash().Bytes()) @@ -48,9 +50,9 @@ func TestWipe(t *testing.T) { customrawdb.WriteSnapshotBlockHash(db, randomHash()) rawdb.WriteSnapshotRoot(db, randomHash()) - // Add some random non-snapshot data too to make wiping harder + // Add some random non-snapshot data too to make wiping harder. for i := 0; i < 500; i++ { - // Generate keys with wrong length for a state snapshot item + // Generate keys with wrong length for a state snapshot item. keysuffix := make([]byte, 31) rand.Read(keysuffix) db.Put(append(rawdb.SnapshotAccountPrefix, keysuffix...), randomHash().Bytes()) @@ -68,25 +70,29 @@ func TestWipe(t *testing.T) { } return items } - // Sanity check that all the keys are present + // Verify snapshot data exists before wipe. if items := count(); items != 128 { - t.Fatalf("snapshot size mismatch: have %d, want %d", items, 128) + t.Fatalf("snapshot size mismatch before wipe: have %d, want %d", items, 128) } - hash, err := customrawdb.ReadSnapshotBlockHash(db) - if err != nil || hash == (common.Hash{}) { - t.Errorf("snapshot block hash marker mismatch: have %#x, want ", hash) + blockHash, err := customrawdb.ReadSnapshotBlockHash(db) + switch { + case err != nil: + t.Fatalf("failed to read snapshot block hash before wipe: %v", err) + case blockHash == (common.Hash{}): + t.Fatalf("snapshot block hash is empty before wipe") } - if hash := rawdb.ReadSnapshotRoot(db); hash == (common.Hash{}) { - t.Errorf("snapshot block root marker mismatch: have %#x, want ", hash) + if root := rawdb.ReadSnapshotRoot(db); root == (common.Hash{}) { + t.Fatalf("snapshot root is empty before wipe") } - // Wipe all snapshot entries from the database + + // Wipe all snapshot entries from the database. <-WipeSnapshot(db, true) - // Iterate over the database end ensure no snapshot information remains + // Verify snapshot data is removed. if items := count(); items != 0 { - t.Fatalf("snapshot size mismatch: have %d, want %d", items, 0) + t.Fatalf("snapshot size mismatch after wipe: have %d, want %d", items, 0) } - // Iterate over the database and ensure miscellaneous items are present + // Verify miscellaneous items are preserved. items := 0 it := db.NewIterator(nil, nil) defer it.Release() @@ -94,14 +100,19 @@ func TestWipe(t *testing.T) { items++ } if items != 1000 { - t.Fatalf("misc item count mismatch: have %d, want %d", items, 1000) + t.Fatalf("misc item count mismatch after wipe: have %d, want %d", items, 1000) } - hash, err := customrawdb.ReadSnapshotBlockHash(db) - if err == nil && hash != (common.Hash{}) { - t.Errorf("snapshot block hash marker remained after wipe: %#x", hash) + // Verify snapshot markers are removed. + blockHash, err = customrawdb.ReadSnapshotBlockHash(db) + switch { + case errors.Is(err, database.ErrNotFound): // Expected: marker was deleted. + case err != nil: + t.Errorf("unexpected error reading snapshot block hash after wipe: %v", err) + case blockHash != (common.Hash{}): + t.Errorf("snapshot block hash marker remained after wipe: %#x", blockHash) } - if hash := rawdb.ReadSnapshotRoot(db); hash != (common.Hash{}) { - t.Errorf("snapshot block root marker remained after wipe: %#x", hash) + if root := rawdb.ReadSnapshotRoot(db); root != (common.Hash{}) { + t.Errorf("snapshot root marker remained after wipe: %#x", root) } } From 0cfd4adc3ca955c7607561e30ff963aadba1e2d6 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Fri, 21 Nov 2025 20:23:08 +0200 Subject: [PATCH 11/25] fix(tracers): apply block override before creating block context - Move block number override fix before NewEVMBlockContext creation so GetHashFn can correctly resolve blockhash(n) when block number is overridden to n+1. This fixes TestTracingWithOverrides for Firewood scheme. - The bug was probably a pre-existing code issue where the header modification happened after creating the block context. Since GetHashFn creates a closure that captures the header reference, modifying the header afterward left the closure with stale values. This bug was exposed by the recent avalanchego update (3b08d6131a00bd55349321a58ae7e6cfcff8635e), which likely changed behavior that made the test fail specifically for Firewood scheme, while HashScheme continued to pass. --- graft/coreth/eth/tracers/api.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/graft/coreth/eth/tracers/api.go b/graft/coreth/eth/tracers/api.go index fbca7a2e4128..0796325e3252 100644 --- a/graft/coreth/eth/tracers/api.go +++ b/graft/coreth/eth/tracers/api.go @@ -961,21 +961,23 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc defer release() h := block.Header() + // Apply block number override fix before creating block context so GetHashFn + // can correctly resolve blockhash(n) when block number is overridden to n+1. + if config != nil && config.BlockOverrides != nil && config.BlockOverrides.Number.ToInt().Uint64() == h.Number.Uint64()+1 { + // Overriding the block number to n+1 is a common way for wallets to + // simulate transactions, however without the following fix, a contract + // can assert it is being simulated by checking if blockhash(n) == 0x0 and + // can behave differently during the simulation. (#32175 for more info) + // -- + // Modify the parent hash and number so that downstream, blockContext's + // GetHash function can correctly return n. + h.ParentHash = h.Hash() + h.Number.Add(h.Number, big.NewInt(1)) + } blockContext := core.NewEVMBlockContext(h, api.chainContext(ctx), nil) // Apply the customization rules if required. if config != nil { - if config.BlockOverrides != nil && config.BlockOverrides.Number.ToInt().Uint64() == h.Number.Uint64()+1 { - // Overriding the block number to n+1 is a common way for wallets to - // simulate transactions, however without the following fix, a contract - // can assert it is being simulated by checking if blockhash(n) == 0x0 and - // can behave differently during the simulation. (#32175 for more info) - // -- - // Modify the parent hash and number so that downstream, blockContext's - // GetHash function can correctly return n. - h.ParentHash = h.Hash() - h.Number.Add(h.Number, big.NewInt(1)) - } originalTime := block.Time() config.BlockOverrides.Apply(&blockContext) // Apply all relevant upgrades from [originalTime] to the block time set in the override. From 68b7e3230f0c8ff85ea0f7256b00f379b2c1d1cd Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Mon, 24 Nov 2025 12:16:04 +0200 Subject: [PATCH 12/25] refactor(snapshot): improve error handling and test validation - Extract sentinel errors in journal.go for better error checking and maintainability. - Refactor loadSnapshot to use switch statements for clearer control flow when validating snapshot block hash and root. - Improve TestWipe validation logic: - Use switch statements for consistent error handling patterns. - Add context to error messages ("before wipe" / "after wipe"). --- graft/coreth/core/state/snapshot/journal.go | 32 ++++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/graft/coreth/core/state/snapshot/journal.go b/graft/coreth/core/state/snapshot/journal.go index 56f6b44b6b31..799b4985bc16 100644 --- a/graft/coreth/core/state/snapshot/journal.go +++ b/graft/coreth/core/state/snapshot/journal.go @@ -42,6 +42,15 @@ import ( "github.com/ava-labs/libevm/triedb" ) +var ( + errSnapshotNotFound = errors.New("snapshot not found") + errSnapshotBlockHashEmpty = errors.New("missing or corrupted snapshot, no snapshot block hash") + errSnapshotBlockHashMismatch = errors.New("snapshot block hash mismatch") + errSnapshotRootEmpty = errors.New("missing or corrupted snapshot, no snapshot root") + errSnapshotRootMismatch = errors.New("snapshot root mismatch") + errSnapshotGeneratorMissing = errors.New("missing snapshot generator") +) + // journalGenerator is a disk layer entry containing the generator progress marker. type journalGenerator struct { // Indicator that whether the database was in progress of being wiped. @@ -59,24 +68,19 @@ type journalGenerator struct { // store. If loading the snapshot from disk is successful, this function also // returns a boolean indicating whether or not the snapshot is fully generated. func loadSnapshot(diskdb ethdb.KeyValueStore, triedb *triedb.Database, cache int, blockHash, root common.Hash, noBuild bool) (snapshot, bool, error) { - // Retrieve the block number and hash of the snapshot, failing if no snapshot - // is present in the database (or crashed mid-update). + // Retrieve the block hash of the snapshot, failing if no snapshot is present. baseBlockHash, err := customrawdb.ReadSnapshotBlockHash(diskdb) if err != nil { return nil, false, errors.New("missing or corrupted snapshot, no snapshot block hash") } - if baseBlockHash == (common.Hash{}) { - return nil, false, errors.New("missing or corrupted snapshot, no snapshot block hash") - } - if baseBlockHash != blockHash { - return nil, false, fmt.Errorf("block hash stored on disk (%#x) does not match last accepted (%#x)", baseBlockHash, blockHash) - } + + // Retrieve and validate the snapshot root. baseRoot := rawdb.ReadSnapshotRoot(diskdb) - if baseRoot == (common.Hash{}) { - return nil, false, errors.New("missing or corrupted snapshot, no snapshot root") - } - if baseRoot != root { - return nil, false, fmt.Errorf("root stored on disk (%#x) does not match last accepted (%#x)", baseRoot, root) + switch { + case baseRoot == (common.Hash{}): + return nil, false, errSnapshotRootEmpty + case baseRoot != root: + return nil, false, fmt.Errorf("%w: stored %#x, expected %#x", errSnapshotRootMismatch, baseRoot, root) } // Retrieve the disk layer generator. It must exist, no matter the @@ -84,7 +88,7 @@ func loadSnapshot(diskdb ethdb.KeyValueStore, triedb *triedb.Database, cache int // layer is invalid. generatorBlob := rawdb.ReadSnapshotGenerator(diskdb) if len(generatorBlob) == 0 { - return nil, false, errors.New("missing snapshot generator") + return nil, false, errSnapshotGeneratorMissing } var generator journalGenerator if err := rlp.DecodeBytes(generatorBlob, &generator); err != nil { From b8b7be528cee5b7bc8cce8a94920084b2d8e0602 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Mon, 24 Nov 2025 12:32:42 +0200 Subject: [PATCH 13/25] fix(customtypes): unalias math/rand package --- graft/coreth/plugin/evm/customtypes/hashing_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/graft/coreth/plugin/evm/customtypes/hashing_test.go b/graft/coreth/plugin/evm/customtypes/hashing_test.go index 71fd7a161881..0e6359f9122b 100644 --- a/graft/coreth/plugin/evm/customtypes/hashing_test.go +++ b/graft/coreth/plugin/evm/customtypes/hashing_test.go @@ -43,7 +43,7 @@ import ( "github.com/ava-labs/libevm/trie" "github.com/ava-labs/libevm/triedb" - mrand "math/rand" + "math/rand" ) func TestDeriveSha(t *testing.T) { @@ -117,7 +117,7 @@ func BenchmarkDeriveSha200(b *testing.B) { func TestFuzzDeriveSha(t *testing.T) { // increase this for longer runs -- it's set to quite low for travis - rndSeed := mrand.Int() + rndSeed := rand.Int() for i := 0; i < 10; i++ { seed := rndSeed + i exp := types.DeriveSha(newDummy(i), trie.NewEmpty(triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil))) @@ -186,7 +186,7 @@ type dummyDerivableList struct { func newDummy(seed int) *dummyDerivableList { d := &dummyDerivableList{} - src := mrand.NewSource(int64(seed)) + src := rand.NewSource(int64(seed)) // don't use lists longer than 4K items d.len = int(src.Int63() & 0x0FFF) d.seed = seed @@ -198,10 +198,10 @@ func (d *dummyDerivableList) Len() int { } func (d *dummyDerivableList) EncodeIndex(i int, w *bytes.Buffer) { - src := mrand.NewSource(int64(d.seed + i)) + src := rand.NewSource(int64(d.seed + i)) // max item size 256, at least 1 byte per item size := 1 + src.Int63()&0x00FF - io.CopyN(w, mrand.New(src), size) + io.CopyN(w, rand.New(src), size) } func printList(l types.DerivableList) { From 1700205985d04f05e827b4efe1303735cafea2f9 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Mon, 24 Nov 2025 16:38:29 +0200 Subject: [PATCH 14/25] refactor(vmtest): simplify requireSyncPerformedHeight signature --- graft/coreth/plugin/evm/vmtest/test_syncervm.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graft/coreth/plugin/evm/vmtest/test_syncervm.go b/graft/coreth/plugin/evm/vmtest/test_syncervm.go index 6956709fcb8a..7d73ebb33282 100644 --- a/graft/coreth/plugin/evm/vmtest/test_syncervm.go +++ b/graft/coreth/plugin/evm/vmtest/test_syncervm.go @@ -497,7 +497,7 @@ func testSyncerVM(t *testing.T, testSyncVMSetup *testSyncVMSetup, test SyncTestP // TODO: this avoids circular dependencies but is not ideal. ethDBPrefix := []byte("ethdb") chaindb := database.New(prefixdb.NewNested(ethDBPrefix, testSyncVMSetup.syncerVM.DB)) - requireSyncPerformedHeight(t, chaindb, nil) + requireSyncPerformedHeight(t, chaindb, 0) return } require.NoError(err, "state sync failed") @@ -509,7 +509,7 @@ func testSyncerVM(t *testing.T, testSyncVMSetup *testSyncVMSetup, test SyncTestP require.Equal(serverVM.LastAcceptedExtendedBlock().ID(), syncerVM.LastAcceptedExtendedBlock().ID(), "blockID mismatch between syncer and server") require.True(syncerVM.Ethereum().BlockChain().HasState(syncerVM.Ethereum().BlockChain().LastAcceptedBlock().Root()), "unavailable state for last accepted block") expectedHeight := retrievedSummary.Height() - requireSyncPerformedHeight(t, syncerVM.Ethereum().ChainDb(), &expectedHeight) + requireSyncPerformedHeight(t, syncerVM.Ethereum().ChainDb(), expectedHeight) lastNumber := syncerVM.Ethereum().BlockChain().LastAcceptedBlock().NumberU64() // check the last block is indexed From 7212c83bfb9a78eb353846dd447e7c9d577a2c8e Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Thu, 27 Nov 2025 17:46:51 +0200 Subject: [PATCH 15/25] chore(go.mod) upgrade avalanchego to ee44f6856445429c0a3358b6c51b3add376b8751 --- graft/coreth/.github/workflows/ci.yml | 5 ++--- graft/coreth/go.mod | 3 +-- graft/coreth/go.sum | 30 --------------------------- 3 files changed, 3 insertions(+), 35 deletions(-) diff --git a/graft/coreth/.github/workflows/ci.yml b/graft/coreth/.github/workflows/ci.yml index 895cb4884c4d..091125ebb2c1 100644 --- a/graft/coreth/.github/workflows/ci.yml +++ b/graft/coreth/.github/workflows/ci.yml @@ -104,7 +104,7 @@ jobs: path: avalanchego token: ${{ secrets.AVALANCHE_PAT }} - name: Run e2e tests - uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@fff1df9564d3fa86899780d73e887d9ee5b9b54e + uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@ee44f6856445429c0a3358b6c51b3add376b8751 with: run: ./scripts/run_task.sh test-e2e-ci prometheus_url: ${{ secrets.PROMETHEUS_URL || '' }} @@ -132,8 +132,7 @@ jobs: ref: ${{ github.event.inputs.avalanchegoBranch }} path: avalanchego - name: Run Warp E2E Tests - uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@fff1df9564d3fa86899780d73e887d9ee5b9b54e - with: + uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@ee44f6856445429c0a3358b6c51b3add376b8751 run: ./scripts/run_task.sh test-e2e-warp-ci artifact_prefix: warp prometheus_url: ${{ secrets.PROMETHEUS_URL || '' }} diff --git a/graft/coreth/go.mod b/graft/coreth/go.mod index d1c2b142ef58..c263c3ee33db 100644 --- a/graft/coreth/go.mod +++ b/graft/coreth/go.mod @@ -15,7 +15,7 @@ go 1.24.9 require ( github.com/VictoriaMetrics/fastcache v1.12.1 - github.com/ava-labs/avalanchego v1.14.1-0.20251120155522-df4a8e531761 + github.com/ava-labs/avalanchego v1.14.1-0.20251126155231-ee44f6856445 github.com/ava-labs/coreth v0.16.0 github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15 github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2 @@ -78,7 +78,6 @@ require ( github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/ethereum/c-kzg-4844 v1.0.0 // indirect - github.com/fatih/structtag v1.2.0 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect diff --git a/graft/coreth/go.sum b/graft/coreth/go.sum index 6ca4982946d0..a7e85a385d22 100644 --- a/graft/coreth/go.sum +++ b/graft/coreth/go.sum @@ -26,35 +26,12 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD github.com/ava-labs/coreth v0.16.0 h1:0AcmiIR3118JrnoePO3ho2EyaySmEMvlbCmk3RcYRxk= github.com/ava-labs/coreth v0.16.0/go.mod h1:uGr1C7BP0+dWhvsIouhuH0yCyI8YDgS6sfEFIExs0iI= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15 h1:NAVjEu508HwdgbxH/xQxMQoBUgYUn9RQf0VeCrhtYMY= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15/go.mod h1:hR/JSGXxST9B9olwu/NpLXHAykfAyNGfyKnYQqiiOeE= -======= -github.com/ava-labs/avalanchego v1.14.1-0.20251120202846-3b08d6131a00 h1:98u5W3kR/MIveMs4eZjH4rU3v/1Ux0imQW+oEAhyhDM= -github.com/ava-labs/avalanchego v1.14.1-0.20251120202846-3b08d6131a00/go.mod h1:Ntq3RBvDQzNjy14NU3RC2Jf1A9pzfM5RVQ30Gwx/6IM= -github.com/ava-labs/firewood-go-ethhash/ffi v0.0.14 h1:Be+LO61hwmo7XKNm57Yoqx7ld8SgBapjVBEPjUcgI8o= -github.com/ava-labs/firewood-go-ethhash/ffi v0.0.14/go.mod h1:hR/JSGXxST9B9olwu/NpLXHAykfAyNGfyKnYQqiiOeE= ->>>>>>> 78697167f9 (chore(go.mod) upgrade avalanchego to 3b08d6131a00bd55349321a58ae7e6cfcff8635e) github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2 h1:hQ15IJxY7WOKqeJqCXawsiXh0NZTzmoQOemkWHz7rr4= github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2/go.mod h1:DqSotSn4Dx/UJV+d3svfW8raR+cH7+Ohl9BpsQ5HlGU= -======= -github.com/ava-labs/avalanchego v1.13.6-0.20251003124158-f1854079a644 h1:6evg50kddMsGxWDXtBAcnGet9UjWx93hliJZnowSqVg= -github.com/ava-labs/avalanchego v1.13.6-0.20251003124158-f1854079a644/go.mod h1:4kotB9pnVuXpwZDVdcB48cSGzRLcanEZ1ZJj2gJo73o= -github.com/ava-labs/avalanchego v1.13.6-0.20251006102538-b79eeab14be3 h1:9Kb7wGBKkhB/fxIdgclXmmw+PaS6ZeKAgAutvoRs0LA= -github.com/ava-labs/avalanchego v1.13.6-0.20251006102538-b79eeab14be3/go.mod h1:yplWYV/FzAZeYAhy0yOj8wjJA1PCdTPxQf8Wzpwg6DY= -======= -github.com/ava-labs/avalanchego v1.13.6-0.20251008120019-fff1df9564d3 h1:PExdlCEpGaAg75iIlWYBYFtUeqiyBityzAjRiZ5nm4M= -github.com/ava-labs/avalanchego v1.13.6-0.20251008120019-fff1df9564d3/go.mod h1:EL0MGbL2liE9jp4QtCHR2thkNl8hCkD26DJ+7cmcaqs= ->>>>>>> eb25364b40 (chore: update to latest avalanchego version) -github.com/ava-labs/firewood-go-ethhash/ffi v0.0.12 h1:aMcrLbpJ/dyu2kZDf/Di/4JIWsUcYPyTDKymiHpejt0= -github.com/ava-labs/firewood-go-ethhash/ffi v0.0.12/go.mod h1:cq89ua3iiZ5wPBALTEQS5eG8DIZcs7ov6OiL4YR1BVY= -github.com/ava-labs/libevm v1.13.15-0.20251002164226-35926db4d661 h1:lt4yQE1HMvxWrdD5RFj+h9kWUsZK2rmNohvkeQsbG9M= -github.com/ava-labs/libevm v1.13.15-0.20251002164226-35926db4d661/go.mod h1:ivRC/KojP8sai7j8WnpXIReQpcRklL2bIzoysnjpARQ= ->>>>>>> dd36d2f075 (fix: rlpgen import issue and update to latest avalanchego version) github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= @@ -168,13 +145,6 @@ github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHE github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= -<<<<<<< HEAD -======= -github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= -github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= -github.com/fjl/gencodec v0.1.1 h1:DhQY29Q6JLXB/GgMqE86NbOEuvckiYcJCbXFu02toms= -github.com/fjl/gencodec v0.1.1/go.mod h1:chDHL3wKXuBgauP8x3XNZkl5EIAR5SoCTmmmDTZRzmw= ->>>>>>> dd36d2f075 (fix: rlpgen import issue and update to latest avalanchego version) github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= From dc77bea478cf7cc98bd2cc067a9ba3aa56247882 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Thu, 27 Nov 2025 17:48:21 +0200 Subject: [PATCH 16/25] ci(.github): remove unneeded ci.yml --- graft/coreth/.github/workflows/ci.yml | 145 -------------------------- 1 file changed, 145 deletions(-) delete mode 100644 graft/coreth/.github/workflows/ci.yml diff --git a/graft/coreth/.github/workflows/ci.yml b/graft/coreth/.github/workflows/ci.yml deleted file mode 100644 index 091125ebb2c1..000000000000 --- a/graft/coreth/.github/workflows/ci.yml +++ /dev/null @@ -1,145 +0,0 @@ -name: CI -on: - push: - branches: - - master - pull_request: - merge_group: - types: [checks_requested] - workflow_dispatch: - inputs: - avalanchegoRepo: - description: "avalanchego github repository" - required: true - default: "ava-labs/avalanchego" - avalanchegoBranch: - description: "avalanchego branch" - required: true - default: "master" - -jobs: - lint_test: - name: Lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: check out ${{ github.event.inputs.avalanchegoRepo }} ${{ github.event.inputs.avalanchegoBranch }} - if: ${{ github.event_name == 'workflow_dispatch' }} - uses: actions/checkout@v4 - with: - repository: ${{ github.event.inputs.avalanchegoRepo }} - ref: ${{ github.event.inputs.avalanchegoBranch }} - path: avalanchego - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache-dependency-path: | - go.sum - tools/go.sum - tools/legacy-golangci-lint.sum - - name: change avalanchego dep - if: ${{ github.event_name == 'workflow_dispatch' }} - run: | - go mod edit -replace github.com/ava-labs/avalanchego=./avalanchego - go mod tidy - go clean -modcache - - name: Run all lint checks - run: ./scripts/run_task.sh lint-all-ci - - name: Check go.mod and go.sum are up-to-date - run: ./scripts/run_task.sh check-go-mod-tidy - - name: Ensure consistent avalanchego version - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./scripts/run_task.sh check-avalanchego-version - - unit_test: - name: Golang Unit Tests (${{ matrix.os }}) - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-latest, ubuntu-22.04, ubuntu-latest] - steps: - - uses: actions/checkout@v4 - - name: check out ${{ github.event.inputs.avalanchegoRepo }} ${{ github.event.inputs.avalanchegoBranch }} - if: ${{ github.event_name == 'workflow_dispatch' }} - uses: actions/checkout@v4 - with: - repository: ${{ github.event.inputs.avalanchegoRepo }} - ref: ${{ github.event.inputs.avalanchegoBranch }} - path: avalanchego - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache-dependency-path: | - go.sum - tools/go.sum - - name: change avalanchego dep - if: ${{ github.event_name == 'workflow_dispatch' }} - run: | - go mod edit -replace github.com/ava-labs/avalanchego=./avalanchego - go mod tidy - - run: go mod download - - name: Check generated codec files are up to date - run: ./scripts/run_task.sh check-generate-codec - - name: Check generated mocks are up to date - run: ./scripts/run_task.sh check-generate-mocks - - run: ./scripts/run_task.sh build - - run: ./scripts/run_task.sh build-test - env: - TIMEOUT: ${{ env.TIMEOUT }} - - run: ./scripts/run_task.sh coverage - - avalanchego_e2e: - name: AvalancheGo E2E Tests - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: check out ${{ github.event.inputs.avalanchegoRepo }} ${{ github.event.inputs.avalanchegoBranch }} - if: ${{ github.event_name == 'workflow_dispatch' }} - uses: actions/checkout@v4 - with: - repository: ${{ github.event.inputs.avalanchegoRepo }} - ref: ${{ github.event.inputs.avalanchegoBranch }} - path: avalanchego - token: ${{ secrets.AVALANCHE_PAT }} - - name: Run e2e tests - uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@ee44f6856445429c0a3358b6c51b3add376b8751 - with: - run: ./scripts/run_task.sh test-e2e-ci - prometheus_url: ${{ secrets.PROMETHEUS_URL || '' }} - prometheus_push_url: ${{ secrets.PROMETHEUS_PUSH_URL || '' }} - prometheus_username: ${{ secrets.PROMETHEUS_ID || '' }} - prometheus_password: ${{ secrets.PROMETHEUS_PASSWORD || '' }} - loki_url: ${{ secrets.LOKI_URL || '' }} - loki_push_url: ${{ secrets.LOKI_PUSH_URL || '' }} - loki_username: ${{ secrets.LOKI_ID || '' }} - loki_password: ${{ secrets.LOKI_PASSWORD || '' }} - - e2e_warp: - name: e2e warp tests - runs-on: ubuntu-latest - steps: - - name: Git checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: check out ${{ github.event.inputs.avalanchegoRepo }} ${{ github.event.inputs.avalanchegoBranch }} - if: ${{ github.event_name == 'workflow_dispatch' }} - uses: actions/checkout@v4 - with: - repository: ${{ github.event.inputs.avalanchegoRepo }} - ref: ${{ github.event.inputs.avalanchegoBranch }} - path: avalanchego - - name: Run Warp E2E Tests - uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@ee44f6856445429c0a3358b6c51b3add376b8751 - run: ./scripts/run_task.sh test-e2e-warp-ci - artifact_prefix: warp - prometheus_url: ${{ secrets.PROMETHEUS_URL || '' }} - prometheus_push_url: ${{ secrets.PROMETHEUS_PUSH_URL || '' }} - prometheus_username: ${{ secrets.PROMETHEUS_ID || '' }} - prometheus_password: ${{ secrets.PROMETHEUS_PASSWORD || '' }} - loki_url: ${{ secrets.LOKI_URL || '' }} - loki_push_url: ${{ secrets.LOKI_PUSH_URL || '' }} - loki_username: ${{ secrets.LOKI_ID || '' }} - loki_password: ${{ secrets.LOKI_PASSWORD || '' }} From 484d76f7b8019e0e5995e0c9b09c2e284ebd0116 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Thu, 27 Nov 2025 18:09:57 +0200 Subject: [PATCH 17/25] fix: necessary fixes --- graft/coreth/core/state/snapshot/generate.go | 2 +- graft/coreth/core/state/snapshot/journal.go | 9 +- graft/coreth/eth/tracers/api.go | 24 +- .../evm/customrawdb/accessors_state_sync.go | 223 ------------------ .../plugin/evm/customrawdb/schema_ext.go | 56 ----- .../plugin/evm/customtypes/block_test.go | 3 - graft/coreth/plugin/evm/vm_test.go | 1 - .../coreth/plugin/evm/vmtest/test_syncervm.go | 17 +- graft/coreth/sync/statesync/sync_test.go | 2 +- 9 files changed, 24 insertions(+), 313 deletions(-) delete mode 100644 graft/coreth/plugin/evm/customrawdb/accessors_state_sync.go delete mode 100644 graft/coreth/plugin/evm/customrawdb/schema_ext.go diff --git a/graft/coreth/core/state/snapshot/generate.go b/graft/coreth/core/state/snapshot/generate.go index 2c9693f4acbe..dc1020ad41a9 100644 --- a/graft/coreth/core/state/snapshot/generate.go +++ b/graft/coreth/core/state/snapshot/generate.go @@ -32,8 +32,8 @@ import ( "fmt" "time" - "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/utils" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/types" diff --git a/graft/coreth/core/state/snapshot/journal.go b/graft/coreth/core/state/snapshot/journal.go index 799b4985bc16..15df471e6657 100644 --- a/graft/coreth/core/state/snapshot/journal.go +++ b/graft/coreth/core/state/snapshot/journal.go @@ -43,12 +43,9 @@ import ( ) var ( - errSnapshotNotFound = errors.New("snapshot not found") - errSnapshotBlockHashEmpty = errors.New("missing or corrupted snapshot, no snapshot block hash") - errSnapshotBlockHashMismatch = errors.New("snapshot block hash mismatch") - errSnapshotRootEmpty = errors.New("missing or corrupted snapshot, no snapshot root") - errSnapshotRootMismatch = errors.New("snapshot root mismatch") - errSnapshotGeneratorMissing = errors.New("missing snapshot generator") + errSnapshotRootEmpty = errors.New("missing or corrupted snapshot, no snapshot root") + errSnapshotRootMismatch = errors.New("snapshot root mismatch") + errSnapshotGeneratorMissing = errors.New("missing snapshot generator") ) // journalGenerator is a disk layer entry containing the generator progress marker. diff --git a/graft/coreth/eth/tracers/api.go b/graft/coreth/eth/tracers/api.go index 0796325e3252..fbca7a2e4128 100644 --- a/graft/coreth/eth/tracers/api.go +++ b/graft/coreth/eth/tracers/api.go @@ -961,23 +961,21 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc defer release() h := block.Header() - // Apply block number override fix before creating block context so GetHashFn - // can correctly resolve blockhash(n) when block number is overridden to n+1. - if config != nil && config.BlockOverrides != nil && config.BlockOverrides.Number.ToInt().Uint64() == h.Number.Uint64()+1 { - // Overriding the block number to n+1 is a common way for wallets to - // simulate transactions, however without the following fix, a contract - // can assert it is being simulated by checking if blockhash(n) == 0x0 and - // can behave differently during the simulation. (#32175 for more info) - // -- - // Modify the parent hash and number so that downstream, blockContext's - // GetHash function can correctly return n. - h.ParentHash = h.Hash() - h.Number.Add(h.Number, big.NewInt(1)) - } blockContext := core.NewEVMBlockContext(h, api.chainContext(ctx), nil) // Apply the customization rules if required. if config != nil { + if config.BlockOverrides != nil && config.BlockOverrides.Number.ToInt().Uint64() == h.Number.Uint64()+1 { + // Overriding the block number to n+1 is a common way for wallets to + // simulate transactions, however without the following fix, a contract + // can assert it is being simulated by checking if blockhash(n) == 0x0 and + // can behave differently during the simulation. (#32175 for more info) + // -- + // Modify the parent hash and number so that downstream, blockContext's + // GetHash function can correctly return n. + h.ParentHash = h.Hash() + h.Number.Add(h.Number, big.NewInt(1)) + } originalTime := block.Time() config.BlockOverrides.Apply(&blockContext) // Apply all relevant upgrades from [originalTime] to the block time set in the override. diff --git a/graft/coreth/plugin/evm/customrawdb/accessors_state_sync.go b/graft/coreth/plugin/evm/customrawdb/accessors_state_sync.go deleted file mode 100644 index 67f41771c33c..000000000000 --- a/graft/coreth/plugin/evm/customrawdb/accessors_state_sync.go +++ /dev/null @@ -1,223 +0,0 @@ -// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package customrawdb - -import ( - "encoding/binary" - - "github.com/ava-labs/libevm/common" - "github.com/ava-labs/libevm/core/rawdb" - "github.com/ava-labs/libevm/ethdb" - "github.com/ava-labs/libevm/log" - - "github.com/ava-labs/avalanchego/utils/wrappers" -) - -// ReadSyncRoot reads the root corresponding to the main trie of an in-progress -// sync and returns common.Hash{} if no in-progress sync was found. -func ReadSyncRoot(db ethdb.KeyValueReader) (common.Hash, error) { - has, err := db.Has(syncRootKey) - if err != nil || !has { - return common.Hash{}, err - } - root, err := db.Get(syncRootKey) - if err != nil { - return common.Hash{}, err - } - return common.BytesToHash(root), nil -} - -// WriteSyncRoot writes root as the root of the main trie of the in-progress sync. -func WriteSyncRoot(db ethdb.KeyValueWriter, root common.Hash) error { - return db.Put(syncRootKey, root[:]) -} - -// AddCodeToFetch adds a marker that we need to fetch the code for `hash`. -func AddCodeToFetch(db ethdb.KeyValueWriter, hash common.Hash) { - if err := db.Put(codeToFetchKey(hash), nil); err != nil { - log.Crit("Failed to put code to fetch", "codeHash", hash, "err", err) - } -} - -// DeleteCodeToFetch removes the marker that the code corresponding to `hash` needs to be fetched. -func DeleteCodeToFetch(db ethdb.KeyValueWriter, hash common.Hash) { - if err := db.Delete(codeToFetchKey(hash)); err != nil { - log.Crit("Failed to delete code to fetch", "codeHash", hash, "err", err) - } -} - -// NewCodeToFetchIterator returns a KeyLength iterator over all code -// hashes that are pending syncing. It is the caller's responsibility to -// unpack the key and call Release on the returned iterator. -func NewCodeToFetchIterator(db ethdb.Iteratee) ethdb.Iterator { - return rawdb.NewKeyLengthIterator( - db.NewIterator(CodeToFetchPrefix, nil), - codeToFetchKeyLength, - ) -} - -func codeToFetchKey(hash common.Hash) []byte { - codeToFetchKey := make([]byte, codeToFetchKeyLength) - copy(codeToFetchKey, CodeToFetchPrefix) - copy(codeToFetchKey[len(CodeToFetchPrefix):], hash[:]) - return codeToFetchKey -} - -// NewSyncSegmentsIterator returns a KeyLength iterator over all trie segments -// added for root. It is the caller's responsibility to unpack the key and call -// Release on the returned iterator. -func NewSyncSegmentsIterator(db ethdb.Iteratee, root common.Hash) ethdb.Iterator { - segmentsPrefix := make([]byte, len(syncSegmentsPrefix)+common.HashLength) - copy(segmentsPrefix, syncSegmentsPrefix) - copy(segmentsPrefix[len(syncSegmentsPrefix):], root[:]) - - return rawdb.NewKeyLengthIterator( - db.NewIterator(segmentsPrefix, nil), - syncSegmentsKeyLength, - ) -} - -// WriteSyncSegment adds a trie segment for root at the given start position. -func WriteSyncSegment(db ethdb.KeyValueWriter, root common.Hash, start common.Hash) error { - return db.Put(packSyncSegmentKey(root, start), []byte{0x01}) -} - -// ClearSyncSegments removes segment markers for root from db -func ClearSyncSegments(db ethdb.KeyValueStore, root common.Hash) error { - segmentsPrefix := make([]byte, len(syncSegmentsPrefix)+common.HashLength) - copy(segmentsPrefix, syncSegmentsPrefix) - copy(segmentsPrefix[len(syncSegmentsPrefix):], root[:]) - return clearPrefix(db, segmentsPrefix, syncSegmentsKeyLength) -} - -// ClearAllSyncSegments removes all segment markers from db -func ClearAllSyncSegments(db ethdb.KeyValueStore) error { - return clearPrefix(db, syncSegmentsPrefix, syncSegmentsKeyLength) -} - -// UnpackSyncSegmentKey returns the root and start position for a trie segment -// key returned from NewSyncSegmentsIterator. -func UnpackSyncSegmentKey(keyBytes []byte) (common.Hash, []byte) { - keyBytes = keyBytes[len(syncSegmentsPrefix):] // skip prefix - root := common.BytesToHash(keyBytes[:common.HashLength]) - start := keyBytes[common.HashLength:] - return root, start -} - -// packSyncSegmentKey packs root and account into a key for storage in db. -func packSyncSegmentKey(root common.Hash, start common.Hash) []byte { - bytes := make([]byte, syncSegmentsKeyLength) - copy(bytes, syncSegmentsPrefix) - copy(bytes[len(syncSegmentsPrefix):], root[:]) - copy(bytes[len(syncSegmentsPrefix)+common.HashLength:], start.Bytes()) - return bytes -} - -// NewSyncStorageTriesIterator returns a KeyLength iterator over all storage tries -// added for syncing (beginning at seek). It is the caller's responsibility to unpack -// the key and call Release on the returned iterator. -func NewSyncStorageTriesIterator(db ethdb.Iteratee, seek []byte) ethdb.Iterator { - return rawdb.NewKeyLengthIterator(db.NewIterator(syncStorageTriesPrefix, seek), syncStorageTriesKeyLength) -} - -// WriteSyncStorageTrie adds a storage trie for account (with the given root) to be synced. -func WriteSyncStorageTrie(db ethdb.KeyValueWriter, root common.Hash, account common.Hash) error { - return db.Put(packSyncStorageTrieKey(root, account), []byte{0x01}) -} - -// ClearSyncStorageTrie removes all storage trie accounts (with the given root) from db. -// Intended for use when the trie with root has completed syncing. -func ClearSyncStorageTrie(db ethdb.KeyValueStore, root common.Hash) error { - accountsPrefix := make([]byte, len(syncStorageTriesPrefix)+common.HashLength) - copy(accountsPrefix, syncStorageTriesPrefix) - copy(accountsPrefix[len(syncStorageTriesPrefix):], root[:]) - return clearPrefix(db, accountsPrefix, syncStorageTriesKeyLength) -} - -// ClearAllSyncStorageTries removes all storage tries added for syncing from db -func ClearAllSyncStorageTries(db ethdb.KeyValueStore) error { - return clearPrefix(db, syncStorageTriesPrefix, syncStorageTriesKeyLength) -} - -// UnpackSyncStorageTrieKey returns the root and account for a storage trie -// key returned from NewSyncStorageTriesIterator. -func UnpackSyncStorageTrieKey(keyBytes []byte) (common.Hash, common.Hash) { - keyBytes = keyBytes[len(syncStorageTriesPrefix):] // skip prefix - root := common.BytesToHash(keyBytes[:common.HashLength]) - account := common.BytesToHash(keyBytes[common.HashLength:]) - return root, account -} - -// packSyncStorageTrieKey packs root and account into a key for storage in db. -func packSyncStorageTrieKey(root common.Hash, account common.Hash) []byte { - bytes := make([]byte, 0, syncStorageTriesKeyLength) - bytes = append(bytes, syncStorageTriesPrefix...) - bytes = append(bytes, root[:]...) - bytes = append(bytes, account[:]...) - return bytes -} - -// WriteSyncPerformed logs an entry in `db` indicating the VM state synced to `blockNumber`. -func WriteSyncPerformed(db ethdb.KeyValueWriter, blockNumber uint64) error { - syncPerformedPrefixLen := len(syncPerformedPrefix) - bytes := make([]byte, syncPerformedPrefixLen+wrappers.LongLen) - copy(bytes[:syncPerformedPrefixLen], syncPerformedPrefix) - binary.BigEndian.PutUint64(bytes[syncPerformedPrefixLen:], blockNumber) - return db.Put(bytes, []byte{0x01}) -} - -// NewSyncPerformedIterator returns an iterator over all block numbers the VM -// has state synced to. -func NewSyncPerformedIterator(db ethdb.Iteratee) ethdb.Iterator { - return rawdb.NewKeyLengthIterator(db.NewIterator(syncPerformedPrefix, nil), syncPerformedKeyLength) -} - -// UnpackSyncPerformedKey returns the block number from keys the iterator returned -// from NewSyncPerformedIterator. -func UnpackSyncPerformedKey(key []byte) uint64 { - return binary.BigEndian.Uint64(key[len(syncPerformedPrefix):]) -} - -// GetLatestSyncPerformed returns the latest block number state synced performed to. -func GetLatestSyncPerformed(db ethdb.Iteratee) uint64 { - it := NewSyncPerformedIterator(db) - defer it.Release() - - var latestSyncPerformed uint64 - for it.Next() { - syncPerformed := UnpackSyncPerformedKey(it.Key()) - if syncPerformed > latestSyncPerformed { - latestSyncPerformed = syncPerformed - } - } - return latestSyncPerformed -} - -// clearPrefix removes all keys in db that begin with prefix and match an -// expected key length. `keyLen` must include the length of the prefix. -func clearPrefix(db ethdb.KeyValueStore, prefix []byte, keyLen int) error { - it := db.NewIterator(prefix, nil) - defer it.Release() - - batch := db.NewBatch() - for it.Next() { - key := common.CopyBytes(it.Key()) - if len(key) != keyLen { - continue - } - if err := batch.Delete(key); err != nil { - return err - } - if batch.ValueSize() > ethdb.IdealBatchSize { - if err := batch.Write(); err != nil { - return err - } - batch.Reset() - } - } - if err := it.Error(); err != nil { - return err - } - return batch.Write() -} diff --git a/graft/coreth/plugin/evm/customrawdb/schema_ext.go b/graft/coreth/plugin/evm/customrawdb/schema_ext.go deleted file mode 100644 index ed3f66f6200c..000000000000 --- a/graft/coreth/plugin/evm/customrawdb/schema_ext.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package customrawdb - -import ( - "github.com/ava-labs/libevm/common" - - "github.com/ava-labs/avalanchego/utils/wrappers" -) - -var ( - // snapshotBlockHashKey tracks the block hash of the last snapshot. - snapshotBlockHashKey = []byte("SnapshotBlockHash") - // offlinePruningKey tracks runs of offline pruning - offlinePruningKey = []byte("OfflinePruning") - // populateMissingTriesKey tracks runs of trie backfills - populateMissingTriesKey = []byte("PopulateMissingTries") - // pruningDisabledKey tracks whether the node has ever run in archival mode - // to ensure that a user does not accidentally corrupt an archival node. - pruningDisabledKey = []byte("PruningDisabled") - // acceptorTipKey tracks the tip of the last accepted block that has been fully processed. - acceptorTipKey = []byte("AcceptorTipKey") -) - -// State sync progress keys and prefixes -var ( - // syncRootKey indicates the root of the main account trie currently being synced - syncRootKey = []byte("sync_root") - // syncStorageTriesPrefix is the prefix for storage tries that need to be fetched. - // syncStorageTriesPrefix + trie root + account hash: indicates a storage trie must be fetched for the account - syncStorageTriesPrefix = []byte("sync_storage") - // syncSegmentsPrefix is the prefix for segments. - // syncSegmentsPrefix + trie root + 32-byte start key: indicates the trie at root has a segment starting at the specified key - syncSegmentsPrefix = []byte("sync_segments") - // CodeToFetchPrefix is the prefix for code hashes that need to be fetched. - // CodeToFetchPrefix + code hash -> empty value tracks the outstanding code hashes we need to fetch. - CodeToFetchPrefix = []byte("CP") -) - -// State sync progress key lengths -var ( - syncStorageTriesKeyLength = len(syncStorageTriesPrefix) + 2*common.HashLength - syncSegmentsKeyLength = len(syncSegmentsPrefix) + 2*common.HashLength - codeToFetchKeyLength = len(CodeToFetchPrefix) + common.HashLength -) - -// State sync metadata -var ( - syncPerformedPrefix = []byte("sync_performed") - // syncPerformedKeyLength is the length of the key for the sync performed metadata key, - // and is equal to [syncPerformedPrefix] + block number as uint64. - syncPerformedKeyLength = len(syncPerformedPrefix) + wrappers.LongLen -) - -var FirewoodScheme = "firewood" diff --git a/graft/coreth/plugin/evm/customtypes/block_test.go b/graft/coreth/plugin/evm/customtypes/block_test.go index 7ddbdf2ba689..499d2f372830 100644 --- a/graft/coreth/plugin/evm/customtypes/block_test.go +++ b/graft/coreth/plugin/evm/customtypes/block_test.go @@ -42,9 +42,6 @@ import ( "github.com/ava-labs/libevm/crypto" "github.com/ava-labs/libevm/rlp" - "github.com/ava-labs/coreth/internal/blocktest" - "github.com/ava-labs/coreth/params" - // This test file has to be in package types_test to avoid a circular // dependency when importing `params`. We dot-import the package to mimic // regular same-package behaviour. diff --git a/graft/coreth/plugin/evm/vm_test.go b/graft/coreth/plugin/evm/vm_test.go index c9fd54fd03d5..ca4c6bcf655e 100644 --- a/graft/coreth/plugin/evm/vm_test.go +++ b/graft/coreth/plugin/evm/vm_test.go @@ -36,7 +36,6 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/params" "github.com/ava-labs/avalanchego/graft/coreth/params/paramstest" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customheader" - "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customrawdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customtypes" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/extension" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/message" diff --git a/graft/coreth/plugin/evm/vmtest/test_syncervm.go b/graft/coreth/plugin/evm/vmtest/test_syncervm.go index 7d73ebb33282..d5cc6743a50c 100644 --- a/graft/coreth/plugin/evm/vmtest/test_syncervm.go +++ b/graft/coreth/plugin/evm/vmtest/test_syncervm.go @@ -13,15 +13,6 @@ import ( "time" "github.com/ava-labs/avalanchego/database/prefixdb" - "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" - "github.com/ava-labs/libevm/common" - "github.com/ava-labs/libevm/core/rawdb" - "github.com/ava-labs/libevm/core/types" - "github.com/ava-labs/libevm/ethdb" - "github.com/ava-labs/libevm/log" - "github.com/ava-labs/libevm/rlp" - "github.com/ava-labs/libevm/trie" - "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/graft/coreth/consensus/dummy" "github.com/ava-labs/avalanchego/graft/coreth/constants" "github.com/ava-labs/avalanchego/graft/coreth/core" @@ -43,6 +34,14 @@ import ( "github.com/ava-labs/avalanchego/vms/evm/database" "github.com/ava-labs/avalanchego/vms/evm/predicate" "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" + "github.com/ava-labs/libevm/common" + "github.com/ava-labs/libevm/core/rawdb" + "github.com/ava-labs/libevm/core/types" + "github.com/ava-labs/libevm/ethdb" + "github.com/ava-labs/libevm/log" + "github.com/ava-labs/libevm/rlp" + "github.com/ava-labs/libevm/trie" + "github.com/stretchr/testify/require" avalancheatomic "github.com/ava-labs/avalanchego/chains/atomic" avalanchedatabase "github.com/ava-labs/avalanchego/database" diff --git a/graft/coreth/sync/statesync/sync_test.go b/graft/coreth/sync/statesync/sync_test.go index 69beb505e9a4..69120f12be84 100644 --- a/graft/coreth/sync/statesync/sync_test.go +++ b/graft/coreth/sync/statesync/sync_test.go @@ -526,7 +526,7 @@ func testSyncerSyncsToNewRoot(t *testing.T, deleteBetweenSyncs func(*testing.T, // Also verifies any code referenced by the EVM state is present in [clientTrieDB] and the hash is correct. func assertDBConsistency(t testing.TB, root common.Hash, clientDB ethdb.Database, serverTrieDB, clientTrieDB *triedb.Database) { numSnapshotAccounts := 0 - accountIt := customrawdb.IterateAccountSnapshots(clientDB) + accountIt := customrawdb.NewAccountSnapshotsIterator(clientDB) defer accountIt.Release() for accountIt.Next() { if !bytes.HasPrefix(accountIt.Key(), rawdb.SnapshotAccountPrefix) || len(accountIt.Key()) != len(rawdb.SnapshotAccountPrefix)+common.HashLength { From 8d6e9eaf032ba5383872256596a4e2f2299fc5d2 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Thu, 27 Nov 2025 22:43:02 +0200 Subject: [PATCH 18/25] fix: apply go mod tidy --- graft/coreth/go.mod | 3 ++- graft/coreth/go.sum | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/graft/coreth/go.mod b/graft/coreth/go.mod index c263c3ee33db..ea9a4599f48c 100644 --- a/graft/coreth/go.mod +++ b/graft/coreth/go.mod @@ -16,7 +16,6 @@ go 1.24.9 require ( github.com/VictoriaMetrics/fastcache v1.12.1 github.com/ava-labs/avalanchego v1.14.1-0.20251126155231-ee44f6856445 - github.com/ava-labs/coreth v0.16.0 github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15 github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc @@ -54,6 +53,7 @@ require ( require ( connectrpc.com/connect v1.18.1 // indirect connectrpc.com/grpcreflect v1.3.0 // indirect + github.com/BurntSushi/toml v1.5.0 // indirect github.com/DataDog/zstd v1.5.2 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/StephenButtolph/canoto v0.17.3 // indirect @@ -61,6 +61,7 @@ require ( github.com/bits-and-blooms/bitset v1.20.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.5 // indirect github.com/btcsuite/btcd/btcutil v1.1.3 // indirect + github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cenkalti/backoff/v5 v5.0.2 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect diff --git a/graft/coreth/go.sum b/graft/coreth/go.sum index a7e85a385d22..230d9e5312f9 100644 --- a/graft/coreth/go.sum +++ b/graft/coreth/go.sum @@ -26,8 +26,6 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/ava-labs/coreth v0.16.0 h1:0AcmiIR3118JrnoePO3ho2EyaySmEMvlbCmk3RcYRxk= -github.com/ava-labs/coreth v0.16.0/go.mod h1:uGr1C7BP0+dWhvsIouhuH0yCyI8YDgS6sfEFIExs0iI= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15 h1:NAVjEu508HwdgbxH/xQxMQoBUgYUn9RQf0VeCrhtYMY= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15/go.mod h1:hR/JSGXxST9B9olwu/NpLXHAykfAyNGfyKnYQqiiOeE= github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2 h1:hQ15IJxY7WOKqeJqCXawsiXh0NZTzmoQOemkWHz7rr4= @@ -39,7 +37,6 @@ github.com/bits-and-blooms/bitset v1.20.0 h1:2F+rfL86jE2d/bmw7OhqUg2Sj/1rURkBn3M github.com/bits-and-blooms/bitset v1.20.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M= -github.com/btcsuite/btcd v0.23.0 h1:V2/ZgjfDFIygAX3ZapeigkVBoVUtOJKSwrhZdlpSvaA= github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA= github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= From ffd26b649d82f825491508f334d2d4e0768f1e2c Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Fri, 28 Nov 2025 15:52:57 +0200 Subject: [PATCH 19/25] fix: style improvements --- go.sum | 9 ++++----- graft/coreth/plugin/evm/vmtest/test_syncervm.go | 17 +++++++++-------- graft/coreth/plugin/evm/vmtest/test_vm.go | 7 ++++--- graft/coreth/sync/statesync/code_queue.go | 11 ++++++++--- graft/coreth/sync/statesync/code_queue_test.go | 7 ++++--- graft/coreth/sync/statesync/code_syncer.go | 10 +++++++--- graft/coreth/sync/statesync/code_syncer_test.go | 8 ++++---- graft/coreth/sync/statesync/sync_test.go | 2 +- graft/coreth/sync/statesync/trie_queue.go | 5 +++-- graft/coreth/sync/statesync/trie_segments.go | 4 ++-- 10 files changed, 46 insertions(+), 34 deletions(-) diff --git a/go.sum b/go.sum index af2c7ae50090..c0068716ca84 100644 --- a/go.sum +++ b/go.sum @@ -43,8 +43,8 @@ connectrpc.com/grpcreflect v1.3.0/go.mod h1:nfloOtCS8VUQOQ1+GTdFzVg2CJo4ZGaat8JI dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= -github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= +github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno= github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo= @@ -71,8 +71,6 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmV github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/ava-labs/coreth v0.16.0 h1:0AcmiIR3118JrnoePO3ho2EyaySmEMvlbCmk3RcYRxk= -github.com/ava-labs/coreth v0.16.0/go.mod h1:uGr1C7BP0+dWhvsIouhuH0yCyI8YDgS6sfEFIExs0iI= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15 h1:NAVjEu508HwdgbxH/xQxMQoBUgYUn9RQf0VeCrhtYMY= github.com/ava-labs/firewood-go-ethhash/ffi v0.0.15/go.mod h1:hR/JSGXxST9B9olwu/NpLXHAykfAyNGfyKnYQqiiOeE= github.com/ava-labs/libevm v1.13.15-0.20251016142715-1bccf4f2ddb2 h1:hQ15IJxY7WOKqeJqCXawsiXh0NZTzmoQOemkWHz7rr4= @@ -101,8 +99,9 @@ github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUB github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipusjXSohQ= github.com/btcsuite/btcd/btcutil v1.1.3/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= -github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= +github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ= +github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= diff --git a/graft/coreth/plugin/evm/vmtest/test_syncervm.go b/graft/coreth/plugin/evm/vmtest/test_syncervm.go index d5cc6743a50c..2a4d745cb714 100644 --- a/graft/coreth/plugin/evm/vmtest/test_syncervm.go +++ b/graft/coreth/plugin/evm/vmtest/test_syncervm.go @@ -12,6 +12,15 @@ import ( "testing" "time" + "github.com/ava-labs/libevm/common" + "github.com/ava-labs/libevm/core/rawdb" + "github.com/ava-labs/libevm/core/types" + "github.com/ava-labs/libevm/ethdb" + "github.com/ava-labs/libevm/log" + "github.com/ava-labs/libevm/rlp" + "github.com/ava-labs/libevm/trie" + "github.com/stretchr/testify/require" + "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/graft/coreth/consensus/dummy" "github.com/ava-labs/avalanchego/graft/coreth/constants" @@ -34,14 +43,6 @@ import ( "github.com/ava-labs/avalanchego/vms/evm/database" "github.com/ava-labs/avalanchego/vms/evm/predicate" "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" - "github.com/ava-labs/libevm/common" - "github.com/ava-labs/libevm/core/rawdb" - "github.com/ava-labs/libevm/core/types" - "github.com/ava-labs/libevm/ethdb" - "github.com/ava-labs/libevm/log" - "github.com/ava-labs/libevm/rlp" - "github.com/ava-labs/libevm/trie" - "github.com/stretchr/testify/require" avalancheatomic "github.com/ava-labs/avalanchego/chains/atomic" avalanchedatabase "github.com/ava-labs/avalanchego/database" diff --git a/graft/coreth/plugin/evm/vmtest/test_vm.go b/graft/coreth/plugin/evm/vmtest/test_vm.go index 81e1ce1f0b3e..0958fff38da0 100644 --- a/graft/coreth/plugin/evm/vmtest/test_vm.go +++ b/graft/coreth/plugin/evm/vmtest/test_vm.go @@ -9,6 +9,10 @@ import ( "fmt" "testing" + "github.com/ava-labs/libevm/core/rawdb" + "github.com/ava-labs/libevm/core/types" + "github.com/stretchr/testify/require" + "github.com/ava-labs/avalanchego/api/metrics" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/extension" @@ -17,9 +21,6 @@ import ( "github.com/ava-labs/avalanchego/snow/engine/enginetest" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" - "github.com/ava-labs/libevm/core/rawdb" - "github.com/ava-labs/libevm/core/types" - "github.com/stretchr/testify/require" avalancheatomic "github.com/ava-labs/avalanchego/chains/atomic" commoneng "github.com/ava-labs/avalanchego/snow/engine/common" diff --git a/graft/coreth/sync/statesync/code_queue.go b/graft/coreth/sync/statesync/code_queue.go index 74123630ad85..d1d0e4327d4a 100644 --- a/graft/coreth/sync/statesync/code_queue.go +++ b/graft/coreth/sync/statesync/code_queue.go @@ -9,11 +9,12 @@ import ( "fmt" "sync" - "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/ethdb" "github.com/ava-labs/libevm/libevm/options" + + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" ) const defaultQueueCapacity = 5000 @@ -135,7 +136,9 @@ func (q *CodeQueue) AddCode(ctx context.Context, codeHashes []common.Hash) error // key rather than growing DB usage. The consumer deletes the marker after // fulfilling the request (or when it detects code is already present). for _, codeHash := range codeHashes { - customrawdb.WriteCodeToFetch(batch, codeHash) + if err := customrawdb.WriteCodeToFetch(batch, codeHash); err != nil { + return fmt.Errorf("failed to write code to fetch marker: %w", err) + } } if err := batch.Write(); err != nil { @@ -201,7 +204,9 @@ func recoverUnfetchedCodeHashes(db ethdb.Database) ([]common.Hash, error) { continue } - customrawdb.DeleteCodeToFetch(batch, codeHash) + if err := customrawdb.DeleteCodeToFetch(batch, codeHash); err != nil { + return nil, fmt.Errorf("failed to delete code to fetch marker: %w", err) + } if batch.ValueSize() < ethdb.IdealBatchSize { continue } diff --git a/graft/coreth/sync/statesync/code_queue_test.go b/graft/coreth/sync/statesync/code_queue_test.go index 147b7c96033e..d40a40b56682 100644 --- a/graft/coreth/sync/statesync/code_queue_test.go +++ b/graft/coreth/sync/statesync/code_queue_test.go @@ -9,14 +9,15 @@ import ( "testing" "time" - "github.com/ava-labs/avalanchego/utils/set" - "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/crypto" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" "go.uber.org/goleak" + + "github.com/ava-labs/avalanchego/utils/set" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" ) func TestCodeQueue(t *testing.T) { @@ -85,7 +86,7 @@ func TestCodeQueue(t *testing.T) { rawdb.WriteCode(db, hash, code) } for hash := range tt.alreadyToFetch { - customrawdb.WriteCodeToFetch(db, hash) + require.NoError(t, customrawdb.WriteCodeToFetch(db, hash)) } quit := make(chan struct{}) diff --git a/graft/coreth/sync/statesync/code_syncer.go b/graft/coreth/sync/statesync/code_syncer.go index adb79f1edb4d..022b8622c3ea 100644 --- a/graft/coreth/sync/statesync/code_syncer.go +++ b/graft/coreth/sync/statesync/code_syncer.go @@ -8,7 +8,6 @@ import ( "fmt" "sync" - "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/ethdb" @@ -16,6 +15,7 @@ import ( "golang.org/x/sync/errgroup" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/message" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" syncpkg "github.com/ava-labs/avalanchego/graft/coreth/sync" statesyncclient "github.com/ava-labs/avalanchego/graft/coreth/sync/client" @@ -145,7 +145,9 @@ func (c *CodeSyncer) work(ctx context.Context) error { if rawdb.HasCode(c.db, codeHash) { // Best-effort cleanup of stale marker. batch := c.db.NewBatch() - customrawdb.DeleteCodeToFetch(batch, codeHash) + if err := customrawdb.DeleteCodeToFetch(batch, codeHash); err != nil { + return fmt.Errorf("failed to delete stale code marker: %w", err) + } if err := batch.Write(); err != nil { return fmt.Errorf("failed to write batch for stale code marker: %w", err) @@ -182,7 +184,9 @@ func (c *CodeSyncer) fulfillCodeRequest(ctx context.Context, codeHashes []common batch := c.db.NewBatch() for i, codeHash := range codeHashes { - customrawdb.DeleteCodeToFetch(batch, codeHash) + if err := customrawdb.DeleteCodeToFetch(batch, codeHash); err != nil { + return fmt.Errorf("failed to delete code to fetch marker: %w", err) + } rawdb.WriteCode(batch, codeHash, codeByteSlices[i]) } diff --git a/graft/coreth/sync/statesync/code_syncer_test.go b/graft/coreth/sync/statesync/code_syncer_test.go index c0828f7b84d9..bf77e46db9a9 100644 --- a/graft/coreth/sync/statesync/code_syncer_test.go +++ b/graft/coreth/sync/statesync/code_syncer_test.go @@ -8,8 +8,6 @@ import ( "errors" "testing" - "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/crypto" @@ -19,6 +17,8 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/message" "github.com/ava-labs/avalanchego/graft/coreth/sync/handlers" + "github.com/ava-labs/avalanchego/utils" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" statesyncclient "github.com/ava-labs/avalanchego/graft/coreth/sync/client" handlerstats "github.com/ava-labs/avalanchego/graft/coreth/sync/handlers/stats" @@ -144,7 +144,7 @@ func TestCodeSyncerAddsInProgressCodeHashes(t *testing.T) { codeBytes := utils.RandomBytes(100) codeHash := crypto.Keccak256Hash(codeBytes) clientDB := rawdb.NewMemoryDatabase() - customrawdb.WriteCodeToFetch(clientDB, codeHash) + require.NoError(t, customrawdb.WriteCodeToFetch(clientDB, codeHash)) testCodeSyncer(t, codeSyncerTest{ clientDB: clientDB, codeRequestHashes: nil, @@ -166,7 +166,7 @@ func TestCodeSyncerAddsMoreInProgressThanQueueSize(t *testing.T) { db := rawdb.NewMemoryDatabase() for _, codeHash := range codeHashes { - customrawdb.WriteCodeToFetch(db, codeHash) + require.NoError(t, customrawdb.WriteCodeToFetch(db, codeHash)) } testCodeSyncer(t, codeSyncerTest{ diff --git a/graft/coreth/sync/statesync/sync_test.go b/graft/coreth/sync/statesync/sync_test.go index 69120f12be84..c3a9749ed91b 100644 --- a/graft/coreth/sync/statesync/sync_test.go +++ b/graft/coreth/sync/statesync/sync_test.go @@ -11,7 +11,6 @@ import ( "sync/atomic" "testing" - "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/types" @@ -27,6 +26,7 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/message" "github.com/ava-labs/avalanchego/graft/coreth/sync/handlers" "github.com/ava-labs/avalanchego/graft/coreth/sync/statesync/statesynctest" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" statesyncclient "github.com/ava-labs/avalanchego/graft/coreth/sync/client" handlerstats "github.com/ava-labs/avalanchego/graft/coreth/sync/handlers/stats" diff --git a/graft/coreth/sync/statesync/trie_queue.go b/graft/coreth/sync/statesync/trie_queue.go index 5f999d126090..749328d03d53 100644 --- a/graft/coreth/sync/statesync/trie_queue.go +++ b/graft/coreth/sync/statesync/trie_queue.go @@ -6,10 +6,11 @@ package statesync import ( "errors" - "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/ethdb" + + "github.com/ava-labs/avalanchego/database" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" ) // trieQueue persists storage trie roots with their associated diff --git a/graft/coreth/sync/statesync/trie_segments.go b/graft/coreth/sync/statesync/trie_segments.go index b314ec4981f3..61f2068a72bf 100644 --- a/graft/coreth/sync/statesync/trie_segments.go +++ b/graft/coreth/sync/statesync/trie_segments.go @@ -10,8 +10,6 @@ import ( "fmt" "sync" - "github.com/ava-labs/avalanchego/utils/wrappers" - "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/ethdb" @@ -20,6 +18,8 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/message" "github.com/ava-labs/avalanchego/graft/coreth/utils" + "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" syncclient "github.com/ava-labs/avalanchego/graft/coreth/sync/client" ) From 5cdf50c5b563c69cc77ef958b4e649572cd4b78a Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Fri, 28 Nov 2025 16:44:08 +0200 Subject: [PATCH 20/25] fix: add sentinel error --- graft/coreth/core/state/snapshot/journal.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/graft/coreth/core/state/snapshot/journal.go b/graft/coreth/core/state/snapshot/journal.go index 15df471e6657..07baa7f8884f 100644 --- a/graft/coreth/core/state/snapshot/journal.go +++ b/graft/coreth/core/state/snapshot/journal.go @@ -44,6 +44,7 @@ import ( var ( errSnapshotRootEmpty = errors.New("missing or corrupted snapshot, no snapshot root") + errSnapshotBlockHashEmpty = errors.New("missing or corrupted snapshot, no snapshot block hash") errSnapshotRootMismatch = errors.New("snapshot root mismatch") errSnapshotGeneratorMissing = errors.New("missing snapshot generator") ) @@ -68,7 +69,7 @@ func loadSnapshot(diskdb ethdb.KeyValueStore, triedb *triedb.Database, cache int // Retrieve the block hash of the snapshot, failing if no snapshot is present. baseBlockHash, err := customrawdb.ReadSnapshotBlockHash(diskdb) if err != nil { - return nil, false, errors.New("missing or corrupted snapshot, no snapshot block hash") + return nil, false, errSnapshotBlockHashEmpty } // Retrieve and validate the snapshot root. From 98a81dcede3ad67c2d527f677894a63ea409460a Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Fri, 28 Nov 2025 16:50:34 +0200 Subject: [PATCH 21/25] fix: reduce diff --- graft/coreth/core/state/snapshot/wipe_test.go | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/graft/coreth/core/state/snapshot/wipe_test.go b/graft/coreth/core/state/snapshot/wipe_test.go index fe1787840eee..5cf603cccbb7 100644 --- a/graft/coreth/core/state/snapshot/wipe_test.go +++ b/graft/coreth/core/state/snapshot/wipe_test.go @@ -42,7 +42,7 @@ import ( // Tests that given a database with random data content, all parts of a snapshot // can be crrectly wiped without touching anything else. func TestWipe(t *testing.T) { - // Create a database with some random snapshot data. + // Create a database with some random snapshot data db := memorydb.New() for i := 0; i < 128; i++ { rawdb.WriteAccountSnapshot(db, randomHash(), randomHash().Bytes()) @@ -50,9 +50,9 @@ func TestWipe(t *testing.T) { customrawdb.WriteSnapshotBlockHash(db, randomHash()) rawdb.WriteSnapshotRoot(db, randomHash()) - // Add some random non-snapshot data too to make wiping harder. + // Add some random non-snapshot data too to make wiping harder for i := 0; i < 500; i++ { - // Generate keys with wrong length for a state snapshot item. + // Generate keys with wrong length for a state snapshot item keysuffix := make([]byte, 31) rand.Read(keysuffix) db.Put(append(rawdb.SnapshotAccountPrefix, keysuffix...), randomHash().Bytes()) @@ -70,9 +70,9 @@ func TestWipe(t *testing.T) { } return items } - // Verify snapshot data exists before wipe. + // Sanity check that all the keys are present if items := count(); items != 128 { - t.Fatalf("snapshot size mismatch before wipe: have %d, want %d", items, 128) + t.Fatalf("snapshot size mismatch: have %d, want %d", items, 128) } blockHash, err := customrawdb.ReadSnapshotBlockHash(db) switch { @@ -81,18 +81,17 @@ func TestWipe(t *testing.T) { case blockHash == (common.Hash{}): t.Fatalf("snapshot block hash is empty before wipe") } - if root := rawdb.ReadSnapshotRoot(db); root == (common.Hash{}) { - t.Fatalf("snapshot root is empty before wipe") + if hash := rawdb.ReadSnapshotRoot(db); hash == (common.Hash{}) { + t.Errorf("snapshot block root marker mismatch: have %#x, want ", hash) } - - // Wipe all snapshot entries from the database. + // Wipe all snapshot entries from the database <-WipeSnapshot(db, true) - // Verify snapshot data is removed. + // Iterate over the database end ensure no snapshot information remains if items := count(); items != 0 { - t.Fatalf("snapshot size mismatch after wipe: have %d, want %d", items, 0) + t.Fatalf("snapshot size mismatch: have %d, want %d", items, 0) } - // Verify miscellaneous items are preserved. + // Iterate over the database and ensure miscellaneous items are present items := 0 it := db.NewIterator(nil, nil) defer it.Release() @@ -100,7 +99,7 @@ func TestWipe(t *testing.T) { items++ } if items != 1000 { - t.Fatalf("misc item count mismatch after wipe: have %d, want %d", items, 1000) + t.Fatalf("misc item count mismatch: have %d, want %d", items, 1000) } // Verify snapshot markers are removed. @@ -112,7 +111,7 @@ func TestWipe(t *testing.T) { case blockHash != (common.Hash{}): t.Errorf("snapshot block hash marker remained after wipe: %#x", blockHash) } - if root := rawdb.ReadSnapshotRoot(db); root != (common.Hash{}) { - t.Errorf("snapshot root marker remained after wipe: %#x", root) + if hash := rawdb.ReadSnapshotRoot(db); hash != (common.Hash{}) { + t.Errorf("snapshot block root marker remained after wipe: %#x", hash) } } From 17f9aa33023183fe3b0153c0c1671995dbff718a Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Mon, 1 Dec 2025 13:44:11 +0200 Subject: [PATCH 22/25] fix: reduce diff in journal.go --- graft/coreth/core/state/snapshot/journal.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/graft/coreth/core/state/snapshot/journal.go b/graft/coreth/core/state/snapshot/journal.go index 07baa7f8884f..c60544ae9479 100644 --- a/graft/coreth/core/state/snapshot/journal.go +++ b/graft/coreth/core/state/snapshot/journal.go @@ -42,13 +42,6 @@ import ( "github.com/ava-labs/libevm/triedb" ) -var ( - errSnapshotRootEmpty = errors.New("missing or corrupted snapshot, no snapshot root") - errSnapshotBlockHashEmpty = errors.New("missing or corrupted snapshot, no snapshot block hash") - errSnapshotRootMismatch = errors.New("snapshot root mismatch") - errSnapshotGeneratorMissing = errors.New("missing snapshot generator") -) - // journalGenerator is a disk layer entry containing the generator progress marker. type journalGenerator struct { // Indicator that whether the database was in progress of being wiped. @@ -69,16 +62,14 @@ func loadSnapshot(diskdb ethdb.KeyValueStore, triedb *triedb.Database, cache int // Retrieve the block hash of the snapshot, failing if no snapshot is present. baseBlockHash, err := customrawdb.ReadSnapshotBlockHash(diskdb) if err != nil { - return nil, false, errSnapshotBlockHashEmpty + return nil, false, errors.New("missing or corrupted snapshot, no snapshot block hash") } - - // Retrieve and validate the snapshot root. baseRoot := rawdb.ReadSnapshotRoot(diskdb) switch { case baseRoot == (common.Hash{}): - return nil, false, errSnapshotRootEmpty + return nil, false, errors.New("missing or corrupted snapshot, no snapshot root") case baseRoot != root: - return nil, false, fmt.Errorf("%w: stored %#x, expected %#x", errSnapshotRootMismatch, baseRoot, root) + return nil, false, fmt.Errorf("root stored on disk (%#x) does not match last accepted (%#x)", baseRoot, root) } // Retrieve the disk layer generator. It must exist, no matter the @@ -86,7 +77,7 @@ func loadSnapshot(diskdb ethdb.KeyValueStore, triedb *triedb.Database, cache int // layer is invalid. generatorBlob := rawdb.ReadSnapshotGenerator(diskdb) if len(generatorBlob) == 0 { - return nil, false, errSnapshotGeneratorMissing + return nil, false, errors.New("missing snapshot generator") } var generator journalGenerator if err := rlp.DecodeBytes(generatorBlob, &generator); err != nil { From ef4dc7c9595733d64e983f40f0ac044f9dff2bc0 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Mon, 1 Dec 2025 14:10:43 +0200 Subject: [PATCH 23/25] fix: reduce diff in hashing_test.go --- graft/coreth/plugin/evm/customtypes/hashing_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/graft/coreth/plugin/evm/customtypes/hashing_test.go b/graft/coreth/plugin/evm/customtypes/hashing_test.go index 0e6359f9122b..ca1958e043ee 100644 --- a/graft/coreth/plugin/evm/customtypes/hashing_test.go +++ b/graft/coreth/plugin/evm/customtypes/hashing_test.go @@ -32,6 +32,7 @@ import ( "fmt" "io" "math/big" + mrand "math/rand" "testing" "github.com/ava-labs/libevm/common" @@ -42,8 +43,6 @@ import ( "github.com/ava-labs/libevm/rlp" "github.com/ava-labs/libevm/trie" "github.com/ava-labs/libevm/triedb" - - "math/rand" ) func TestDeriveSha(t *testing.T) { @@ -117,7 +116,7 @@ func BenchmarkDeriveSha200(b *testing.B) { func TestFuzzDeriveSha(t *testing.T) { // increase this for longer runs -- it's set to quite low for travis - rndSeed := rand.Int() + rndSeed := mrand.Int() for i := 0; i < 10; i++ { seed := rndSeed + i exp := types.DeriveSha(newDummy(i), trie.NewEmpty(triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil))) @@ -186,7 +185,7 @@ type dummyDerivableList struct { func newDummy(seed int) *dummyDerivableList { d := &dummyDerivableList{} - src := rand.NewSource(int64(seed)) + src := mrand.NewSource(int64(seed)) // don't use lists longer than 4K items d.len = int(src.Int63() & 0x0FFF) d.seed = seed @@ -198,10 +197,10 @@ func (d *dummyDerivableList) Len() int { } func (d *dummyDerivableList) EncodeIndex(i int, w *bytes.Buffer) { - src := rand.NewSource(int64(d.seed + i)) + src := mrand.NewSource(int64(d.seed + i)) // max item size 256, at least 1 byte per item size := 1 + src.Int63()&0x00FF - io.CopyN(w, rand.New(src), size) + io.CopyN(w, mrand.New(src), size) } func printList(l types.DerivableList) { From a34b609632d39ab5be544ab389155804094ce7ed Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Mon, 1 Dec 2025 16:59:37 +0200 Subject: [PATCH 24/25] fix: reintroduce falsely removed check in journal.go --- graft/coreth/core/state/snapshot/journal.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/graft/coreth/core/state/snapshot/journal.go b/graft/coreth/core/state/snapshot/journal.go index c60544ae9479..e4926e45b072 100644 --- a/graft/coreth/core/state/snapshot/journal.go +++ b/graft/coreth/core/state/snapshot/journal.go @@ -64,6 +64,9 @@ func loadSnapshot(diskdb ethdb.KeyValueStore, triedb *triedb.Database, cache int if err != nil { return nil, false, errors.New("missing or corrupted snapshot, no snapshot block hash") } + if baseBlockHash != blockHash { + return nil, false, fmt.Errorf("block hash stored on disk (%#x) does not match last accepted (%#x)", baseBlockHash, blockHash) + } baseRoot := rawdb.ReadSnapshotRoot(diskdb) switch { case baseRoot == (common.Hash{}): From 7207b185cf7250f472cd3e4f44b6fe8f3b6f2db8 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Mon, 1 Dec 2025 17:23:21 +0200 Subject: [PATCH 25/25] fix: wrap customrawdb.ReadSnapshotBlockHash error result --- graft/coreth/core/state/snapshot/journal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graft/coreth/core/state/snapshot/journal.go b/graft/coreth/core/state/snapshot/journal.go index e4926e45b072..1de91725de90 100644 --- a/graft/coreth/core/state/snapshot/journal.go +++ b/graft/coreth/core/state/snapshot/journal.go @@ -62,7 +62,7 @@ func loadSnapshot(diskdb ethdb.KeyValueStore, triedb *triedb.Database, cache int // Retrieve the block hash of the snapshot, failing if no snapshot is present. baseBlockHash, err := customrawdb.ReadSnapshotBlockHash(diskdb) if err != nil { - return nil, false, errors.New("missing or corrupted snapshot, no snapshot block hash") + return nil, false, fmt.Errorf("missing or corrupted snapshot, no snapshot block hash: %v", err) } if baseBlockHash != blockHash { return nil, false, fmt.Errorf("block hash stored on disk (%#x) does not match last accepted (%#x)", baseBlockHash, blockHash)