Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.8
require (
github.com/VictoriaMetrics/fastcache v1.12.1
github.com/antithesishq/antithesis-sdk-go v0.3.8
github.com/ava-labs/avalanchego v1.11.13
github.com/ava-labs/avalanchego v1.12.1-0.20241205143951-c4914c8b09d5
github.com/cespare/cp v0.1.0
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233
github.com/davecgh/go-spew v1.1.1
Expand Down Expand Up @@ -41,6 +41,7 @@ require (
github.com/urfave/cli/v2 v2.25.7
go.uber.org/goleak v1.3.0
go.uber.org/mock v0.4.0
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.26.0
golang.org/x/exp v0.0.0-20231127185646-65229373498e
golang.org/x/sync v0.8.0
Expand Down Expand Up @@ -153,7 +154,6 @@ require (
go.opentelemetry.io/otel/trace v1.22.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/term v0.23.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl
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/avalanchego v1.11.13 h1:1lcDZ9ILZgeiv7IwL4TuFTyglgZMr9QBOnpLHX+Qy5k=
github.com/ava-labs/avalanchego v1.11.13/go.mod h1:yhD5dpZyStIVbxQ550EDi5w5SL7DQ/xGE6TIxosb7U0=
github.com/ava-labs/avalanchego v1.12.0 h1:NBx0vSOY1dCT0PeJzojIhNhx0NMQNem4GgTEN+v8Sx4=
github.com/ava-labs/avalanchego v1.12.0/go.mod h1:yhD5dpZyStIVbxQ550EDi5w5SL7DQ/xGE6TIxosb7U0=
github.com/ava-labs/avalanchego v1.12.1-0.20241205143951-c4914c8b09d5 h1:VEOLrZ3VJue1PLw5NrnPYveRdRmZ1nhBA78uht2PMyY=
github.com/ava-labs/avalanchego v1.12.1-0.20241205143951-c4914c8b09d5/go.mod h1:yhD5dpZyStIVbxQ550EDi5w5SL7DQ/xGE6TIxosb7U0=
github.com/ava-labs/coreth v0.13.9-rc.1 h1:qIICpC/OZGYUP37QnLgIqqwGmxnLwLpZaUlqJNI85vU=
github.com/ava-labs/coreth v0.13.9-rc.1/go.mod h1:7aMsRIo/3GBE44qWZMjnfqdqfcfZ5yShTTm2LObLaYo=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (b *Block) Accept(context.Context) error {

// Although returning an error from Accept is considered fatal, it is good
// practice to cleanup the batch we were modifying in the case of an error.
defer vm.db.Abort()
defer vm.verdb.Abort()

log.Debug(fmt.Sprintf("Accepting block %s (%s) at height %d", b.ID().Hex(), b.ID(), b.Height()))

Expand All @@ -74,7 +74,7 @@ func (b *Block) Accept(context.Context) error {
return fmt.Errorf("failed to put %s as the last accepted block: %w", b.ID(), err)
}

return b.vm.db.Commit()
return b.vm.verdb.Commit()
}

// handlePrecompileAccept calls Accept on any logs generated with an active precompile address that implements
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/syncervm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ func testSyncerVM(t *testing.T, vmSetup *syncVMSetup, test syncTest) {
err = syncerVM.StateSyncClient.Error()
if test.expectedErr != nil {
require.ErrorIs(err, test.expectedErr)
// Note we re-open the database here to avoid a closed error when the test is for a shutdown VM.
chaindb := database.WrapDatabase(prefixdb.NewNested(ethDBPrefix, syncerVM.db))
// Note we re-open the database here to avoid a closed error verdb the test is for a shutdown VM.
chaindb := database.WrapDatabase(prefixdb.NewNested(ethDBPrefix, syncerVM.verdb))
assertSyncPerformedHeights(t, chaindb, map[uint64]struct{}{})
return
}
Expand Down
14 changes: 11 additions & 3 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,11 @@ type VM struct {
blockChain *core.BlockChain
miner *miner.Miner

// [db] is the VM's current database managed by ChainState
db *versiondb.Database
// [verdb] is the VM's current versioned database
verdb *versiondb.Database

// [db] is the VM's current database
db database.Database

// metadataDB is used to store one off keys.
metadataDB database.Database
Expand Down Expand Up @@ -630,7 +633,7 @@ func (vm *VM) initializeStateSyncClient(lastAcceptedHeight uint64) error {
chaindb: vm.chaindb,
metadataDB: vm.metadataDB,
acceptedBlockDB: vm.acceptedBlockDB,
db: vm.db,
db: vm.verdb,
toEngine: vm.toEngine,
})

Expand Down Expand Up @@ -880,6 +883,11 @@ func (vm *VM) Shutdown(context.Context) error {
}
vm.eth.Stop()
log.Info("Ethereum backend stop completed")
if err := vm.db.Close(); err != nil {
log.Error("failed to close database: %w", err)
} else {
log.Info("Database closed")
}
vm.shutdownWg.Wait()
log.Info("Subnet-EVM Shutdown completed")
return nil
Expand Down
7 changes: 4 additions & 3 deletions plugin/evm/vm_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ func (vm *VM) initializeDBs(avaDB avalanchedatabase.Database) error {
// Use NewNested rather than New so that the structure of the database
// remains the same regardless of the provided baseDB type.
vm.chaindb = rawdb.NewDatabase(database.WrapDatabase(prefixdb.NewNested(ethDBPrefix, db)))
vm.db = versiondb.New(db)
vm.acceptedBlockDB = prefixdb.New(acceptedPrefix, vm.db)
vm.metadataDB = prefixdb.New(metadataPrefix, vm.db)
vm.verdb = versiondb.New(db)
vm.acceptedBlockDB = prefixdb.New(acceptedPrefix, vm.verdb)
vm.metadataDB = prefixdb.New(metadataPrefix, vm.verdb)
vm.db = db
// Note warpDB and validatorsDB are not part of versiondb because it is not necessary
// that they are committed to the database atomically with
// the last accepted block.
Expand Down
5 changes: 1 addition & 4 deletions scripts/versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
# shellcheck disable=SC2034

# Don't export them as they're used in the context of other calls
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'v1.11.13'}
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'v1.12.0'}
GINKGO_VERSION=${GINKGO_VERSION:-'v2.2.0'}

# This won't be used, but it's here to make code syncs easier
LATEST_CORETH_VERSION='v0.13.7'
31 changes: 20 additions & 11 deletions tests/antithesis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"crypto/ecdsa"
"crypto/rand"
"fmt"
"log"
"math/big"
"path/filepath"
"time"
Expand All @@ -18,6 +17,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests/antithesis"
Expand All @@ -31,13 +31,15 @@ import (
"github.com/ava-labs/subnet-evm/tests/utils"

ago_tests "github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/utils/logging"
timerpkg "github.com/ava-labs/avalanchego/utils/timer"
)

const NumKeys = 5

func main() {
tc := ago_tests.NewTestContext()
logger := ago_tests.NewDefaultLogger("")
tc := ago_tests.NewTestContext(logger)
defer tc.Cleanup()
require := require.New(tc)

Expand All @@ -60,7 +62,9 @@ func main() {
ctx := ago_tests.DefaultNotifyContext(c.Duration, tc.DeferCleanup)

require.Len(c.ChainIDs, 1)
log.Printf("CHAIN IDS: %v", c.ChainIDs)
logger.Info("Starting testing",
zap.Strings("chainIDs", c.ChainIDs),
)
chainID, err := ids.FromString(c.ChainIDs[0])
require.NoError(err, "failed to parse chainID")

Expand All @@ -69,6 +73,7 @@ func main() {
genesisKey := tmpnet.HardhatKey.ToECDSA()
genesisWorkload := &workload{
id: 0,
log: ago_tests.NewDefaultLogger(fmt.Sprintf("worker %d", 0)),
client: genesisClient,
key: genesisKey,
uris: c.URIs,
Expand All @@ -82,13 +87,14 @@ func main() {
key, err := crypto.ToECDSA(crypto.Keccak256([]byte{uint8(i)}))
require.NoError(err, "failed to generate key")

require.NoError(transferFunds(ctx, genesisClient, genesisKey, crypto.PubkeyToAddress(key.PublicKey), initialAmount))
require.NoError(transferFunds(ctx, genesisClient, genesisKey, crypto.PubkeyToAddress(key.PublicKey), initialAmount, logger))

client, err := ethclient.Dial(getChainURI(c.URIs[i%len(c.URIs)], chainID.String()))
require.NoError(err, "failed to dial chain")

workloads[i] = &workload{
id: i,
log: ago_tests.NewDefaultLogger(fmt.Sprintf("worker %d", i)),
client: client,
key: key,
uris: c.URIs,
Expand All @@ -109,14 +115,15 @@ func main() {
type workload struct {
id int
client ethclient.Client
log logging.Logger
key *ecdsa.PrivateKey
uris []string
}

func (w *workload) run(ctx context.Context) {
timer := timerpkg.StoppedTimer()

tc := ago_tests.NewTestContext()
tc := ago_tests.NewTestContext(w.log)
defer tc.Cleanup()
require := require.New(tc)

Expand All @@ -132,12 +139,14 @@ func (w *workload) run(ctx context.Context) {
for {
// TODO(marun) Exercise a wider variety of transactions
recipientEthAddress := crypto.PubkeyToAddress(w.key.PublicKey)
err := transferFunds(ctx, w.client, w.key, recipientEthAddress, txAmount)
err := transferFunds(ctx, w.client, w.key, recipientEthAddress, txAmount, w.log)
if err != nil {
// Log the error and continue since the problem may be
// transient. require.NoError is only for errors that should stop
// execution.
log.Printf("failed to transfer funds: %s", err)
w.log.Info("failed to transfer funds",
zap.Error(err),
)
}

val, err := rand.Int(rand.Reader, big.NewInt(int64(time.Second)))
Expand All @@ -156,7 +165,7 @@ func getChainURI(nodeURI string, blockchainID string) string {
return fmt.Sprintf("%s/ext/bc/%s/rpc", nodeURI, blockchainID)
}

func transferFunds(ctx context.Context, client ethclient.Client, key *ecdsa.PrivateKey, recipientAddress common.Address, txAmount uint64) error {
func transferFunds(ctx context.Context, client ethclient.Client, key *ecdsa.PrivateKey, recipientAddress common.Address, txAmount uint64, log logging.Logger) error {
chainID, err := client.ChainID(ctx)
if err != nil {
return fmt.Errorf("failed to fetch chainID: %w", err)
Expand Down Expand Up @@ -188,17 +197,17 @@ func transferFunds(ctx context.Context, client ethclient.Client, key *ecdsa.Priv
return fmt.Errorf("failed to format transaction: %w", err)
}

log.Printf("sending transaction with ID %s and nonce %d\n", tx.Hash(), acceptedNonce)
log.Info("sending transaction", zap.Stringer("txID", tx.Hash()), zap.Uint64("nonce", acceptedNonce))
err = client.SendTransaction(ctx, tx)
if err != nil {
return fmt.Errorf("failed to send transaction: %w", err)
}

log.Printf("waiting for acceptance of transaction with ID %s\n", tx.Hash())
log.Info("waiting for acceptance of transaction", zap.Stringer("txID", tx.Hash()))
if _, err := bind.WaitMined(ctx, client, tx); err != nil {
return fmt.Errorf("failed to wait for receipt: %v", err)
}
log.Printf("confirmed acceptance of transaction with ID %s\n", tx.Hash())
log.Info("confirmed acceptance of transaction", zap.Stringer("txID", tx.Hash()))

return nil
}
10 changes: 3 additions & 7 deletions tests/utils/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func CreateSubnetsSuite(genesisFiles map[string]string) *SubnetSuite {
// each test case. Each test case has its own subnet, therefore all tests
// can run in parallel without any issue.
//
var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
_ = ginkgo.SynchronizedBeforeSuite(func() []byte {
ctx, cancel := context.WithTimeout(context.Background(), BootAvalancheNodeTimeout)
defer cancel()

Expand Down Expand Up @@ -101,7 +101,7 @@ func CreateSubnetsSuite(genesisFiles map[string]string) *SubnetSuite {
// SynchronizedAfterSuite() takes two functions, the first runs after each test suite is done and the second
// function is executed once when all the tests are done. This function is used
// to gracefully shutdown the AvalancheGo node.
var _ = ginkgo.SynchronizedAfterSuite(func() {}, func() {
_ = ginkgo.SynchronizedAfterSuite(func() {}, func() {
require.NotNil(startCmd)
require.NoError(startCmd.Stop())
})
Expand All @@ -118,11 +118,7 @@ func CreateNewSubnet(ctx context.Context, genesisFilePath string) string {

// MakeWallet fetches the available UTXOs owned by [kc] on the network
// that [LocalAPIURI] is hosting.
wallet, err := wallet.MakeWallet(ctx, &wallet.WalletConfig{
URI: DefaultLocalNodeURI,
AVAXKeychain: kc,
EthKeychain: kc,
})
wallet, err := wallet.MakeWallet(ctx, DefaultLocalNodeURI, kc, kc, wallet.WalletConfig{})
require.NoError(err)

pWallet := wallet.P()
Expand Down
Loading