From 45afbddcf717bac6847c4cedd27b78944b5e1bee Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Wed, 11 Dec 2024 17:04:29 +0300 Subject: [PATCH 01/12] bump coreth --- go.mod | 2 +- go.sum | 4 +- tests/e2e/c/dynamic_fees.go | 6 +-- tests/e2e/c/interchain_workflow.go | 6 +-- tests/e2e/p/interchain_workflow.go | 4 +- tests/e2e/x/interchain_workflow.go | 4 +- tests/fixture/tmpnet/genesis.go | 4 +- wallet/chain/c/backend.go | 10 ++--- wallet/chain/c/builder.go | 42 +++++++++---------- wallet/chain/c/builder_with_options.go | 6 +-- wallet/chain/c/signer.go | 22 +++++----- wallet/chain/c/wallet.go | 31 +++++++------- wallet/chain/c/wallet_with_options.go | 13 +++--- wallet/subnet/primary/api.go | 9 ++-- .../primary/examples/c-chain-import/main.go | 5 +-- 15 files changed, 84 insertions(+), 84 deletions(-) diff --git a/go.mod b/go.mod index 2aebc2449bf5..f4482f7f90a6 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/DataDog/zstd v1.5.2 github.com/NYTimes/gziphandler v1.1.1 github.com/antithesishq/antithesis-sdk-go v0.3.8 - github.com/ava-labs/coreth v0.13.9-0.20241212130727-826f07478957 + github.com/ava-labs/coreth v0.13.9-0.20241212181508-cec8f8bc8c27 github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 github.com/ava-labs/libevm v1.13.14-0.1.0.rc-2 github.com/btcsuite/btcd/btcutil v1.1.3 diff --git a/go.sum b/go.sum index fa7847c6f83a..4638293a6ba6 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,8 @@ 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/coreth v0.13.9-0.20241212130727-826f07478957 h1:/fC3IX58aFBpmtcBEeaxfkS/FaEp8ZUmDa19rlxjmQc= -github.com/ava-labs/coreth v0.13.9-0.20241212130727-826f07478957/go.mod h1:BlsmYTz7BwftckrNbapyM4erGfzqgGPVDyPiQzJqpsU= +github.com/ava-labs/coreth v0.13.9-0.20241212181508-cec8f8bc8c27 h1:RNPZUr8dt1MNRIgbpdtuw81yCQTkCm0Nhq2xZo+fwgc= +github.com/ava-labs/coreth v0.13.9-0.20241212181508-cec8f8bc8c27/go.mod h1:BlsmYTz7BwftckrNbapyM4erGfzqgGPVDyPiQzJqpsU= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 h1:EL66gtXOAwR/4KYBjOV03LTWgkEXvLePribLlJNu4g0= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60/go.mod h1:/7qKobTfbzBu7eSTVaXMTr56yTYk4j2Px6/8G+idxHo= github.com/ava-labs/libevm v1.13.14-0.1.0.rc-2 h1:CVbn0hSsPCl6gCkTCnqwuN4vtJgdVbkCqLXzYAE7qF8= diff --git a/tests/e2e/c/dynamic_fees.go b/tests/e2e/c/dynamic_fees.go index f3cba9def216..1c5f1d3f0e2a 100644 --- a/tests/e2e/c/dynamic_fees.go +++ b/tests/e2e/c/dynamic_fees.go @@ -9,7 +9,7 @@ import ( "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/ava-labs/libevm/accounts/abi" "github.com/ava-labs/libevm/common" "github.com/onsi/ginkgo/v2" @@ -48,7 +48,7 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() { tc.By("allocating a pre-funded key") key := privateNetwork.PreFundedKeys[0] - ethAddress := evm.GetEthAddress(key) + ethAddress := atomic.GetEthAddress(key) tc.By("initializing a coreth client") node := privateNetwork.Nodes[0] @@ -154,7 +154,7 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() { // Create a recipient address var ( recipientKey = e2e.NewPrivateKey(tc) - recipientEthAddress = evm.GetEthAddress(recipientKey) + recipientEthAddress = atomic.GetEthAddress(recipientKey) ) // Create transaction diff --git a/tests/e2e/c/interchain_workflow.go b/tests/e2e/c/interchain_workflow.go index f4b9cc85c544..6718bd86e504 100644 --- a/tests/e2e/c/interchain_workflow.go +++ b/tests/e2e/c/interchain_workflow.go @@ -7,7 +7,7 @@ import ( "math/big" "github.com/ava-labs/coreth/core/types" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/onsi/ginkgo/v2" "github.com/stretchr/testify/require" @@ -39,9 +39,9 @@ var _ = e2e.DescribeCChain("[Interchain Workflow]", func() { tc.By("allocating a pre-funded key to send from and a recipient key to deliver to") var ( senderKey = env.PreFundedKey - senderEthAddress = evm.GetEthAddress(senderKey) + senderEthAddress = atomic.GetEthAddress(senderKey) recipientKey = e2e.NewPrivateKey(tc) - recipientEthAddress = evm.GetEthAddress(recipientKey) + recipientEthAddress = atomic.GetEthAddress(recipientKey) ) tc.By("sending funds from one address to another on the C-Chain", func() { diff --git a/tests/e2e/p/interchain_workflow.go b/tests/e2e/p/interchain_workflow.go index a190a5a75131..06566c45c20e 100644 --- a/tests/e2e/p/interchain_workflow.go +++ b/tests/e2e/p/interchain_workflow.go @@ -7,7 +7,7 @@ import ( "math/big" "time" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/onsi/ginkgo/v2" "github.com/spf13/cast" "github.com/stretchr/testify/require" @@ -74,7 +74,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL ) tc.By("defining common configuration") - recipientEthAddress := evm.GetEthAddress(recipientKey) + recipientEthAddress := atomic.GetEthAddress(recipientKey) // Use the same owner for sending to X-Chain and importing funds to P-Chain recipientOwner := secp256k1fx.OutputOwners{ Threshold: 1, diff --git a/tests/e2e/x/interchain_workflow.go b/tests/e2e/x/interchain_workflow.go index 33f26cbc9bb4..5c0c7809f8d3 100644 --- a/tests/e2e/x/interchain_workflow.go +++ b/tests/e2e/x/interchain_workflow.go @@ -6,7 +6,7 @@ package x import ( "math/big" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/onsi/ginkgo/v2" "github.com/stretchr/testify/require" @@ -41,7 +41,7 @@ var _ = e2e.DescribeXChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL pWallet := baseWallet.P() tc.By("defining common configuration") - recipientEthAddress := evm.GetEthAddress(recipientKey) + recipientEthAddress := atomic.GetEthAddress(recipientKey) xBuilder := xWallet.Builder() xContext := xBuilder.Context() cBuilder := cWallet.Builder() diff --git a/tests/fixture/tmpnet/genesis.go b/tests/fixture/tmpnet/genesis.go index c914c9b94e9b..846f7339f59d 100644 --- a/tests/fixture/tmpnet/genesis.go +++ b/tests/fixture/tmpnet/genesis.go @@ -12,7 +12,7 @@ import ( "github.com/ava-labs/coreth/core" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" @@ -117,7 +117,7 @@ func NewTestGenesis( cChainBalances := make(core.GenesisAlloc, len(keysToFund)) for _, key := range keysToFund { xChainBalances[key.Address()] = defaultFundedKeyXChainAmount - cChainBalances[evm.GetEthAddress(key)] = core.GenesisAccount{ + cChainBalances[atomic.GetEthAddress(key)] = core.GenesisAccount{ Balance: defaultFundedKeyCChainAmount, } } diff --git a/wallet/chain/c/backend.go b/wallet/chain/c/backend.go index df9a44b216a1..cdf0bc503ff9 100644 --- a/wallet/chain/c/backend.go +++ b/wallet/chain/c/backend.go @@ -10,7 +10,7 @@ import ( "math/big" "sync" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/utils/math" @@ -32,7 +32,7 @@ type Backend interface { BuilderBackend SignerBackend - AcceptAtomicTx(ctx context.Context, tx *evm.Tx) error + AcceptAtomicTx(ctx context.Context, tx *atomic.Tx) error } type backend struct { @@ -57,9 +57,9 @@ func NewBackend( } } -func (b *backend) AcceptAtomicTx(ctx context.Context, tx *evm.Tx) error { +func (b *backend) AcceptAtomicTx(ctx context.Context, tx *atomic.Tx) error { switch tx := tx.UnsignedAtomicTx.(type) { - case *evm.UnsignedImportTx: + case *atomic.UnsignedImportTx: for _, input := range tx.ImportedInputs { utxoID := input.InputID() if err := b.RemoveUTXO(ctx, tx.SourceChain, utxoID); err != nil { @@ -80,7 +80,7 @@ func (b *backend) AcceptAtomicTx(ctx context.Context, tx *evm.Tx) error { balance.Mul(balance, avaxConversionRate) account.Balance.Add(account.Balance, balance) } - case *evm.UnsignedExportTx: + case *atomic.UnsignedExportTx: txID := tx.ID() for i, out := range tx.ExportedOutputs { err := b.AddUTXO( diff --git a/wallet/chain/c/builder.go b/wallet/chain/c/builder.go index 0128b060999e..a79202d0d7a0 100644 --- a/wallet/chain/c/builder.go +++ b/wallet/chain/c/builder.go @@ -8,7 +8,7 @@ import ( "errors" "math/big" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils" @@ -71,7 +71,7 @@ type Builder interface { to ethcommon.Address, baseFee *big.Int, options ...common.Option, - ) (*evm.UnsignedImportTx, error) + ) (*atomic.UnsignedImportTx, error) // NewExportTx creates an export transaction that attempts to send all the // provided [outputs] to the requested [chainID]. @@ -84,7 +84,7 @@ type Builder interface { outputs []*secp256k1fx.TransferOutput, baseFee *big.Int, options ...common.Option, - ) (*evm.UnsignedExportTx, error) + ) (*atomic.UnsignedExportTx, error) } // BuilderBackend specifies the required information needed to build unsigned @@ -185,7 +185,7 @@ func (b *builder) NewImportTx( to ethcommon.Address, baseFee *big.Int, options ...common.Option, -) (*evm.UnsignedImportTx, error) { +) (*atomic.UnsignedImportTx, error) { ops := common.NewOptions(options) utxos, err := b.backend.UTXOs(ops.Context(), chainID) if err != nil { @@ -226,7 +226,7 @@ func (b *builder) NewImportTx( } utils.Sort(importedInputs) - tx := &evm.UnsignedImportTx{ + tx := &atomic.UnsignedImportTx{ NetworkID: b.context.NetworkID, BlockchainID: b.context.BlockchainID, SourceChain: chainID, @@ -234,8 +234,8 @@ func (b *builder) NewImportTx( } // We must initialize the bytes of the tx to calculate the initial cost - wrappedTx := &evm.Tx{UnsignedAtomicTx: tx} - if err := wrappedTx.Sign(evm.Codec, nil); err != nil { + wrappedTx := &atomic.Tx{UnsignedAtomicTx: tx} + if err := wrappedTx.Sign(atomic.Codec, nil); err != nil { return nil, err } @@ -243,9 +243,9 @@ func (b *builder) NewImportTx( if err != nil { return nil, err } - gasUsedWithOutput := gasUsedWithoutOutput + evm.EVMOutputGas + gasUsedWithOutput := gasUsedWithoutOutput + atomic.EVMOutputGas - txFee, err := evm.CalculateDynamicFee(gasUsedWithOutput, baseFee) + txFee, err := atomic.CalculateDynamicFee(gasUsedWithOutput, baseFee) if err != nil { return nil, err } @@ -254,7 +254,7 @@ func (b *builder) NewImportTx( return nil, errInsufficientFunds } - tx.Outs = []evm.EVMOutput{{ + tx.Outs = []atomic.EVMOutput{{ Address: to, Amount: importedAmount - txFee, AssetID: avaxAssetID, @@ -267,7 +267,7 @@ func (b *builder) NewExportTx( outputs []*secp256k1fx.TransferOutput, baseFee *big.Int, options ...common.Option, -) (*evm.UnsignedExportTx, error) { +) (*atomic.UnsignedExportTx, error) { var ( avaxAssetID = b.context.AVAXAssetID exportedOutputs = make([]*avax.TransferableOutput, len(outputs)) @@ -287,8 +287,8 @@ func (b *builder) NewExportTx( exportedAmount = newExportedAmount } - avax.SortTransferableOutputs(exportedOutputs, evm.Codec) - tx := &evm.UnsignedExportTx{ + avax.SortTransferableOutputs(exportedOutputs, atomic.Codec) + tx := &atomic.UnsignedExportTx{ NetworkID: b.context.NetworkID, BlockchainID: b.context.BlockchainID, DestinationChain: chainID, @@ -296,8 +296,8 @@ func (b *builder) NewExportTx( } // We must initialize the bytes of the tx to calculate the initial cost - wrappedTx := &evm.Tx{UnsignedAtomicTx: tx} - if err := wrappedTx.Sign(evm.Codec, nil); err != nil { + wrappedTx := &atomic.Tx{UnsignedAtomicTx: tx} + if err := wrappedTx.Sign(atomic.Codec, nil); err != nil { return nil, err } @@ -306,7 +306,7 @@ func (b *builder) NewExportTx( return nil, err } - initialFee, err := evm.CalculateDynamicFee(cost, baseFee) + initialFee, err := atomic.CalculateDynamicFee(cost, baseFee) if err != nil { return nil, err } @@ -320,20 +320,20 @@ func (b *builder) NewExportTx( ops = common.NewOptions(options) ctx = ops.Context() addrs = ops.EthAddresses(b.ethAddrs) - inputs = make([]evm.EVMInput, 0, addrs.Len()) + inputs = make([]atomic.EVMInput, 0, addrs.Len()) ) for addr := range addrs { if amountToConsume == 0 { break } - prevFee, err := evm.CalculateDynamicFee(cost, baseFee) + prevFee, err := atomic.CalculateDynamicFee(cost, baseFee) if err != nil { return nil, err } - newCost := cost + evm.EVMInputGas - newFee, err := evm.CalculateDynamicFee(newCost, baseFee) + newCost := cost + atomic.EVMInputGas + newFee, err := atomic.CalculateDynamicFee(newCost, baseFee) if err != nil { return nil, err } @@ -371,7 +371,7 @@ func (b *builder) NewExportTx( } inputAmount := min(amountToConsume, avaxBalance) - inputs = append(inputs, evm.EVMInput{ + inputs = append(inputs, atomic.EVMInput{ Address: addr, Amount: inputAmount, AssetID: avaxAssetID, diff --git a/wallet/chain/c/builder_with_options.go b/wallet/chain/c/builder_with_options.go index 3f0d39117251..328c3a0f114e 100644 --- a/wallet/chain/c/builder_with_options.go +++ b/wallet/chain/c/builder_with_options.go @@ -6,7 +6,7 @@ package c import ( "math/big" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/vms/secp256k1fx" @@ -59,7 +59,7 @@ func (b *builderWithOptions) NewImportTx( to ethcommon.Address, baseFee *big.Int, options ...common.Option, -) (*evm.UnsignedImportTx, error) { +) (*atomic.UnsignedImportTx, error) { return b.Builder.NewImportTx( chainID, to, @@ -73,7 +73,7 @@ func (b *builderWithOptions) NewExportTx( outputs []*secp256k1fx.TransferOutput, baseFee *big.Int, options ...common.Option, -) (*evm.UnsignedExportTx, error) { +) (*atomic.UnsignedExportTx, error) { return b.Builder.NewExportTx( chainID, outputs, diff --git a/wallet/chain/c/signer.go b/wallet/chain/c/signer.go index e0e470ebfd98..399540ec134d 100644 --- a/wallet/chain/c/signer.go +++ b/wallet/chain/c/signer.go @@ -8,7 +8,7 @@ import ( "errors" "fmt" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/ava-labs/libevm/common" "github.com/ava-labs/avalanchego/database" @@ -44,7 +44,7 @@ type Signer interface { // // If the signer doesn't have the ability to provide a required signature, // the signature slot will be skipped without reporting an error. - SignAtomic(ctx context.Context, tx *evm.Tx) error + SignAtomic(ctx context.Context, tx *atomic.Tx) error } type EthKeychain interface { @@ -73,15 +73,15 @@ func NewSigner(avaxKC keychain.Keychain, ethKC EthKeychain, backend SignerBacken } } -func (s *txSigner) SignAtomic(ctx context.Context, tx *evm.Tx) error { +func (s *txSigner) SignAtomic(ctx context.Context, tx *atomic.Tx) error { switch utx := tx.UnsignedAtomicTx.(type) { - case *evm.UnsignedImportTx: + case *atomic.UnsignedImportTx: signers, err := s.getImportSigners(ctx, utx.SourceChain, utx.ImportedInputs) if err != nil { return err } return sign(tx, true, signers) - case *evm.UnsignedExportTx: + case *atomic.UnsignedExportTx: signers := s.getExportSigners(utx.Ins) return sign(tx, true, signers) default: @@ -134,7 +134,7 @@ func (s *txSigner) getImportSigners(ctx context.Context, sourceChainID ids.ID, i return txSigners, nil } -func (s *txSigner) getExportSigners(ins []evm.EVMInput) [][]keychain.Signer { +func (s *txSigner) getExportSigners(ins []atomic.EVMInput) [][]keychain.Signer { txSigners := make([][]keychain.Signer, len(ins)) for credIndex, input := range ins { inputSigners := make([]keychain.Signer, 1) @@ -151,14 +151,14 @@ func (s *txSigner) getExportSigners(ins []evm.EVMInput) [][]keychain.Signer { return txSigners } -func SignUnsignedAtomic(ctx context.Context, signer Signer, utx evm.UnsignedAtomicTx) (*evm.Tx, error) { - tx := &evm.Tx{UnsignedAtomicTx: utx} +func SignUnsignedAtomic(ctx context.Context, signer Signer, utx atomic.UnsignedAtomicTx) (*atomic.Tx, error) { + tx := &atomic.Tx{UnsignedAtomicTx: utx} return tx, signer.SignAtomic(ctx, tx) } // TODO: remove [signHash] after the ledger supports signing all transactions. -func sign(tx *evm.Tx, signHash bool, txSigners [][]keychain.Signer) error { - unsignedBytes, err := evm.Codec.Marshal(version, &tx.UnsignedAtomicTx) +func sign(tx *atomic.Tx, signHash bool, txSigners [][]keychain.Signer) error { + unsignedBytes, err := atomic.Codec.Marshal(version, &tx.UnsignedAtomicTx) if err != nil { return fmt.Errorf("couldn't marshal unsigned tx: %w", err) } @@ -219,7 +219,7 @@ func sign(tx *evm.Tx, signHash bool, txSigners [][]keychain.Signer) error { } } - signedBytes, err := evm.Codec.Marshal(version, tx) + signedBytes, err := atomic.Codec.Marshal(version, tx) if err != nil { return fmt.Errorf("couldn't marshal tx: %w", err) } diff --git a/wallet/chain/c/wallet.go b/wallet/chain/c/wallet.go index be632177107e..c58aaace1756 100644 --- a/wallet/chain/c/wallet.go +++ b/wallet/chain/c/wallet.go @@ -9,7 +9,8 @@ import ( "time" "github.com/ava-labs/coreth/ethclient" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/atomic" + "github.com/ava-labs/coreth/plugin/evm/client" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/rpc" @@ -37,7 +38,7 @@ type Wallet interface { chainID ids.ID, to ethcommon.Address, options ...common.Option, - ) (*evm.Tx, error) + ) (*atomic.Tx, error) // IssueExportTx creates, signs, and issues an export transaction that // attempts to send all the provided [outputs] to the requested [chainID]. @@ -48,17 +49,17 @@ type Wallet interface { chainID ids.ID, outputs []*secp256k1fx.TransferOutput, options ...common.Option, - ) (*evm.Tx, error) + ) (*atomic.Tx, error) // IssueUnsignedAtomicTx signs and issues the unsigned tx. IssueUnsignedAtomicTx( - utx evm.UnsignedAtomicTx, + utx atomic.UnsignedAtomicTx, options ...common.Option, - ) (*evm.Tx, error) + ) (*atomic.Tx, error) // IssueAtomicTx issues the signed tx. IssueAtomicTx( - tx *evm.Tx, + tx *atomic.Tx, options ...common.Option, ) error } @@ -66,7 +67,7 @@ type Wallet interface { func NewWallet( builder Builder, signer Signer, - avaxClient evm.Client, + avaxClient client.Client, ethClient ethclient.Client, backend Backend, ) Wallet { @@ -83,7 +84,7 @@ type wallet struct { Backend builder Builder signer Signer - avaxClient evm.Client + avaxClient client.Client ethClient ethclient.Client } @@ -99,7 +100,7 @@ func (w *wallet) IssueImportTx( chainID ids.ID, to ethcommon.Address, options ...common.Option, -) (*evm.Tx, error) { +) (*atomic.Tx, error) { baseFee, err := w.baseFee(options) if err != nil { return nil, err @@ -116,7 +117,7 @@ func (w *wallet) IssueExportTx( chainID ids.ID, outputs []*secp256k1fx.TransferOutput, options ...common.Option, -) (*evm.Tx, error) { +) (*atomic.Tx, error) { baseFee, err := w.baseFee(options) if err != nil { return nil, err @@ -130,9 +131,9 @@ func (w *wallet) IssueExportTx( } func (w *wallet) IssueUnsignedAtomicTx( - utx evm.UnsignedAtomicTx, + utx atomic.UnsignedAtomicTx, options ...common.Option, -) (*evm.Tx, error) { +) (*atomic.Tx, error) { ops := common.NewOptions(options) ctx := ops.Context() tx, err := SignUnsignedAtomic(ctx, w.signer, utx) @@ -144,7 +145,7 @@ func (w *wallet) IssueUnsignedAtomicTx( } func (w *wallet) IssueAtomicTx( - tx *evm.Tx, + tx *atomic.Tx, options ...common.Option, ) error { ops := common.NewOptions(options) @@ -182,7 +183,7 @@ func (w *wallet) baseFee(options []common.Option) (*big.Int, error) { // TODO: Upstream this function into coreth. func awaitTxAccepted( - c evm.Client, + c client.Client, ctx context.Context, txID ids.ID, freq time.Duration, @@ -197,7 +198,7 @@ func awaitTxAccepted( return err } - if status == evm.Accepted { + if status == atomic.Accepted { return nil } diff --git a/wallet/chain/c/wallet_with_options.go b/wallet/chain/c/wallet_with_options.go index e5ffaf6e9f93..653adbe5a549 100644 --- a/wallet/chain/c/wallet_with_options.go +++ b/wallet/chain/c/wallet_with_options.go @@ -4,11 +4,10 @@ package c import ( - "github.com/ava-labs/coreth/plugin/evm" - "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" + "github.com/ava-labs/coreth/plugin/evm/atomic" ethcommon "github.com/ava-labs/libevm/common" ) @@ -41,7 +40,7 @@ func (w *walletWithOptions) IssueImportTx( chainID ids.ID, to ethcommon.Address, options ...common.Option, -) (*evm.Tx, error) { +) (*atomic.Tx, error) { return w.Wallet.IssueImportTx( chainID, to, @@ -53,7 +52,7 @@ func (w *walletWithOptions) IssueExportTx( chainID ids.ID, outputs []*secp256k1fx.TransferOutput, options ...common.Option, -) (*evm.Tx, error) { +) (*atomic.Tx, error) { return w.Wallet.IssueExportTx( chainID, outputs, @@ -62,9 +61,9 @@ func (w *walletWithOptions) IssueExportTx( } func (w *walletWithOptions) IssueUnsignedAtomicTx( - utx evm.UnsignedAtomicTx, + utx atomic.UnsignedAtomicTx, options ...common.Option, -) (*evm.Tx, error) { +) (*atomic.Tx, error) { return w.Wallet.IssueUnsignedAtomicTx( utx, common.UnionOptions(w.options, options)..., @@ -72,7 +71,7 @@ func (w *walletWithOptions) IssueUnsignedAtomicTx( } func (w *walletWithOptions) IssueAtomicTx( - tx *evm.Tx, + tx *atomic.Tx, options ...common.Option, ) error { return w.Wallet.IssueAtomicTx( diff --git a/wallet/subnet/primary/api.go b/wallet/subnet/primary/api.go index 6ea169e65990..fa6ab7d745d2 100644 --- a/wallet/subnet/primary/api.go +++ b/wallet/subnet/primary/api.go @@ -8,9 +8,10 @@ import ( "fmt" "github.com/ava-labs/coreth/ethclient" - "github.com/ava-labs/coreth/plugin/evm" + "github.com/ava-labs/coreth/plugin/evm/client" "github.com/ava-labs/avalanchego/api/info" + "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" @@ -62,7 +63,7 @@ type AVAXState struct { PCTX *pbuilder.Context XClient avm.Client XCTX *xbuilder.Context - CClient evm.Client + CClient client.Client CCTX *c.Context UTXOs walletcommon.UTXOs } @@ -78,7 +79,7 @@ func FetchState( infoClient := info.NewClient(uri) pClient := platformvm.NewClient(uri) xClient := avm.NewClient(uri, "X") - cClient := evm.NewCChainClient(uri) + cClient := client.NewCChainClient(uri) pCTX, err := p.NewContextFromClients(ctx, infoClient, pClient) if err != nil { @@ -115,7 +116,7 @@ func FetchState( { id: cCTX.BlockchainID, client: cClient, - codec: evm.Codec, + codec: atomic.Codec, }, } for _, destinationChain := range chains { diff --git a/wallet/subnet/primary/examples/c-chain-import/main.go b/wallet/subnet/primary/examples/c-chain-import/main.go index 8b599cd4b742..9280c1e5f44e 100644 --- a/wallet/subnet/primary/examples/c-chain-import/main.go +++ b/wallet/subnet/primary/examples/c-chain-import/main.go @@ -8,8 +8,6 @@ import ( "log" "time" - "github.com/ava-labs/coreth/plugin/evm" - "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" @@ -17,6 +15,7 @@ import ( "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/subnet/primary" + "github.com/ava-labs/coreth/plugin/evm/atomic" ) func main() { @@ -24,7 +23,7 @@ func main() { uri := primary.LocalAPIURI kc := secp256k1fx.NewKeychain(key) avaxAddr := key.Address() - ethAddr := evm.PublicKeyToEthAddress(key.PublicKey()) + ethAddr := atomic.PublicKeyToEthAddress(key.PublicKey()) ctx := context.Background() From caaa39dbb2456fed91714a4727534d22442968f9 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Wed, 11 Dec 2024 17:35:11 +0300 Subject: [PATCH 02/12] lint --- wallet/chain/c/wallet_with_options.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wallet/chain/c/wallet_with_options.go b/wallet/chain/c/wallet_with_options.go index 653adbe5a549..d4912ed83217 100644 --- a/wallet/chain/c/wallet_with_options.go +++ b/wallet/chain/c/wallet_with_options.go @@ -4,10 +4,11 @@ package c import ( + "github.com/ava-labs/coreth/plugin/evm/atomic" + "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" - "github.com/ava-labs/coreth/plugin/evm/atomic" ethcommon "github.com/ava-labs/libevm/common" ) From 75b65b77a2aabfc91a79171f214ef334daf74656 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Wed, 11 Dec 2024 17:48:46 +0300 Subject: [PATCH 03/12] fix lint --- wallet/subnet/primary/examples/c-chain-import/main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wallet/subnet/primary/examples/c-chain-import/main.go b/wallet/subnet/primary/examples/c-chain-import/main.go index 9280c1e5f44e..6d7f07c2e4ee 100644 --- a/wallet/subnet/primary/examples/c-chain-import/main.go +++ b/wallet/subnet/primary/examples/c-chain-import/main.go @@ -8,6 +8,8 @@ import ( "log" "time" + "github.com/ava-labs/coreth/plugin/evm/atomic" + "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" @@ -15,7 +17,6 @@ import ( "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/subnet/primary" - "github.com/ava-labs/coreth/plugin/evm/atomic" ) func main() { From 6bf003426a29cfe161a1e8b3a4b18f303cdce919 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Thu, 12 Dec 2024 11:46:34 -0800 Subject: [PATCH 04/12] workaround ProcessContext --- tests/fixture/tmpnet/node_process.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/fixture/tmpnet/node_process.go b/tests/fixture/tmpnet/node_process.go index 68381ea00907..499029c9eae8 100644 --- a/tests/fixture/tmpnet/node_process.go +++ b/tests/fixture/tmpnet/node_process.go @@ -11,6 +11,7 @@ import ( "fmt" "io" "io/fs" + "net/netip" "os" "os/exec" "path/filepath" @@ -22,7 +23,6 @@ import ( "go.uber.org/zap" "github.com/ava-labs/avalanchego/config" - "github.com/ava-labs/avalanchego/node" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/perms" ) @@ -48,7 +48,13 @@ type NodeProcess struct { pid int } -func (p *NodeProcess) setProcessContext(processContext node.ProcessContext) { +type ProcessContext struct { + PID int + URI string + StakingAddress netip.AddrPort +} + +func (p *NodeProcess) setProcessContext(processContext ProcessContext) { p.pid = processContext.PID p.node.URI = processContext.URI p.node.StakingAddress = processContext.StakingAddress @@ -59,12 +65,12 @@ func (p *NodeProcess) readState() error { bytes, err := os.ReadFile(path) if errors.Is(err, fs.ErrNotExist) { // The absence of the process context file indicates the node is not running - p.setProcessContext(node.ProcessContext{}) + p.setProcessContext(ProcessContext{}) return nil } else if err != nil { return fmt.Errorf("failed to read node process context: %w", err) } - processContext := node.ProcessContext{} + processContext := ProcessContext{} if err := json.Unmarshal(bytes, &processContext); err != nil { return fmt.Errorf("failed to unmarshal node process context: %w", err) } From f992b2f170f7477c5f6c4937c8dfce9f0f1c2d63 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Thu, 12 Dec 2024 12:06:30 -0800 Subject: [PATCH 05/12] move configs to configNode --- config/config.go | 2 +- config/node/config.go | 221 ++++++++++++++++++++++++++++++++++++++++ node/config.go | 227 +++--------------------------------------- 3 files changed, 234 insertions(+), 216 deletions(-) create mode 100644 config/node/config.go diff --git a/config/config.go b/config/config.go index 8a95045b7f77..cb0c149df72e 100644 --- a/config/config.go +++ b/config/config.go @@ -20,12 +20,12 @@ import ( "github.com/ava-labs/avalanchego/api/server" "github.com/ava-labs/avalanchego/chains" + "github.com/ava-labs/avalanchego/config/node" "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/network" "github.com/ava-labs/avalanchego/network/dialer" "github.com/ava-labs/avalanchego/network/throttling" - "github.com/ava-labs/avalanchego/node" "github.com/ava-labs/avalanchego/snow/consensus/snowball" "github.com/ava-labs/avalanchego/snow/networking/benchlist" "github.com/ava-labs/avalanchego/snow/networking/router" diff --git a/config/node/config.go b/config/node/config.go new file mode 100644 index 000000000000..1c99b2de8a83 --- /dev/null +++ b/config/node/config.go @@ -0,0 +1,221 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package node + +import ( + "crypto/tls" + "net/netip" + "time" + + "github.com/ava-labs/avalanchego/api/server" + "github.com/ava-labs/avalanchego/chains" + "github.com/ava-labs/avalanchego/genesis" + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/network" + "github.com/ava-labs/avalanchego/snow/networking/benchlist" + "github.com/ava-labs/avalanchego/snow/networking/router" + "github.com/ava-labs/avalanchego/snow/networking/tracker" + "github.com/ava-labs/avalanchego/subnets" + "github.com/ava-labs/avalanchego/trace" + "github.com/ava-labs/avalanchego/upgrade" + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/logging" + "github.com/ava-labs/avalanchego/utils/profiler" + "github.com/ava-labs/avalanchego/utils/set" + "github.com/ava-labs/avalanchego/utils/timer" +) + +type APIIndexerConfig struct { + IndexAPIEnabled bool `json:"indexAPIEnabled"` + IndexAllowIncomplete bool `json:"indexAllowIncomplete"` +} + +type HTTPConfig struct { + server.HTTPConfig + APIConfig `json:"apiConfig"` + HTTPHost string `json:"httpHost"` + HTTPPort uint16 `json:"httpPort"` + + HTTPSEnabled bool `json:"httpsEnabled"` + HTTPSKey []byte `json:"-"` + HTTPSCert []byte `json:"-"` + + HTTPAllowedOrigins []string `json:"httpAllowedOrigins"` + HTTPAllowedHosts []string `json:"httpAllowedHosts"` + + ShutdownTimeout time.Duration `json:"shutdownTimeout"` + ShutdownWait time.Duration `json:"shutdownWait"` +} + +type APIConfig struct { + APIIndexerConfig `json:"indexerConfig"` + + // Enable/Disable APIs + AdminAPIEnabled bool `json:"adminAPIEnabled"` + InfoAPIEnabled bool `json:"infoAPIEnabled"` + KeystoreAPIEnabled bool `json:"keystoreAPIEnabled"` + MetricsAPIEnabled bool `json:"metricsAPIEnabled"` + HealthAPIEnabled bool `json:"healthAPIEnabled"` +} + +type IPConfig struct { + PublicIP string `json:"publicIP"` + PublicIPResolutionService string `json:"publicIPResolutionService"` + PublicIPResolutionFreq time.Duration `json:"publicIPResolutionFreq"` + // The host portion of the address to listen on. The port to + // listen on will be sourced from IPPort. + // + // - If empty, listen on all interfaces (both ipv4 and ipv6). + // - If populated, listen only on the specified address. + ListenHost string `json:"listenHost"` + ListenPort uint16 `json:"listenPort"` +} + +type StakingConfig struct { + genesis.StakingConfig + SybilProtectionEnabled bool `json:"sybilProtectionEnabled"` + PartialSyncPrimaryNetwork bool `json:"partialSyncPrimaryNetwork"` + StakingTLSCert tls.Certificate `json:"-"` + StakingSigningKey *bls.SecretKey `json:"-"` + SybilProtectionDisabledWeight uint64 `json:"sybilProtectionDisabledWeight"` + StakingKeyPath string `json:"stakingKeyPath"` + StakingCertPath string `json:"stakingCertPath"` + StakingSignerPath string `json:"stakingSignerPath"` +} + +type StateSyncConfig struct { + StateSyncIDs []ids.NodeID `json:"stateSyncIDs"` + StateSyncIPs []netip.AddrPort `json:"stateSyncIPs"` +} + +type BootstrapConfig struct { + // Timeout before emitting a warn log when connecting to bootstrapping beacons + BootstrapBeaconConnectionTimeout time.Duration `json:"bootstrapBeaconConnectionTimeout"` + + // Max number of containers in an ancestors message sent by this node. + BootstrapAncestorsMaxContainersSent int `json:"bootstrapAncestorsMaxContainersSent"` + + // This node will only consider the first [AncestorsMaxContainersReceived] + // containers in an ancestors message it receives. + BootstrapAncestorsMaxContainersReceived int `json:"bootstrapAncestorsMaxContainersReceived"` + + // Max time to spend fetching a container and its + // ancestors while responding to a GetAncestors message + BootstrapMaxTimeGetAncestors time.Duration `json:"bootstrapMaxTimeGetAncestors"` + + Bootstrappers []genesis.Bootstrapper `json:"bootstrappers"` +} + +type DatabaseConfig struct { + // If true, all writes are to memory and are discarded at node shutdown. + ReadOnly bool `json:"readOnly"` + + // Path to database + Path string `json:"path"` + + // Name of the database type to use + Name string `json:"name"` + + // Path to config file + Config []byte `json:"-"` +} + +// Config contains all of the configurations of an Avalanche node. +type Config struct { + HTTPConfig `json:"httpConfig"` + IPConfig `json:"ipConfig"` + StakingConfig `json:"stakingConfig"` + genesis.TxFeeConfig `json:"txFeeConfig"` + StateSyncConfig `json:"stateSyncConfig"` + BootstrapConfig `json:"bootstrapConfig"` + DatabaseConfig `json:"databaseConfig"` + + UpgradeConfig upgrade.Config `json:"upgradeConfig"` + + // Genesis information + GenesisBytes []byte `json:"-"` + AvaxAssetID ids.ID `json:"avaxAssetID"` + + // ID of the network this node should connect to + NetworkID uint32 `json:"networkID"` + + // Health + HealthCheckFreq time.Duration `json:"healthCheckFreq"` + + // Network configuration + NetworkConfig network.Config `json:"networkConfig"` + + AdaptiveTimeoutConfig timer.AdaptiveTimeoutConfig `json:"adaptiveTimeoutConfig"` + + BenchlistConfig benchlist.Config `json:"benchlistConfig"` + + ProfilerConfig profiler.Config `json:"profilerConfig"` + + LoggingConfig logging.Config `json:"loggingConfig"` + + PluginDir string `json:"pluginDir"` + + // File Descriptor Limit + FdLimit uint64 `json:"fdLimit"` + + // Metrics + MeterVMEnabled bool `json:"meterVMEnabled"` + + RouterHealthConfig router.HealthConfig `json:"routerHealthConfig"` + ConsensusShutdownTimeout time.Duration `json:"consensusShutdownTimeout"` + // Poll for new frontiers every [FrontierPollFrequency] + FrontierPollFrequency time.Duration `json:"consensusGossipFreq"` + // ConsensusAppConcurrency defines the maximum number of goroutines to + // handle App messages per chain. + ConsensusAppConcurrency int `json:"consensusAppConcurrency"` + + TrackedSubnets set.Set[ids.ID] `json:"trackedSubnets"` + + SubnetConfigs map[ids.ID]subnets.Config `json:"subnetConfigs"` + + ChainConfigs map[string]chains.ChainConfig `json:"-"` + ChainAliases map[ids.ID][]string `json:"chainAliases"` + + VMAliases map[ids.ID][]string `json:"vmAliases"` + + // Halflife to use for the processing requests tracker. + // Larger halflife --> usage metrics change more slowly. + SystemTrackerProcessingHalflife time.Duration `json:"systemTrackerProcessingHalflife"` + + // Frequency to check the real resource usage of tracked processes. + // More frequent checks --> usage metrics are more accurate, but more + // expensive to track + SystemTrackerFrequency time.Duration `json:"systemTrackerFrequency"` + + // Halflife to use for the cpu tracker. + // Larger halflife --> cpu usage metrics change more slowly. + SystemTrackerCPUHalflife time.Duration `json:"systemTrackerCPUHalflife"` + + // Halflife to use for the disk tracker. + // Larger halflife --> disk usage metrics change more slowly. + SystemTrackerDiskHalflife time.Duration `json:"systemTrackerDiskHalflife"` + + CPUTargeterConfig tracker.TargeterConfig `json:"cpuTargeterConfig"` + + DiskTargeterConfig tracker.TargeterConfig `json:"diskTargeterConfig"` + + RequiredAvailableDiskSpace uint64 `json:"requiredAvailableDiskSpace"` + WarningThresholdAvailableDiskSpace uint64 `json:"warningThresholdAvailableDiskSpace"` + + TraceConfig trace.Config `json:"traceConfig"` + + // See comment on [UseCurrentHeight] in platformvm.Config + UseCurrentHeight bool `json:"useCurrentHeight"` + + // ProvidedFlags contains all the flags set by the user + ProvidedFlags map[string]interface{} `json:"-"` + + // ChainDataDir is the root path for per-chain directories where VMs can + // write arbitrary data. + ChainDataDir string `json:"chainDataDir"` + + // Path to write process context to (including PID, API URI, and + // staking address). + ProcessContextFilePath string `json:"processContextFilePath"` +} diff --git a/node/config.go b/node/config.go index 1c99b2de8a83..991c96942389 100644 --- a/node/config.go +++ b/node/config.go @@ -3,219 +3,16 @@ package node -import ( - "crypto/tls" - "net/netip" - "time" - - "github.com/ava-labs/avalanchego/api/server" - "github.com/ava-labs/avalanchego/chains" - "github.com/ava-labs/avalanchego/genesis" - "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/network" - "github.com/ava-labs/avalanchego/snow/networking/benchlist" - "github.com/ava-labs/avalanchego/snow/networking/router" - "github.com/ava-labs/avalanchego/snow/networking/tracker" - "github.com/ava-labs/avalanchego/subnets" - "github.com/ava-labs/avalanchego/trace" - "github.com/ava-labs/avalanchego/upgrade" - "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/logging" - "github.com/ava-labs/avalanchego/utils/profiler" - "github.com/ava-labs/avalanchego/utils/set" - "github.com/ava-labs/avalanchego/utils/timer" +import "github.com/ava-labs/avalanchego/config/node" + +type ( + APIIndexerConfig = node.APIIndexerConfig + HTTPConfig = node.HTTPConfig + APIConfig = node.APIConfig + IPConfig = node.IPConfig + StakingConfig = node.StakingConfig + StateSyncConfig = node.StateSyncConfig + BootstrapConfig = node.BootstrapConfig + DatabaseConfig = node.DatabaseConfig + Config = node.Config ) - -type APIIndexerConfig struct { - IndexAPIEnabled bool `json:"indexAPIEnabled"` - IndexAllowIncomplete bool `json:"indexAllowIncomplete"` -} - -type HTTPConfig struct { - server.HTTPConfig - APIConfig `json:"apiConfig"` - HTTPHost string `json:"httpHost"` - HTTPPort uint16 `json:"httpPort"` - - HTTPSEnabled bool `json:"httpsEnabled"` - HTTPSKey []byte `json:"-"` - HTTPSCert []byte `json:"-"` - - HTTPAllowedOrigins []string `json:"httpAllowedOrigins"` - HTTPAllowedHosts []string `json:"httpAllowedHosts"` - - ShutdownTimeout time.Duration `json:"shutdownTimeout"` - ShutdownWait time.Duration `json:"shutdownWait"` -} - -type APIConfig struct { - APIIndexerConfig `json:"indexerConfig"` - - // Enable/Disable APIs - AdminAPIEnabled bool `json:"adminAPIEnabled"` - InfoAPIEnabled bool `json:"infoAPIEnabled"` - KeystoreAPIEnabled bool `json:"keystoreAPIEnabled"` - MetricsAPIEnabled bool `json:"metricsAPIEnabled"` - HealthAPIEnabled bool `json:"healthAPIEnabled"` -} - -type IPConfig struct { - PublicIP string `json:"publicIP"` - PublicIPResolutionService string `json:"publicIPResolutionService"` - PublicIPResolutionFreq time.Duration `json:"publicIPResolutionFreq"` - // The host portion of the address to listen on. The port to - // listen on will be sourced from IPPort. - // - // - If empty, listen on all interfaces (both ipv4 and ipv6). - // - If populated, listen only on the specified address. - ListenHost string `json:"listenHost"` - ListenPort uint16 `json:"listenPort"` -} - -type StakingConfig struct { - genesis.StakingConfig - SybilProtectionEnabled bool `json:"sybilProtectionEnabled"` - PartialSyncPrimaryNetwork bool `json:"partialSyncPrimaryNetwork"` - StakingTLSCert tls.Certificate `json:"-"` - StakingSigningKey *bls.SecretKey `json:"-"` - SybilProtectionDisabledWeight uint64 `json:"sybilProtectionDisabledWeight"` - StakingKeyPath string `json:"stakingKeyPath"` - StakingCertPath string `json:"stakingCertPath"` - StakingSignerPath string `json:"stakingSignerPath"` -} - -type StateSyncConfig struct { - StateSyncIDs []ids.NodeID `json:"stateSyncIDs"` - StateSyncIPs []netip.AddrPort `json:"stateSyncIPs"` -} - -type BootstrapConfig struct { - // Timeout before emitting a warn log when connecting to bootstrapping beacons - BootstrapBeaconConnectionTimeout time.Duration `json:"bootstrapBeaconConnectionTimeout"` - - // Max number of containers in an ancestors message sent by this node. - BootstrapAncestorsMaxContainersSent int `json:"bootstrapAncestorsMaxContainersSent"` - - // This node will only consider the first [AncestorsMaxContainersReceived] - // containers in an ancestors message it receives. - BootstrapAncestorsMaxContainersReceived int `json:"bootstrapAncestorsMaxContainersReceived"` - - // Max time to spend fetching a container and its - // ancestors while responding to a GetAncestors message - BootstrapMaxTimeGetAncestors time.Duration `json:"bootstrapMaxTimeGetAncestors"` - - Bootstrappers []genesis.Bootstrapper `json:"bootstrappers"` -} - -type DatabaseConfig struct { - // If true, all writes are to memory and are discarded at node shutdown. - ReadOnly bool `json:"readOnly"` - - // Path to database - Path string `json:"path"` - - // Name of the database type to use - Name string `json:"name"` - - // Path to config file - Config []byte `json:"-"` -} - -// Config contains all of the configurations of an Avalanche node. -type Config struct { - HTTPConfig `json:"httpConfig"` - IPConfig `json:"ipConfig"` - StakingConfig `json:"stakingConfig"` - genesis.TxFeeConfig `json:"txFeeConfig"` - StateSyncConfig `json:"stateSyncConfig"` - BootstrapConfig `json:"bootstrapConfig"` - DatabaseConfig `json:"databaseConfig"` - - UpgradeConfig upgrade.Config `json:"upgradeConfig"` - - // Genesis information - GenesisBytes []byte `json:"-"` - AvaxAssetID ids.ID `json:"avaxAssetID"` - - // ID of the network this node should connect to - NetworkID uint32 `json:"networkID"` - - // Health - HealthCheckFreq time.Duration `json:"healthCheckFreq"` - - // Network configuration - NetworkConfig network.Config `json:"networkConfig"` - - AdaptiveTimeoutConfig timer.AdaptiveTimeoutConfig `json:"adaptiveTimeoutConfig"` - - BenchlistConfig benchlist.Config `json:"benchlistConfig"` - - ProfilerConfig profiler.Config `json:"profilerConfig"` - - LoggingConfig logging.Config `json:"loggingConfig"` - - PluginDir string `json:"pluginDir"` - - // File Descriptor Limit - FdLimit uint64 `json:"fdLimit"` - - // Metrics - MeterVMEnabled bool `json:"meterVMEnabled"` - - RouterHealthConfig router.HealthConfig `json:"routerHealthConfig"` - ConsensusShutdownTimeout time.Duration `json:"consensusShutdownTimeout"` - // Poll for new frontiers every [FrontierPollFrequency] - FrontierPollFrequency time.Duration `json:"consensusGossipFreq"` - // ConsensusAppConcurrency defines the maximum number of goroutines to - // handle App messages per chain. - ConsensusAppConcurrency int `json:"consensusAppConcurrency"` - - TrackedSubnets set.Set[ids.ID] `json:"trackedSubnets"` - - SubnetConfigs map[ids.ID]subnets.Config `json:"subnetConfigs"` - - ChainConfigs map[string]chains.ChainConfig `json:"-"` - ChainAliases map[ids.ID][]string `json:"chainAliases"` - - VMAliases map[ids.ID][]string `json:"vmAliases"` - - // Halflife to use for the processing requests tracker. - // Larger halflife --> usage metrics change more slowly. - SystemTrackerProcessingHalflife time.Duration `json:"systemTrackerProcessingHalflife"` - - // Frequency to check the real resource usage of tracked processes. - // More frequent checks --> usage metrics are more accurate, but more - // expensive to track - SystemTrackerFrequency time.Duration `json:"systemTrackerFrequency"` - - // Halflife to use for the cpu tracker. - // Larger halflife --> cpu usage metrics change more slowly. - SystemTrackerCPUHalflife time.Duration `json:"systemTrackerCPUHalflife"` - - // Halflife to use for the disk tracker. - // Larger halflife --> disk usage metrics change more slowly. - SystemTrackerDiskHalflife time.Duration `json:"systemTrackerDiskHalflife"` - - CPUTargeterConfig tracker.TargeterConfig `json:"cpuTargeterConfig"` - - DiskTargeterConfig tracker.TargeterConfig `json:"diskTargeterConfig"` - - RequiredAvailableDiskSpace uint64 `json:"requiredAvailableDiskSpace"` - WarningThresholdAvailableDiskSpace uint64 `json:"warningThresholdAvailableDiskSpace"` - - TraceConfig trace.Config `json:"traceConfig"` - - // See comment on [UseCurrentHeight] in platformvm.Config - UseCurrentHeight bool `json:"useCurrentHeight"` - - // ProvidedFlags contains all the flags set by the user - ProvidedFlags map[string]interface{} `json:"-"` - - // ChainDataDir is the root path for per-chain directories where VMs can - // write arbitrary data. - ChainDataDir string `json:"chainDataDir"` - - // Path to write process context to (including PID, API URI, and - // staking address). - ProcessContextFilePath string `json:"processContextFilePath"` -} From 76243f2e94f85f1f5da428eda8473ec9621b34b6 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Thu, 12 Dec 2024 14:58:57 -0800 Subject: [PATCH 06/12] change some more imports --- genesis/genesis_test.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- tests/e2e/c/dynamic_fees.go | 4 ++-- tests/fixture/tmpnet/genesis.go | 23 +++++++++++------------ 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/genesis/genesis_test.go b/genesis/genesis_test.go index 3b77889101e2..e4979a2d733f 100644 --- a/genesis/genesis_test.go +++ b/genesis/genesis_test.go @@ -13,7 +13,7 @@ import ( "testing" "time" - "github.com/ava-labs/coreth/core" + "github.com/ava-labs/libevm/core" "github.com/stretchr/testify/require" _ "embed" diff --git a/go.mod b/go.mod index f4482f7f90a6..c5241d2256c8 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/DataDog/zstd v1.5.2 github.com/NYTimes/gziphandler v1.1.1 github.com/antithesishq/antithesis-sdk-go v0.3.8 - github.com/ava-labs/coreth v0.13.9-0.20241212181508-cec8f8bc8c27 + github.com/ava-labs/coreth v0.13.9-0.20241212225319-0011692590f7 github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 github.com/ava-labs/libevm v1.13.14-0.1.0.rc-2 github.com/btcsuite/btcd/btcutil v1.1.3 diff --git a/go.sum b/go.sum index 4638293a6ba6..1685369ffd43 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,8 @@ 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/coreth v0.13.9-0.20241212181508-cec8f8bc8c27 h1:RNPZUr8dt1MNRIgbpdtuw81yCQTkCm0Nhq2xZo+fwgc= -github.com/ava-labs/coreth v0.13.9-0.20241212181508-cec8f8bc8c27/go.mod h1:BlsmYTz7BwftckrNbapyM4erGfzqgGPVDyPiQzJqpsU= +github.com/ava-labs/coreth v0.13.9-0.20241212225319-0011692590f7 h1:t++aVVAxByMHkYXbuoOXhxWdjzU3LtSyAjZ+PsiX4/c= +github.com/ava-labs/coreth v0.13.9-0.20241212225319-0011692590f7/go.mod h1:BlsmYTz7BwftckrNbapyM4erGfzqgGPVDyPiQzJqpsU= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 h1:EL66gtXOAwR/4KYBjOV03LTWgkEXvLePribLlJNu4g0= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60/go.mod h1:/7qKobTfbzBu7eSTVaXMTr56yTYk4j2Px6/8G+idxHo= github.com/ava-labs/libevm v1.13.14-0.1.0.rc-2 h1:CVbn0hSsPCl6gCkTCnqwuN4vtJgdVbkCqLXzYAE7qF8= diff --git a/tests/e2e/c/dynamic_fees.go b/tests/e2e/c/dynamic_fees.go index 1c5f1d3f0e2a..ac83c0ba8eca 100644 --- a/tests/e2e/c/dynamic_fees.go +++ b/tests/e2e/c/dynamic_fees.go @@ -7,11 +7,11 @@ import ( "math/big" "strings" - "github.com/ava-labs/coreth/core/types" - "github.com/ava-labs/coreth/params" "github.com/ava-labs/coreth/plugin/evm/atomic" "github.com/ava-labs/libevm/accounts/abi" "github.com/ava-labs/libevm/common" + "github.com/ava-labs/libevm/core/types" + "github.com/ava-labs/libevm/params" "github.com/onsi/ginkgo/v2" "github.com/stretchr/testify/require" "go.uber.org/zap" diff --git a/tests/fixture/tmpnet/genesis.go b/tests/fixture/tmpnet/genesis.go index 846f7339f59d..ebe0dcd86340 100644 --- a/tests/fixture/tmpnet/genesis.go +++ b/tests/fixture/tmpnet/genesis.go @@ -4,15 +4,14 @@ package tmpnet import ( - "encoding/json" "errors" "fmt" "math/big" "time" - "github.com/ava-labs/coreth/core" - "github.com/ava-labs/coreth/params" + "github.com/ava-labs/coreth/clienttypes" "github.com/ava-labs/coreth/plugin/evm/atomic" + "github.com/ava-labs/libevm/core" "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" @@ -149,15 +148,15 @@ func NewTestGenesis( chainID := big.NewInt(int64(networkID)) // Define C-Chain genesis - cChainGenesis := &core.Genesis{ - // TODO: remove this after Etna and set only the chainID - Config: params.GetChainConfig(upgrade.Default, chainID), // upgrade will be again set by VM according to the snow.Context - Difficulty: big.NewInt(0), // Difficulty is a mandatory field - Timestamp: uint64(upgrade.InitiallyActiveTime.Unix()), // This time enables Avalanche upgrades by default - GasLimit: defaultGasLimit, - Alloc: cChainBalances, - } - cChainGenesisBytes, err := json.Marshal(cChainGenesis) + chainConfig, chainConfigExtras := clienttypes.GetChainConfig(upgrade.Default, chainID) + cChainGenesisBytes, err := clienttypes.MarshalGenesis( + &core.Genesis{ + Config: chainConfig, + Difficulty: big.NewInt(0), // Difficulty is a mandatory field + Timestamp: uint64(upgrade.InitiallyActiveTime.Unix()), // This time enables Avalanche upgrades by default + GasLimit: defaultGasLimit, + Alloc: cChainBalances, + }, chainConfigExtras) if err != nil { return nil, fmt.Errorf("failed to marshal C-Chain genesis: %w", err) } From eeecde3311bb4a4d5efbf7d4ce7a47558cfae761 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Thu, 12 Dec 2024 16:47:51 -0800 Subject: [PATCH 07/12] add failed logging --- scripts/lib_test_antithesis_images.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/lib_test_antithesis_images.sh b/scripts/lib_test_antithesis_images.sh index 6a6627f71890..db8a05809d6d 100644 --- a/scripts/lib_test_antithesis_images.sh +++ b/scripts/lib_test_antithesis_images.sh @@ -53,10 +53,11 @@ docker cp "${CONTAINER_NAME}":/volumes "${TMPDIR}/" TIMEOUT=30s HEALTHY_MESSAGE="all nodes reported healthy" -if timeout "${TIMEOUT}" bash -c "${COMPOSE_CMD} up 2>&1 | grep -m 1 '${HEALTHY_MESSAGE}'"; then +if timeout "${TIMEOUT}" bash -c "${COMPOSE_CMD} up 2>&1 | tee out.log | grep -m 1 '${HEALTHY_MESSAGE}'"; then echo "Saw log containing '${HEALTHY_MESSAGE}'" echo "Successfully invoked the antithesis test setup configured by ${IMAGE_NAME}:${IMAGE_TAG}" else + cat out.log echo "Failed to see log containing '${HEALTHY_MESSAGE}' within ${TIMEOUT}" exit 1 fi From 46b99d7482798e97e03e1a85180adb3d49b7394f Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Thu, 12 Dec 2024 16:51:47 -0800 Subject: [PATCH 08/12] bump coreth --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c5241d2256c8..9f4843639332 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/DataDog/zstd v1.5.2 github.com/NYTimes/gziphandler v1.1.1 github.com/antithesishq/antithesis-sdk-go v0.3.8 - github.com/ava-labs/coreth v0.13.9-0.20241212225319-0011692590f7 + github.com/ava-labs/coreth v0.13.9-0.20241213004938-d537b69672b1 github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 github.com/ava-labs/libevm v1.13.14-0.1.0.rc-2 github.com/btcsuite/btcd/btcutil v1.1.3 diff --git a/go.sum b/go.sum index 1685369ffd43..f879d7c17caf 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,8 @@ 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/coreth v0.13.9-0.20241212225319-0011692590f7 h1:t++aVVAxByMHkYXbuoOXhxWdjzU3LtSyAjZ+PsiX4/c= -github.com/ava-labs/coreth v0.13.9-0.20241212225319-0011692590f7/go.mod h1:BlsmYTz7BwftckrNbapyM4erGfzqgGPVDyPiQzJqpsU= +github.com/ava-labs/coreth v0.13.9-0.20241213004938-d537b69672b1 h1:PZ4lRGGkj5EMN++KTpbjE/XZjKS5Dhp5N0yDmHqmnJo= +github.com/ava-labs/coreth v0.13.9-0.20241213004938-d537b69672b1/go.mod h1:rhavEod/zgeBP8L+2lneIe374VYVMIpvgxW8WAF3wzo= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 h1:EL66gtXOAwR/4KYBjOV03LTWgkEXvLePribLlJNu4g0= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60/go.mod h1:/7qKobTfbzBu7eSTVaXMTr56yTYk4j2Px6/8G+idxHo= github.com/ava-labs/libevm v1.13.14-0.1.0.rc-2 h1:CVbn0hSsPCl6gCkTCnqwuN4vtJgdVbkCqLXzYAE7qF8= From f9b7a43895051623d2f11fac6e9f1f174bbb9b9f Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Thu, 12 Dec 2024 17:08:25 -0800 Subject: [PATCH 09/12] increase timeout --- scripts/lib_test_antithesis_images.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lib_test_antithesis_images.sh b/scripts/lib_test_antithesis_images.sh index db8a05809d6d..c7d38e404d4e 100644 --- a/scripts/lib_test_antithesis_images.sh +++ b/scripts/lib_test_antithesis_images.sh @@ -50,7 +50,7 @@ docker cp "${CONTAINER_NAME}":/volumes "${TMPDIR}/" # reporting healthy. This indicates that the workload has been correctly configured. Subsequent # validation will need to be tailored to a given workload implementation. -TIMEOUT=30s +TIMEOUT=60s HEALTHY_MESSAGE="all nodes reported healthy" if timeout "${TIMEOUT}" bash -c "${COMPOSE_CMD} up 2>&1 | tee out.log | grep -m 1 '${HEALTHY_MESSAGE}'"; then From 076f60bd5e57babe5ccee498440efa7cd6c92c46 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Mon, 16 Dec 2024 12:26:49 -0800 Subject: [PATCH 10/12] undo changes to scripts/lib_test_antithesis_images.sh --- scripts/lib_test_antithesis_images.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/lib_test_antithesis_images.sh b/scripts/lib_test_antithesis_images.sh index c7d38e404d4e..6a6627f71890 100644 --- a/scripts/lib_test_antithesis_images.sh +++ b/scripts/lib_test_antithesis_images.sh @@ -50,14 +50,13 @@ docker cp "${CONTAINER_NAME}":/volumes "${TMPDIR}/" # reporting healthy. This indicates that the workload has been correctly configured. Subsequent # validation will need to be tailored to a given workload implementation. -TIMEOUT=60s +TIMEOUT=30s HEALTHY_MESSAGE="all nodes reported healthy" -if timeout "${TIMEOUT}" bash -c "${COMPOSE_CMD} up 2>&1 | tee out.log | grep -m 1 '${HEALTHY_MESSAGE}'"; then +if timeout "${TIMEOUT}" bash -c "${COMPOSE_CMD} up 2>&1 | grep -m 1 '${HEALTHY_MESSAGE}'"; then echo "Saw log containing '${HEALTHY_MESSAGE}'" echo "Successfully invoked the antithesis test setup configured by ${IMAGE_NAME}:${IMAGE_TAG}" else - cat out.log echo "Failed to see log containing '${HEALTHY_MESSAGE}' within ${TIMEOUT}" exit 1 fi From 8c94e21222c2141959cd231eb5322a59662f7c0f Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Mon, 16 Dec 2024 13:17:03 -0800 Subject: [PATCH 11/12] try --- scripts/lib_test_antithesis_images.sh | 3 ++- tests/antithesis/config.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/lib_test_antithesis_images.sh b/scripts/lib_test_antithesis_images.sh index 6a6627f71890..51fb46520148 100644 --- a/scripts/lib_test_antithesis_images.sh +++ b/scripts/lib_test_antithesis_images.sh @@ -53,10 +53,11 @@ docker cp "${CONTAINER_NAME}":/volumes "${TMPDIR}/" TIMEOUT=30s HEALTHY_MESSAGE="all nodes reported healthy" -if timeout "${TIMEOUT}" bash -c "${COMPOSE_CMD} up 2>&1 | grep -m 1 '${HEALTHY_MESSAGE}'"; then +if timeout "${TIMEOUT}" bash -c "${COMPOSE_CMD} up 2>&1 | tee log.out | grep -m 1 '${HEALTHY_MESSAGE}'"; then echo "Saw log containing '${HEALTHY_MESSAGE}'" echo "Successfully invoked the antithesis test setup configured by ${IMAGE_NAME}:${IMAGE_TAG}" else + cat log.out echo "Failed to see log containing '${HEALTHY_MESSAGE}' within ${TIMEOUT}" exit 1 fi diff --git a/tests/antithesis/config.go b/tests/antithesis/config.go index 14568fd1df10..d9152fb7112a 100644 --- a/tests/antithesis/config.go +++ b/tests/antithesis/config.go @@ -74,6 +74,8 @@ func NewConfigWithSubnets(tc tests.TestContext, defaultNetwork *tmpnet.Network, ChainIDs: chainIDs, Duration: duration, } + } else { + tc.Log().Fatal("no URIs provided") } // Create a new network From 734d7d2abc85168d2f5903273f514fec98d3d873 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Mon, 16 Dec 2024 13:28:21 -0800 Subject: [PATCH 12/12] Revert "try" This reverts commit 8c94e21222c2141959cd231eb5322a59662f7c0f. --- scripts/lib_test_antithesis_images.sh | 3 +-- tests/antithesis/config.go | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/lib_test_antithesis_images.sh b/scripts/lib_test_antithesis_images.sh index 51fb46520148..6a6627f71890 100644 --- a/scripts/lib_test_antithesis_images.sh +++ b/scripts/lib_test_antithesis_images.sh @@ -53,11 +53,10 @@ docker cp "${CONTAINER_NAME}":/volumes "${TMPDIR}/" TIMEOUT=30s HEALTHY_MESSAGE="all nodes reported healthy" -if timeout "${TIMEOUT}" bash -c "${COMPOSE_CMD} up 2>&1 | tee log.out | grep -m 1 '${HEALTHY_MESSAGE}'"; then +if timeout "${TIMEOUT}" bash -c "${COMPOSE_CMD} up 2>&1 | grep -m 1 '${HEALTHY_MESSAGE}'"; then echo "Saw log containing '${HEALTHY_MESSAGE}'" echo "Successfully invoked the antithesis test setup configured by ${IMAGE_NAME}:${IMAGE_TAG}" else - cat log.out echo "Failed to see log containing '${HEALTHY_MESSAGE}' within ${TIMEOUT}" exit 1 fi diff --git a/tests/antithesis/config.go b/tests/antithesis/config.go index d9152fb7112a..14568fd1df10 100644 --- a/tests/antithesis/config.go +++ b/tests/antithesis/config.go @@ -74,8 +74,6 @@ func NewConfigWithSubnets(tc tests.TestContext, defaultNetwork *tmpnet.Network, ChainIDs: chainIDs, Duration: duration, } - } else { - tc.Log().Fatal("no URIs provided") } // Create a new network