From 3eacafabf6bf4e6af7c32f4968f3a4a84aee6fcc Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Tue, 19 Dec 2023 11:33:18 -0500 Subject: [PATCH 01/13] Use `snowtest` pkg --- go.mod | 4 +-- go.sum | 8 +++--- params/config.go | 27 +++++++++++---------- plugin/evm/block_builder_test.go | 8 +++--- plugin/evm/tx_gossip_test.go | 5 ++-- plugin/evm/vm_test.go | 3 ++- precompile/contracts/warp/contract_test.go | 6 ++--- precompile/contracts/warp/predicate_test.go | 7 +++--- precompile/testutils/test_precompile.go | 4 +-- warp/handlers/signature_request_test.go | 6 ++--- warp/validators/state_test.go | 4 +-- 11 files changed, 43 insertions(+), 39 deletions(-) diff --git a/go.mod b/go.mod index 6709bd2e0f..2698cb9339 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/VictoriaMetrics/fastcache v1.10.0 - github.com/ava-labs/avalanchego v1.10.18-rc.2 + github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231219161835-dcbba27ba8af github.com/cespare/cp v0.1.0 github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 github.com/davecgh/go-spew v1.1.1 @@ -39,7 +39,7 @@ require ( github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa go.uber.org/goleak v1.2.1 go.uber.org/mock v0.2.0 - golang.org/x/crypto v0.16.0 + golang.org/x/crypto v0.17.0 golang.org/x/exp v0.0.0-20231127185646-65229373498e golang.org/x/sync v0.5.0 golang.org/x/sys v0.15.0 diff --git a/go.sum b/go.sum index e0f2a4960c..616109193f 100644 --- a/go.sum +++ b/go.sum @@ -55,8 +55,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/avalanchego v1.10.18-rc.2 h1:fjks/pUp7HmGzjupl+f3MfGo5cLkCrDnoCarL8NyqlA= -github.com/ava-labs/avalanchego v1.10.18-rc.2/go.mod h1:D0tP5nGZtGb/vNOzvROUGUER+Gcar73l9qP97vbEarY= +github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231219161835-dcbba27ba8af h1:us3G2gSNOMo5KwyrrHTXEOUlkDZaPUVjEjrEwBqE5H4= +github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231219161835-dcbba27ba8af/go.mod h1:A5cyvLdc2OEOkDTqP7bRRWu/npQN4gcD3e8K2nugp4c= 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= @@ -648,8 +648,8 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= diff --git a/params/config.go b/params/config.go index c62aa40652..2cf6c1cbf3 100644 --- a/params/config.go +++ b/params/config.go @@ -33,6 +33,7 @@ import ( "time" "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/coreth/precompile/modules" "github.com/ava-labs/coreth/precompile/precompileconfig" "github.com/ava-labs/coreth/utils" @@ -134,7 +135,7 @@ var ( } TestChainConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -161,7 +162,7 @@ var ( } TestLaunchConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -188,7 +189,7 @@ var ( } TestApricotPhase1Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -215,7 +216,7 @@ var ( } TestApricotPhase2Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -242,7 +243,7 @@ var ( } TestApricotPhase3Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -269,7 +270,7 @@ var ( } TestApricotPhase4Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -296,7 +297,7 @@ var ( } TestApricotPhase5Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -323,7 +324,7 @@ var ( } TestApricotPhasePre6Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -350,7 +351,7 @@ var ( } TestApricotPhase6Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -377,7 +378,7 @@ var ( } TestApricotPhasePost6Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -404,7 +405,7 @@ var ( } TestBanffChainConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -431,7 +432,7 @@ var ( } TestCortinaChainConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -458,7 +459,7 @@ var ( } TestDUpgradeChainConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, diff --git a/plugin/evm/block_builder_test.go b/plugin/evm/block_builder_test.go index ce65c0c093..fdbe773c51 100644 --- a/plugin/evm/block_builder_test.go +++ b/plugin/evm/block_builder_test.go @@ -8,16 +8,16 @@ import ( "testing" "time" - "github.com/ava-labs/coreth/params" + "github.com/ava-labs/avalanchego/snow/snowtest" - "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/coreth/params" ) func TestBlockBuilderShutsDown(t *testing.T) { shutdownChan := make(chan struct{}) wg := &sync.WaitGroup{} builder := &blockBuilder{ - ctx: snow.DefaultContextTest(), + ctx: snowtest.EmptyContext(), chainConfig: params.TestChainConfig, shutdownChan: shutdownChan, shutdownWg: wg, @@ -34,7 +34,7 @@ func TestBlockBuilderSkipsTimerInitialization(t *testing.T) { shutdownChan := make(chan struct{}) wg := &sync.WaitGroup{} builder := &blockBuilder{ - ctx: snow.DefaultContextTest(), + ctx: snowtest.EmptyContext(), chainConfig: params.TestChainConfig, shutdownChan: shutdownChan, shutdownWg: wg, diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index cc41ad9ad5..b66abd8e4d 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -18,6 +18,7 @@ import ( "github.com/ava-labs/avalanchego/proto/pb/sdk" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/engine/common" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" @@ -37,7 +38,7 @@ import ( func TestEthTxGossip(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := snow.DefaultContextTest() + snowCtx := snowtest.EmptyContext() validatorState := &validators.TestState{} snowCtx.ValidatorState = validatorState @@ -157,7 +158,7 @@ func TestEthTxGossip(t *testing.T) { func TestAtomicTxGossip(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := snow.DefaultContextTest() + snowCtx := snowtest.EmptyContext() snowCtx.AVAXAssetID = ids.GenerateTestID() snowCtx.XChainID = ids.GenerateTestID() validatorState := &validators.TestState{ diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index 0f4dea63e9..3af74c6693 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -42,6 +42,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/cb58" "github.com/ava-labs/avalanchego/utils/constants" @@ -164,7 +165,7 @@ func BuildGenesisTest(t *testing.T, genesisJSON string) []byte { } func NewContext() *snow.Context { - ctx := snow.DefaultContextTest() + ctx := snowtest.EmptyContext() ctx.NodeID = ids.GenerateTestNodeID() ctx.NetworkID = testNetworkID ctx.ChainID = testCChainID diff --git a/precompile/contracts/warp/contract_test.go b/precompile/contracts/warp/contract_test.go index 4b20036157..915253831d 100644 --- a/precompile/contracts/warp/contract_test.go +++ b/precompile/contracts/warp/contract_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/platformvm/warp" @@ -27,7 +27,7 @@ import ( func TestGetBlockchainID(t *testing.T) { callerAddr := common.HexToAddress("0x0123") - defaultSnowCtx := snow.DefaultContextTest() + defaultSnowCtx := snowtest.EmptyContext() blockchainID := defaultSnowCtx.ChainID tests := map[string]testutils.PrecompileTest{ @@ -85,7 +85,7 @@ func TestGetBlockchainID(t *testing.T) { func TestSendWarpMessage(t *testing.T) { callerAddr := common.HexToAddress("0x0123") - defaultSnowCtx := snow.DefaultContextTest() + defaultSnowCtx := snowtest.EmptyContext() blockchainID := defaultSnowCtx.ChainID sendWarpMessagePayload := utils.RandomBytes(100) diff --git a/precompile/contracts/warp/predicate_test.go b/precompile/contracts/warp/predicate_test.go index 1aee80596a..4c04f2774c 100644 --- a/precompile/contracts/warp/predicate_test.go +++ b/precompile/contracts/warp/predicate_test.go @@ -12,6 +12,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" @@ -198,7 +199,7 @@ func createSnowCtx(validatorRanges []validatorRange) *snow.Context { } } - snowCtx := snow.DefaultContextTest() + snowCtx := snowtest.EmptyContext() state := &validators.TestState{ GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) { return sourceSubnetID, nil @@ -263,7 +264,7 @@ func TestWarpMessageFromPrimaryNetwork(t *testing.T) { predicateBytes := predicate.PackPredicate(warpMsg.Bytes()) - snowCtx := snow.DefaultContextTest() + snowCtx := snowtest.EmptyContext() snowCtx.SubnetID = ids.GenerateTestID() snowCtx.ChainID = ids.GenerateTestID() snowCtx.CChainID = cChainID @@ -664,7 +665,7 @@ func initWarpPredicateTests() { } } - snowCtx := snow.DefaultContextTest() + snowCtx := snowtest.EmptyContext() snowCtx.NetworkID = networkID state := &validators.TestState{ GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) { diff --git a/precompile/testutils/test_precompile.go b/precompile/testutils/test_precompile.go index 047ef7dae8..3058e8cfd6 100644 --- a/precompile/testutils/test_precompile.go +++ b/precompile/testutils/test_precompile.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/coreth/precompile/contract" "github.com/ava-labs/coreth/precompile/modules" "github.com/ava-labs/coreth/precompile/precompileconfig" @@ -103,7 +103,7 @@ func (test PrecompileTest) setup(t testing.TB, module modules.Module, state cont blockContext.EXPECT().Number().Return(big.NewInt(0)).AnyTimes() blockContext.EXPECT().Timestamp().Return(uint64(time.Now().Unix())).AnyTimes() } - snowContext := snow.DefaultContextTest() + snowContext := snowtest.EmptyContext() accessibleState := contract.NewMockAccessibleState(ctrl) accessibleState.EXPECT().GetStateDB().Return(state).AnyTimes() diff --git a/warp/handlers/signature_request_test.go b/warp/handlers/signature_request_test.go index 9f92fd2451..85c44fc0e8 100644 --- a/warp/handlers/signature_request_test.go +++ b/warp/handlers/signature_request_test.go @@ -10,11 +10,11 @@ import ( "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils/crypto/bls" avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/coreth/plugin/evm/message" @@ -24,7 +24,7 @@ import ( func TestMessageSignatureHandler(t *testing.T) { database := memdb.New() - snowCtx := snow.DefaultContextTest() + snowCtx := snowtest.EmptyContext() blsSecretKey, err := bls.NewSecretKey() require.NoError(t, err) @@ -105,7 +105,7 @@ func TestMessageSignatureHandler(t *testing.T) { func TestBlockSignatureHandler(t *testing.T) { database := memdb.New() - snowCtx := snow.DefaultContextTest() + snowCtx := snowtest.EmptyContext() blsSecretKey, err := bls.NewSecretKey() require.NoError(t, err) diff --git a/warp/validators/state_test.go b/warp/validators/state_test.go index 53705df6c7..50fe12c516 100644 --- a/warp/validators/state_test.go +++ b/warp/validators/state_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/constants" "github.com/stretchr/testify/require" @@ -23,7 +23,7 @@ func TestGetValidatorSetPrimaryNetwork(t *testing.T) { otherSubnetID := ids.GenerateTestID() mockState := validators.NewMockState(ctrl) - snowCtx := snow.DefaultContextTest() + snowCtx := snowtest.EmptyContext() snowCtx.SubnetID = mySubnetID snowCtx.ValidatorState = mockState state := NewState(snowCtx) From 2cf426de8601ea2b0ac331d24025983fdbefbb08 Mon Sep 17 00:00:00 2001 From: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> Date: Tue, 19 Dec 2023 18:12:15 -0500 Subject: [PATCH 02/13] add gossip marshallers Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +-- plugin/evm/gossip.go | 63 +++++++++++++++++++++--------------- plugin/evm/gossip_test.go | 38 +++++++++++++++------- plugin/evm/tx_gossip_test.go | 6 ++-- plugin/evm/vm.go | 29 +++++++++++++---- scripts/versions.sh | 2 +- 7 files changed, 95 insertions(+), 49 deletions(-) diff --git a/go.mod b/go.mod index 1c4f6d8e3f..fdaa59941c 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/VictoriaMetrics/fastcache v1.10.0 - github.com/ava-labs/avalanchego v1.10.18-rc.3 + github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231219230255-6a6438a71b40 github.com/cespare/cp v0.1.0 github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 github.com/davecgh/go-spew v1.1.1 diff --git a/go.sum b/go.sum index 4107173e9b..00f23b5a85 100644 --- a/go.sum +++ b/go.sum @@ -55,8 +55,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/avalanchego v1.10.18-rc.3 h1:LmTUUu0jXVAyRPs8xH7bD2I2vuW3TyvfLesKCkDBq1c= -github.com/ava-labs/avalanchego v1.10.18-rc.3/go.mod h1:A5cyvLdc2OEOkDTqP7bRRWu/npQN4gcD3e8K2nugp4c= +github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231219230255-6a6438a71b40 h1:Yjstm8ZqDCE7u4q9NhzgEXtvfAFRNWQFxlOKsgiddQI= +github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231219230255-6a6438a71b40/go.mod h1:8j1HFa7PT984IsVYKIc4pxCYAwwePuTDGxrdgpEmciw= 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= diff --git a/plugin/evm/gossip.go b/plugin/evm/gossip.go index 1bd73253e8..3d85cb00c1 100644 --- a/plugin/evm/gossip.go +++ b/plugin/evm/gossip.go @@ -24,14 +24,17 @@ import ( var ( _ p2p.Handler = (*txGossipHandler)(nil) - _ gossip.Gossipable = (*GossipEthTx)(nil) - _ gossip.Gossipable = (*GossipAtomicTx)(nil) - _ gossip.Set[*GossipEthTx] = (*GossipEthTxPool)(nil) + _ gossip.Gossipable = (*GossipEthTx)(nil) + _ gossip.Gossipable = (*GossipAtomicTx)(nil) + _ gossip.Marshaller[*GossipAtomicTx] = (*GossipAtomicTxMarshaller)(nil) + _ gossip.Marshaller[*GossipEthTx] = (*GossipEthTxMarshaller)(nil) + _ gossip.Set[*GossipEthTx] = (*GossipEthTxPool)(nil) ) -func newTxGossipHandler[T any, U gossip.GossipableAny[T]]( +func newTxGossipHandler[T gossip.Gossipable]( log logging.Logger, - mempool gossip.Set[U], + marshaller gossip.Marshaller[T], + mempool gossip.Set[T], metrics gossip.Metrics, maxMessageSize int, throttlingPeriod time.Duration, @@ -39,8 +42,9 @@ func newTxGossipHandler[T any, U gossip.GossipableAny[T]]( validators *p2p.Validators, ) txGossipHandler { // push gossip messages can be handled from any peer - handler := gossip.NewHandler[T, U]( + handler := gossip.NewHandler[T]( log, + marshaller, // Don't forward gossip to avoid double-forwarding gossip.NoOpAccumulator[U]{}, mempool, @@ -80,23 +84,25 @@ func (t txGossipHandler) AppRequest(ctx context.Context, nodeID ids.NodeID, dead return t.appRequestHandler.AppRequest(ctx, nodeID, deadline, requestBytes) } -type GossipAtomicTx struct { - Tx *Tx -} +type GossipAtomicTxMarshaller struct{} -func (tx *GossipAtomicTx) GetID() ids.ID { - return tx.Tx.ID() +func (g GossipAtomicTxMarshaller) MarshalGossip(tx *GossipAtomicTx) ([]byte, error) { + return tx.Tx.SignedBytes(), nil } -func (tx *GossipAtomicTx) Marshal() ([]byte, error) { - return tx.Tx.SignedBytes(), nil +func (g GossipAtomicTxMarshaller) UnmarshalGossip(bytes []byte) (*GossipAtomicTx, error) { + tx, err := ExtractAtomicTx(bytes, Codec) + return &GossipAtomicTx{ + Tx: tx, + }, err } -func (tx *GossipAtomicTx) Unmarshal(bytes []byte) error { - atomicTx, err := ExtractAtomicTx(bytes, Codec) - tx.Tx = atomicTx +type GossipAtomicTx struct { + Tx *Tx +} - return err +func (tx *GossipAtomicTx) GossipID() ids.ID { + return tx.Tx.ID() } func NewGossipEthTxPool(mempool *txpool.TxPool) (*GossipEthTxPool, error) { @@ -175,19 +181,24 @@ func (g *GossipEthTxPool) GetFilter() ([]byte, []byte, error) { return bloom, salt[:], err } -type GossipEthTx struct { - Tx *types.Transaction +type GossipEthTxMarshaller struct{} + +func (g GossipEthTxMarshaller) MarshalGossip(tx *GossipEthTx) ([]byte, error) { + return tx.Tx.MarshalBinary() } -func (tx *GossipEthTx) GetID() ids.ID { - return ids.ID(tx.Tx.Hash()) +func (g GossipEthTxMarshaller) UnmarshalGossip(bytes []byte) (*GossipEthTx, error) { + tx := &GossipEthTx{ + Tx: &types.Transaction{}, + } + + return tx, tx.Tx.UnmarshalBinary(bytes) } -func (tx *GossipEthTx) Marshal() ([]byte, error) { - return tx.Tx.MarshalBinary() +type GossipEthTx struct { + Tx *types.Transaction } -func (tx *GossipEthTx) Unmarshal(bytes []byte) error { - tx.Tx = &types.Transaction{} - return tx.Tx.UnmarshalBinary(bytes) +func (tx *GossipEthTx) GossipID() ids.ID { + return ids.ID(tx.Tx.Hash()) } diff --git a/plugin/evm/gossip_test.go b/plugin/evm/gossip_test.go index 1f7934b5e5..1fc23fe538 100644 --- a/plugin/evm/gossip_test.go +++ b/plugin/evm/gossip_test.go @@ -6,35 +6,36 @@ package evm import ( "testing" - "github.com/ava-labs/avalanchego/snow" - "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" - "github.com/ava-labs/avalanchego/vms/components/verify" "github.com/stretchr/testify/require" + "github.com/ava-labs/coreth/core/types" + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" + "github.com/ava-labs/avalanchego/vms/components/verify" ) -func TestGossipAtomicTxMarshal(t *testing.T) { +func TestGossipAtomicTxMarshaller(t *testing.T) { require := require.New(t) - expected := &GossipAtomicTx{ + want := &GossipAtomicTx{ Tx: &Tx{ UnsignedAtomicTx: &UnsignedImportTx{}, Creds: []verify.Verifiable{}, }, } + marshaller := GossipAtomicTxMarshaller{} key0 := testKeys[0] - require.NoError(expected.Tx.Sign(Codec, [][]*secp256k1.PrivateKey{{key0}})) + require.NoError(want.Tx.Sign(Codec, [][]*secp256k1.PrivateKey{{key0}})) - bytes, err := expected.Marshal() + bytes, err := marshaller.MarshalGossip(want) require.NoError(err) - actual := &GossipAtomicTx{} - require.NoError(actual.Unmarshal(bytes)) - + got, err := marshaller.UnmarshalGossip(bytes) require.NoError(err) - require.Equal(expected.GetID(), actual.GetID()) + require.Equal(want.GetID(), got.GetID()) } func TestAtomicMempoolIterate(t *testing.T) { @@ -118,3 +119,18 @@ func TestAtomicMempoolIterate(t *testing.T) { }) } } + +func TestGossipEthTxMarshaller(t *testing.T) { + require := require.New(t) + + blobTx := &types.BlobTx{} + want := &GossipEthTx{Tx: types.NewTx(blobTx)} + marshaller := GossipEthTxMarshaller{} + + bytes, err := marshaller.MarshalGossip(want) + require.NoError(err) + + got, err := marshaller.UnmarshalGossip(bytes) + require.NoError(err) + require.Equal(want.GetID(), got.GetID()) +} diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index 6de5a1f255..59482fbfb2 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -270,6 +270,8 @@ func TestAtomicTxGossip(t *testing.T) { // Ask the VM for new transactions. We should get the newly issued tx. wg.Add(1) + + marshaller := GossipAtomicTxMarshaller{} onResponse = func(_ context.Context, nodeID ids.NodeID, responseBytes []byte, err error) { require.NoError(err) @@ -277,8 +279,8 @@ func TestAtomicTxGossip(t *testing.T) { require.NoError(proto.Unmarshal(responseBytes, response)) require.Len(response.Gossip, 1) - gotTx := &GossipAtomicTx{} - require.NoError(gotTx.Unmarshal(response.Gossip[0])) + gotTx, err := marshaller.UnmarshalGossip(response.Gossip[0]) + require.NoError(err) require.Equal(tx.ID(), gotTx.GetID()) wg.Done() diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index f20830cd8e..56b1f747d3 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -1050,6 +1050,9 @@ func (vm *VM) initBlockBuilding() error { ctx, cancel := context.WithCancel(context.TODO()) vm.cancel = cancel + ethTxGossipMarshaller := GossipEthTxMarshaller{} + atomicTxGossipMarshaller := GossipAtomicTxMarshaller{} + ethTxGossipClient := vm.Network.NewClient(ethTxGossipProtocol, p2p.WithValidatorSampling(vm.validators)) atomicTxGossipClient := vm.Network.NewClient(atomicTxGossipProtocol, p2p.WithValidatorSampling(vm.validators)) @@ -1064,11 +1067,21 @@ func (vm *VM) initBlockBuilding() error { } if vm.ethTxPushGossiper == nil { - vm.ethTxPushGossiper = gossip.NewPushGossiper[*GossipEthTx](ethTxGossipClient, ethTxGossipMetrics, txGossipTargetMessageSize) + vm.ethTxPushGossiper = gossip.NewPushGossiper[*GossipEthTx]( + ethTxGossipMarshaller, + ethTxGossipClient, + ethTxGossipMetrics, + txGossipTargetMessageSize, + ) } if vm.atomicTxPushGossiper == nil { - vm.atomicTxPushGossiper = gossip.NewPushGossiper[*GossipAtomicTx](atomicTxGossipClient, atomicTxGossipMetrics, txGossipTargetMessageSize) + vm.atomicTxPushGossiper = gossip.NewPushGossiper[*GossipAtomicTx]( + atomicTxGossipMarshaller, + atomicTxGossipClient, + atomicTxGossipMetrics, + txGossipTargetMessageSize, + ) } // NOTE: gossip network must be initialized first otherwise ETH tx gossip will not work. @@ -1089,8 +1102,9 @@ func (vm *VM) initBlockBuilding() error { }() if vm.ethTxGossipHandler == nil { - vm.ethTxGossipHandler = newTxGossipHandler[GossipEthTx, *GossipEthTx]( + vm.ethTxGossipHandler = newTxGossipHandler[*GossipEthTx]( vm.ctx.Log, + ethTxGossipMarshaller, ethTxPool, ethTxGossipMetrics, txGossipTargetMessageSize, @@ -1105,8 +1119,9 @@ func (vm *VM) initBlockBuilding() error { } if vm.atomicTxGossipHandler == nil { - vm.atomicTxGossipHandler = newTxGossipHandler[GossipAtomicTx, *GossipAtomicTx]( + vm.atomicTxGossipHandler = newTxGossipHandler[*GossipAtomicTx]( vm.ctx.Log, + atomicTxGossipMarshaller, vm.mempool, atomicTxGossipMetrics, txGossipTargetMessageSize, @@ -1121,8 +1136,9 @@ func (vm *VM) initBlockBuilding() error { } if vm.ethTxPullGossiper == nil { - ethTxPullGossiper := gossip.NewPullGossiper[GossipEthTx, *GossipEthTx]( + ethTxPullGossiper := gossip.NewPullGossiper[*GossipEthTx]( vm.ctx.Log, + ethTxGossipMarshaller, ethTxPool, ethTxGossipClient, ethTxGossipMetrics, @@ -1143,8 +1159,9 @@ func (vm *VM) initBlockBuilding() error { }() if vm.atomicTxPullGossiper == nil { - atomicTxPullGossiper := gossip.NewPullGossiper[GossipAtomicTx, *GossipAtomicTx]( + atomicTxPullGossiper := gossip.NewPullGossiper[*GossipAtomicTx]( vm.ctx.Log, + atomicTxGossipMarshaller, vm.mempool, atomicTxGossipClient, atomicTxGossipMetrics, diff --git a/scripts/versions.sh b/scripts/versions.sh index 6839c600af..a052420d6e 100644 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash # Don't export them as they're used in the context of other calls -avalanche_version=${AVALANCHE_VERSION:-'v1.10.18-rc.3'} +avalanche_version=${AVALANCHE_VERSION:-'aafcde5'} From 224728dbacb4eaf199c9abfaa08f62903e30ec65 Mon Sep 17 00:00:00 2001 From: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> Date: Tue, 19 Dec 2023 18:14:51 -0500 Subject: [PATCH 03/13] nit Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> --- plugin/evm/gossip.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/evm/gossip.go b/plugin/evm/gossip.go index 3d85cb00c1..fd76b006ff 100644 --- a/plugin/evm/gossip.go +++ b/plugin/evm/gossip.go @@ -46,7 +46,7 @@ func newTxGossipHandler[T gossip.Gossipable]( log, marshaller, // Don't forward gossip to avoid double-forwarding - gossip.NoOpAccumulator[U]{}, + gossip.NoOpAccumulator[T]{}, mempool, metrics, maxMessageSize, From fe5ffbd20c05250f73e28cb68bbc4b3346380c5e Mon Sep 17 00:00:00 2001 From: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> Date: Tue, 19 Dec 2023 18:16:55 -0500 Subject: [PATCH 04/13] nit Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> --- scripts/versions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/versions.sh b/scripts/versions.sh index a052420d6e..e66f2a1417 100644 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash # Don't export them as they're used in the context of other calls -avalanche_version=${AVALANCHE_VERSION:-'aafcde5'} +avalanche_version=${AVALANCHE_VERSION:-'eeb1bc7'} From 25cf30c0d7fcc98ce613f1297e451e61eb79d954 Mon Sep 17 00:00:00 2001 From: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> Date: Tue, 19 Dec 2023 18:32:36 -0500 Subject: [PATCH 05/13] fix build Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> --- plugin/evm/gossip_test.go | 4 ++-- plugin/evm/tx_gossip_test.go | 35 ++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/plugin/evm/gossip_test.go b/plugin/evm/gossip_test.go index 1fc23fe538..f0fa8533af 100644 --- a/plugin/evm/gossip_test.go +++ b/plugin/evm/gossip_test.go @@ -35,7 +35,7 @@ func TestGossipAtomicTxMarshaller(t *testing.T) { got, err := marshaller.UnmarshalGossip(bytes) require.NoError(err) - require.Equal(want.GetID(), got.GetID()) + require.Equal(want.GossipID(), got.GossipID()) } func TestAtomicMempoolIterate(t *testing.T) { @@ -132,5 +132,5 @@ func TestGossipEthTxMarshaller(t *testing.T) { got, err := marshaller.UnmarshalGossip(bytes) require.NoError(err) - require.Equal(want.GetID(), got.GetID()) + require.Equal(want.GossipID(), got.GossipID()) } diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index 59482fbfb2..6086cda6c8 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -135,6 +135,7 @@ func TestEthTxGossip(t *testing.T) { // wait so we aren't throttled by the vm time.Sleep(5 * time.Second) + marshaller := GossipEthTxMarshaller{} // Ask the VM for new transactions. We should get the newly issued tx. wg.Add(1) onResponse = func(_ context.Context, nodeID ids.NodeID, responseBytes []byte, err error) { @@ -144,8 +145,8 @@ func TestEthTxGossip(t *testing.T) { require.NoError(proto.Unmarshal(responseBytes, response)) require.Len(response.Gossip, 1) - gotTx := &GossipEthTx{} - require.NoError(gotTx.Unmarshal(response.Gossip[0])) + gotTx, err := marshaller.UnmarshalGossip(response.Gossip[0]) + require.NoError(err) require.Equal(signedTx.Hash(), gotTx.Tx.Hash()) wg.Done() @@ -281,7 +282,7 @@ func TestAtomicTxGossip(t *testing.T) { gotTx, err := marshaller.UnmarshalGossip(response.Gossip[0]) require.NoError(err) - require.Equal(tx.ID(), gotTx.GetID()) + require.Equal(tx.ID(), gotTx.GossipID()) wg.Done() } @@ -341,10 +342,11 @@ func TestEthTxPushGossipOutbound(t *testing.T) { require.Equal(byte(ethTxGossipProtocol), sent[0]) require.NoError(proto.Unmarshal(sent[1:], got)) - gossipedTx := &GossipEthTx{} + marshaller := GossipEthTxMarshaller{} require.Len(got.Gossip, 1) - require.NoError(gossipedTx.Unmarshal(got.Gossip[0])) - require.Equal(ids.ID(signedTx.Hash()), gossipedTx.GetID()) + gossipedTx, err := marshaller.UnmarshalGossip(got.Gossip[0]) + require.NoError(err) + require.Equal(ids.ID(signedTx.Hash()), gossipedTx.GossipID()) } // Tests that a gossiped tx is added to the mempool and forwarded @@ -386,10 +388,11 @@ func TestEthTxPushGossipInbound(t *testing.T) { signedTx, err := types.SignTx(tx, types.NewEIP155Signer(vm.chainID), pk.ToECDSA()) require.NoError(err) + marshaller := GossipEthTxMarshaller{} gossipedTx := &GossipEthTx{ Tx: signedTx, } - gossipedTxBytes, err := gossipedTx.Marshal() + gossipedTxBytes, err := marshaller.MarshalGossip(gossipedTx) require.NoError(err) inboundGossip := &sdk.PushGossip{ @@ -409,9 +412,9 @@ func TestEthTxPushGossipInbound(t *testing.T) { require.NoError(proto.Unmarshal(outboundGossipBytes[1:], forwardedMsg)) require.Len(forwardedMsg.Gossip, 1) - forwardedTx := &GossipEthTx{} - require.NoError(forwardedTx.Unmarshal(forwardedMsg.Gossip[0])) - require.Equal(gossipedTx.GetID(), forwardedTx.GetID()) + forwardedTx, err := marshaller.UnmarshalGossip(forwardedMsg.Gossip[0]) + require.NoError(err) + require.Equal(gossipedTx.GossipID(), forwardedTx.GossipID()) require.True(vm.txPool.Has(signedTx.Hash())) } @@ -482,8 +485,9 @@ func TestAtomicTxPushGossipOutbound(t *testing.T) { require.NoError(proto.Unmarshal(gossipedBytes[1:], outboundGossipMsg)) require.Len(outboundGossipMsg.Gossip, 1) - gossipedTx := &GossipAtomicTx{} - require.NoError(gossipedTx.Unmarshal(outboundGossipMsg.Gossip[0])) + marshaller := GossipAtomicTxMarshaller{} + gossipedTx, err := marshaller.UnmarshalGossip(outboundGossipMsg.Gossip[0]) + require.NoError(err) require.Equal(tx.ID(), gossipedTx.Tx.ID()) } @@ -547,10 +551,11 @@ func TestAtomicTxPushGossipInbound(t *testing.T) { require.NoError(err) require.NoError(vm.mempool.AddLocalTx(tx)) + marshaller := GossipAtomicTxMarshaller{} gossipedTx := &GossipAtomicTx{ Tx: tx, } - gossipBytes, err := gossipedTx.Marshal() + gossipBytes, err := marshaller.MarshalGossip(gossipedTx) require.NoError(err) inboundGossip := &sdk.PushGossip{ @@ -570,8 +575,8 @@ func TestAtomicTxPushGossipInbound(t *testing.T) { require.NoError(proto.Unmarshal(forwardedBytes[1:], forwardedGossipMsg)) require.Len(forwardedGossipMsg.Gossip, 1) - forwardedTx := &GossipAtomicTx{} - require.NoError(forwardedTx.Unmarshal(forwardedGossipMsg.Gossip[0])) + forwardedTx, err := marshaller.UnmarshalGossip(forwardedGossipMsg.Gossip[0]) + require.NoError(err) require.Equal(tx.ID(), forwardedTx.Tx.ID()) require.True(vm.mempool.has(tx.ID())) } From 2b8e3849e30ebde885b41eaecf5fedcf55997a1a Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 21 Dec 2023 16:20:08 -0500 Subject: [PATCH 06/13] nit --- go.mod | 2 +- go.sum | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index ff74809f05..74eb3d4925 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/VictoriaMetrics/fastcache v1.10.0 - github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231220002200-6bf491850f5e + github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231221211726-20b6a1114b6a github.com/cespare/cp v0.1.0 github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 github.com/davecgh/go-spew v1.1.1 diff --git a/go.sum b/go.sum index d6ff0882dd..426cb5951c 100644 --- a/go.sum +++ b/go.sum @@ -51,12 +51,16 @@ github.com/VictoriaMetrics/fastcache v1.10.0 h1:5hDJnLsKLpnUEToub7ETuRu8RCkb40wo github.com/VictoriaMetrics/fastcache v1.10.0/go.mod h1:tjiYeEfYXCqacuvYw/7UoDIeJaNxq6132xHICNP77w8= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231220002200-6bf491850f5e h1:pCYeYa8+v0AZ9VUqL2HDVRXcbAFaSMarpaOeqwIRrU8= github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231220002200-6bf491850f5e/go.mod h1:A5cyvLdc2OEOkDTqP7bRRWu/npQN4gcD3e8K2nugp4c= +github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231221211726-20b6a1114b6a h1:wv+Dvg8wrN6hEa9Js0WG/NKeFg1CPaeGwBY0tSlshLo= +github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231221211726-20b6a1114b6a/go.mod h1:1tGWmhbOJvvpMUTk2ZncqAxbsPLXE6g6lFS12MHQx04= 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= @@ -122,6 +126,7 @@ github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 h1:ytcWPaNPhNoG github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811/go.mod h1:Nb5lgvnQ2+oGlE/EyZy4+2/CxRh9KfvCXnag1vtpxVM= github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ= github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= +github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2/go.mod h1:8BT+cPK6xvFOcRlk0R8eg+OTkcqI6baNH4xAkpiYVvQ= github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= @@ -208,6 +213,7 @@ github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxI github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -371,13 +377,16 @@ github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7Bd github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= github.com/kataras/golog v0.0.10/go.mod h1:yJ8YKCmyL+nWjERB90Qwn+bdyBZsaQwU3bTVFgkFIp8= github.com/kataras/iris/v12 v12.1.8/go.mod h1:LMYy4VlP67TQ3Zgriz8RE2h2kMZV2SgMYbq3UhfoFmE= @@ -408,6 +417,7 @@ github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4F github.com/labstack/echo/v4 v4.5.0/go.mod h1:czIriw4a0C1dFun+ObrXp7ok03xON0N1awStJ6ArI7Y= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= +github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= @@ -449,9 +459,11 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= @@ -548,6 +560,7 @@ github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobt github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -625,6 +638,7 @@ go.opentelemetry.io/otel/trace v1.11.0/go.mod h1:nyYjis9jy0gytE9LXGU+/m1sHTKbRY0 go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.19.0 h1:IVN6GR+mhC4s5yfcTbmzHYODqvWAp3ZedA2SJPI1Nnw= go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU= @@ -1025,6 +1039,7 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From b910cd74611cca88cf3b32a335fd5a30764ab5bc Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 21 Dec 2023 19:16:11 -0500 Subject: [PATCH 07/13] nits --- plugin/evm/tx_gossip_test.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index f982c35aef..c3d76dab70 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -297,7 +297,7 @@ func TestAtomicTxGossip(t *testing.T) { func TestEthTxPushGossipOutbound(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := snow.DefaultContextTest() + snowCtx := snowtest.Context(t, snowtest.CChainID) sender := &common.FakeSender{ SentAppGossip: make(chan []byte, 1), } @@ -354,7 +354,7 @@ func TestEthTxPushGossipOutbound(t *testing.T) { func TestEthTxPushGossipInbound(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := snow.DefaultContextTest() + snowCtx := snowtest.Context(t, snowtest.CChainID) sender := &common.FakeSender{ SentAppGossip: make(chan []byte, 1), @@ -423,9 +423,7 @@ func TestEthTxPushGossipInbound(t *testing.T) { func TestAtomicTxPushGossipOutbound(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := snow.DefaultContextTest() - snowCtx.AVAXAssetID = ids.GenerateTestID() - snowCtx.XChainID = ids.GenerateTestID() + snowCtx := snowtest.Context(t, snowtest.CChainID) validatorState := &validators.TestState{ GetSubnetIDF: func(context.Context, ids.ID) (ids.ID, error) { return ids.Empty, nil @@ -496,9 +494,7 @@ func TestAtomicTxPushGossipOutbound(t *testing.T) { func TestAtomicTxPushGossipInbound(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := snow.DefaultContextTest() - snowCtx.AVAXAssetID = ids.GenerateTestID() - snowCtx.XChainID = ids.GenerateTestID() + snowCtx := snowtest.Context(t, snowtest.CChainID) validatorState := &validators.TestState{ GetSubnetIDF: func(context.Context, ids.ID) (ids.ID, error) { return ids.Empty, nil From bcbc94ec96562767bdfa58cb240596218f843df7 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 21 Dec 2023 19:42:22 -0500 Subject: [PATCH 08/13] in-line `EmptyContext` --- params/config.go | 27 +++++++++---------- plugin/evm/block_builder_test.go | 7 +++-- plugin/evm/tx_gossip_test.go | 5 ++-- plugin/evm/vm_test.go | 3 +-- precompile/contracts/warp/contract_test.go | 6 ++--- precompile/contracts/warp/predicate_test.go | 7 +++-- precompile/testutils/test_precompile.go | 4 +-- utils/snow.go | 30 +++++++++++++++++++++ warp/handlers/signature_request_test.go | 6 ++--- warp/validators/state_test.go | 4 +-- 10 files changed, 63 insertions(+), 36 deletions(-) create mode 100644 utils/snow.go diff --git a/params/config.go b/params/config.go index 2cf6c1cbf3..587ae39c2f 100644 --- a/params/config.go +++ b/params/config.go @@ -33,7 +33,6 @@ import ( "time" "github.com/ava-labs/avalanchego/snow" - "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/coreth/precompile/modules" "github.com/ava-labs/coreth/precompile/precompileconfig" "github.com/ava-labs/coreth/utils" @@ -135,7 +134,7 @@ var ( } TestChainConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -162,7 +161,7 @@ var ( } TestLaunchConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -189,7 +188,7 @@ var ( } TestApricotPhase1Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -216,7 +215,7 @@ var ( } TestApricotPhase2Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -243,7 +242,7 @@ var ( } TestApricotPhase3Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -270,7 +269,7 @@ var ( } TestApricotPhase4Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -297,7 +296,7 @@ var ( } TestApricotPhase5Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -324,7 +323,7 @@ var ( } TestApricotPhasePre6Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -351,7 +350,7 @@ var ( } TestApricotPhase6Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -378,7 +377,7 @@ var ( } TestApricotPhasePost6Config = &ChainConfig{ - AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -405,7 +404,7 @@ var ( } TestBanffChainConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -432,7 +431,7 @@ var ( } TestCortinaChainConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, @@ -459,7 +458,7 @@ var ( } TestDUpgradeChainConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{snowtest.EmptyContext()}, + AvalancheContext: AvalancheContext{utils.TestSnowContext()}, ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, diff --git a/plugin/evm/block_builder_test.go b/plugin/evm/block_builder_test.go index fdbe773c51..316c4792b8 100644 --- a/plugin/evm/block_builder_test.go +++ b/plugin/evm/block_builder_test.go @@ -8,16 +8,15 @@ import ( "testing" "time" - "github.com/ava-labs/avalanchego/snow/snowtest" - "github.com/ava-labs/coreth/params" + "github.com/ava-labs/coreth/utils" ) func TestBlockBuilderShutsDown(t *testing.T) { shutdownChan := make(chan struct{}) wg := &sync.WaitGroup{} builder := &blockBuilder{ - ctx: snowtest.EmptyContext(), + ctx: utils.TestSnowContext(), chainConfig: params.TestChainConfig, shutdownChan: shutdownChan, shutdownWg: wg, @@ -34,7 +33,7 @@ func TestBlockBuilderSkipsTimerInitialization(t *testing.T) { shutdownChan := make(chan struct{}) wg := &sync.WaitGroup{} builder := &blockBuilder{ - ctx: snowtest.EmptyContext(), + ctx: utils.TestSnowContext(), chainConfig: params.TestChainConfig, shutdownChan: shutdownChan, shutdownWg: wg, diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index c3d76dab70..a77ec45dbf 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -35,12 +35,13 @@ import ( "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/params" + corethUtils "github.com/ava-labs/coreth/utils" ) func TestEthTxGossip(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := snowtest.EmptyContext() + snowCtx := corethUtils.TestSnowContext() validatorState := &validators.TestState{} snowCtx.ValidatorState = validatorState @@ -161,7 +162,7 @@ func TestEthTxGossip(t *testing.T) { func TestAtomicTxGossip(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := snowtest.EmptyContext() + snowCtx := corethUtils.TestSnowContext() snowCtx.AVAXAssetID = ids.GenerateTestID() snowCtx.XChainID = ids.GenerateTestID() validatorState := &validators.TestState{ diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index 77fd09c2d1..1feed0f11c 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -42,7 +42,6 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" - "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/cb58" "github.com/ava-labs/avalanchego/utils/constants" @@ -165,7 +164,7 @@ func BuildGenesisTest(t *testing.T, genesisJSON string) []byte { } func NewContext() *snow.Context { - ctx := snowtest.EmptyContext() + ctx := utils.TestSnowContext() ctx.NodeID = ids.GenerateTestNodeID() ctx.NetworkID = testNetworkID ctx.ChainID = testCChainID diff --git a/precompile/contracts/warp/contract_test.go b/precompile/contracts/warp/contract_test.go index 915253831d..c45f7a5946 100644 --- a/precompile/contracts/warp/contract_test.go +++ b/precompile/contracts/warp/contract_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/platformvm/warp" @@ -19,6 +18,7 @@ import ( "github.com/ava-labs/coreth/precompile/contract" "github.com/ava-labs/coreth/precompile/testutils" "github.com/ava-labs/coreth/predicate" + corethUtils "github.com/ava-labs/coreth/utils" "github.com/ava-labs/coreth/vmerrs" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" @@ -27,7 +27,7 @@ import ( func TestGetBlockchainID(t *testing.T) { callerAddr := common.HexToAddress("0x0123") - defaultSnowCtx := snowtest.EmptyContext() + defaultSnowCtx := corethUtils.TestSnowContext() blockchainID := defaultSnowCtx.ChainID tests := map[string]testutils.PrecompileTest{ @@ -85,7 +85,7 @@ func TestGetBlockchainID(t *testing.T) { func TestSendWarpMessage(t *testing.T) { callerAddr := common.HexToAddress("0x0123") - defaultSnowCtx := snowtest.EmptyContext() + defaultSnowCtx := corethUtils.TestSnowContext() blockchainID := defaultSnowCtx.ChainID sendWarpMessagePayload := utils.RandomBytes(100) diff --git a/precompile/contracts/warp/predicate_test.go b/precompile/contracts/warp/predicate_test.go index 4c04f2774c..88df1c534e 100644 --- a/precompile/contracts/warp/predicate_test.go +++ b/precompile/contracts/warp/predicate_test.go @@ -12,7 +12,6 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" - "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" @@ -199,7 +198,7 @@ func createSnowCtx(validatorRanges []validatorRange) *snow.Context { } } - snowCtx := snowtest.EmptyContext() + snowCtx := corethUtils.TestSnowContext() state := &validators.TestState{ GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) { return sourceSubnetID, nil @@ -264,7 +263,7 @@ func TestWarpMessageFromPrimaryNetwork(t *testing.T) { predicateBytes := predicate.PackPredicate(warpMsg.Bytes()) - snowCtx := snowtest.EmptyContext() + snowCtx := corethUtils.TestSnowContext() snowCtx.SubnetID = ids.GenerateTestID() snowCtx.ChainID = ids.GenerateTestID() snowCtx.CChainID = cChainID @@ -665,7 +664,7 @@ func initWarpPredicateTests() { } } - snowCtx := snowtest.EmptyContext() + snowCtx := corethUtils.TestSnowContext() snowCtx.NetworkID = networkID state := &validators.TestState{ GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) { diff --git a/precompile/testutils/test_precompile.go b/precompile/testutils/test_precompile.go index 3058e8cfd6..ee38ad51bb 100644 --- a/precompile/testutils/test_precompile.go +++ b/precompile/testutils/test_precompile.go @@ -8,10 +8,10 @@ import ( "testing" "time" - "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/coreth/precompile/contract" "github.com/ava-labs/coreth/precompile/modules" "github.com/ava-labs/coreth/precompile/precompileconfig" + "github.com/ava-labs/coreth/utils" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" @@ -103,7 +103,7 @@ func (test PrecompileTest) setup(t testing.TB, module modules.Module, state cont blockContext.EXPECT().Number().Return(big.NewInt(0)).AnyTimes() blockContext.EXPECT().Timestamp().Return(uint64(time.Now().Unix())).AnyTimes() } - snowContext := snowtest.EmptyContext() + snowContext := utils.TestSnowContext() accessibleState := contract.NewMockAccessibleState(ctrl) accessibleState.EXPECT().GetStateDB().Return(state).AnyTimes() diff --git a/utils/snow.go b/utils/snow.go new file mode 100644 index 0000000000..50caa40b90 --- /dev/null +++ b/utils/snow.go @@ -0,0 +1,30 @@ +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package utils + +import ( + "github.com/ava-labs/avalanchego/api/metrics" + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/logging" +) + +func TestSnowContext() *snow.Context { + sk, err := bls.NewSecretKey() + if err != nil { + panic(err) + } + pk := bls.PublicFromSecretKey(sk) + return &snow.Context{ + NetworkID: 0, + SubnetID: ids.Empty, + ChainID: ids.Empty, + NodeID: ids.EmptyNodeID, + PublicKey: pk, + Log: logging.NoLog{}, + Metrics: metrics.NewOptionalGatherer(), + ChainDataDir: "", + } +} diff --git a/warp/handlers/signature_request_test.go b/warp/handlers/signature_request_test.go index 4a58ba069e..7dc6347bff 100644 --- a/warp/handlers/signature_request_test.go +++ b/warp/handlers/signature_request_test.go @@ -14,18 +14,18 @@ import ( "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" - "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils/crypto/bls" avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload" "github.com/ava-labs/coreth/plugin/evm/message" + "github.com/ava-labs/coreth/utils" "github.com/ava-labs/coreth/warp" "github.com/stretchr/testify/require" ) func TestMessageSignatureHandler(t *testing.T) { database := memdb.New() - snowCtx := snowtest.EmptyContext() + snowCtx := utils.TestSnowContext() blsSecretKey, err := bls.NewSecretKey() require.NoError(t, err) warpSigner := avalancheWarp.NewSigner(blsSecretKey, snowCtx.NetworkID, snowCtx.ChainID) @@ -129,7 +129,7 @@ func TestMessageSignatureHandler(t *testing.T) { func TestBlockSignatureHandler(t *testing.T) { database := memdb.New() - snowCtx := snowtest.EmptyContext() + snowCtx := utils.TestSnowContext() blsSecretKey, err := bls.NewSecretKey() require.NoError(t, err) diff --git a/warp/validators/state_test.go b/warp/validators/state_test.go index 50fe12c516..e06d1374ad 100644 --- a/warp/validators/state_test.go +++ b/warp/validators/state_test.go @@ -8,9 +8,9 @@ import ( "testing" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/constants" + "github.com/ava-labs/coreth/utils" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) @@ -23,7 +23,7 @@ func TestGetValidatorSetPrimaryNetwork(t *testing.T) { otherSubnetID := ids.GenerateTestID() mockState := validators.NewMockState(ctrl) - snowCtx := snowtest.EmptyContext() + snowCtx := utils.TestSnowContext() snowCtx.SubnetID = mySubnetID snowCtx.ValidatorState = mockState state := NewState(snowCtx) From dee53bc2e175352a6d438bd7818cfbc52b7bcd65 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 21 Dec 2023 19:43:07 -0500 Subject: [PATCH 09/13] nit --- go.mod | 2 +- go.sum | 19 ++----------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 74eb3d4925..bd87ae7d1e 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/VictoriaMetrics/fastcache v1.10.0 - github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231221211726-20b6a1114b6a + github.com/ava-labs/avalanchego v1.10.18-rc.5 github.com/cespare/cp v0.1.0 github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 github.com/davecgh/go-spew v1.1.1 diff --git a/go.sum b/go.sum index 426cb5951c..1b9a183cba 100644 --- a/go.sum +++ b/go.sum @@ -51,16 +51,12 @@ github.com/VictoriaMetrics/fastcache v1.10.0 h1:5hDJnLsKLpnUEToub7ETuRu8RCkb40wo github.com/VictoriaMetrics/fastcache v1.10.0/go.mod h1:tjiYeEfYXCqacuvYw/7UoDIeJaNxq6132xHICNP77w8= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231220002200-6bf491850f5e h1:pCYeYa8+v0AZ9VUqL2HDVRXcbAFaSMarpaOeqwIRrU8= -github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231220002200-6bf491850f5e/go.mod h1:A5cyvLdc2OEOkDTqP7bRRWu/npQN4gcD3e8K2nugp4c= -github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231221211726-20b6a1114b6a h1:wv+Dvg8wrN6hEa9Js0WG/NKeFg1CPaeGwBY0tSlshLo= -github.com/ava-labs/avalanchego v1.10.18-rc.3.0.20231221211726-20b6a1114b6a/go.mod h1:1tGWmhbOJvvpMUTk2ZncqAxbsPLXE6g6lFS12MHQx04= +github.com/ava-labs/avalanchego v1.10.18-rc.5 h1:kGfadhGDa/jKLunRJvQ4cLvKvJzd1MJDspHFnKWEsHk= +github.com/ava-labs/avalanchego v1.10.18-rc.5/go.mod h1:RfJ7vv0nOk9iZrxcjQC6HnLNwlPFxkRVJhvGq+++0po= 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= @@ -126,7 +122,6 @@ github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 h1:ytcWPaNPhNoG github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811/go.mod h1:Nb5lgvnQ2+oGlE/EyZy4+2/CxRh9KfvCXnag1vtpxVM= github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ= github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= -github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2/go.mod h1:8BT+cPK6xvFOcRlk0R8eg+OTkcqI6baNH4xAkpiYVvQ= github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= @@ -213,7 +208,6 @@ github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxI github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -377,16 +371,13 @@ github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7Bd github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= github.com/kataras/golog v0.0.10/go.mod h1:yJ8YKCmyL+nWjERB90Qwn+bdyBZsaQwU3bTVFgkFIp8= github.com/kataras/iris/v12 v12.1.8/go.mod h1:LMYy4VlP67TQ3Zgriz8RE2h2kMZV2SgMYbq3UhfoFmE= @@ -417,7 +408,6 @@ github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4F github.com/labstack/echo/v4 v4.5.0/go.mod h1:czIriw4a0C1dFun+ObrXp7ok03xON0N1awStJ6ArI7Y= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= -github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= @@ -459,11 +449,9 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= @@ -560,7 +548,6 @@ github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobt github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -638,7 +625,6 @@ go.opentelemetry.io/otel/trace v1.11.0/go.mod h1:nyYjis9jy0gytE9LXGU+/m1sHTKbRY0 go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.19.0 h1:IVN6GR+mhC4s5yfcTbmzHYODqvWAp3ZedA2SJPI1Nnw= go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= -go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU= @@ -1039,7 +1025,6 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 0f093358bc66afa0e8e2dfb06c2fa5ff23beb868 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 21 Dec 2023 19:49:20 -0500 Subject: [PATCH 10/13] nit --- utils/snow.go | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/snow.go b/utils/snow.go index 50caa40b90..7600744187 100644 --- a/utils/snow.go +++ b/utils/snow.go @@ -24,6 +24,7 @@ func TestSnowContext() *snow.Context { NodeID: ids.EmptyNodeID, PublicKey: pk, Log: logging.NoLog{}, + BCLookup: ids.NewAliaser(), Metrics: metrics.NewOptionalGatherer(), ChainDataDir: "", } From 23796eb940c9dedd1ed4ade31d4220d8994c191f Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:14:50 -0500 Subject: [PATCH 11/13] nit --- plugin/evm/tx_gossip_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index a77ec45dbf..dcb1f89c49 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -22,7 +22,6 @@ import ( "github.com/ava-labs/avalanchego/proto/pb/sdk" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/engine/common" - "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" @@ -298,7 +297,7 @@ func TestAtomicTxGossip(t *testing.T) { func TestEthTxPushGossipOutbound(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := snowtest.Context(t, snowtest.CChainID) + snowCtx := corethUtils.TestSnowContext() sender := &common.FakeSender{ SentAppGossip: make(chan []byte, 1), } @@ -355,7 +354,7 @@ func TestEthTxPushGossipOutbound(t *testing.T) { func TestEthTxPushGossipInbound(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := snowtest.Context(t, snowtest.CChainID) + snowCtx := corethUtils.TestSnowContext() sender := &common.FakeSender{ SentAppGossip: make(chan []byte, 1), @@ -424,7 +423,7 @@ func TestEthTxPushGossipInbound(t *testing.T) { func TestAtomicTxPushGossipOutbound(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := snowtest.Context(t, snowtest.CChainID) + snowCtx := corethUtils.TestSnowContext() validatorState := &validators.TestState{ GetSubnetIDF: func(context.Context, ids.ID) (ids.ID, error) { return ids.Empty, nil @@ -495,7 +494,7 @@ func TestAtomicTxPushGossipOutbound(t *testing.T) { func TestAtomicTxPushGossipInbound(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := snowtest.Context(t, snowtest.CChainID) + snowCtx := corethUtils.TestSnowContext() validatorState := &validators.TestState{ GetSubnetIDF: func(context.Context, ids.ID) (ids.ID, error) { return ids.Empty, nil From 3e34a861b53a905d177a976a9c6358653fff54a0 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:15:56 -0500 Subject: [PATCH 12/13] reduce diff --- plugin/evm/tx_gossip_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index dcb1f89c49..480e69f917 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -424,6 +424,8 @@ func TestAtomicTxPushGossipOutbound(t *testing.T) { require := require.New(t) ctx := context.Background() snowCtx := corethUtils.TestSnowContext() + snowCtx.AVAXAssetID = ids.GenerateTestID() + snowCtx.XChainID = ids.GenerateTestID() validatorState := &validators.TestState{ GetSubnetIDF: func(context.Context, ids.ID) (ids.ID, error) { return ids.Empty, nil @@ -495,6 +497,8 @@ func TestAtomicTxPushGossipInbound(t *testing.T) { require := require.New(t) ctx := context.Background() snowCtx := corethUtils.TestSnowContext() + snowCtx.AVAXAssetID = ids.GenerateTestID() + snowCtx.XChainID = ids.GenerateTestID() validatorState := &validators.TestState{ GetSubnetIDF: func(context.Context, ids.ID) (ids.ID, error) { return ids.Empty, nil From 2bf4768cc9ce7e64f08becf13f3be1ae69424c75 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 22 Dec 2023 11:51:23 -0500 Subject: [PATCH 13/13] naming nit --- plugin/evm/tx_gossip_test.go | 20 ++++++------ precompile/contracts/warp/contract_test.go | 11 ++++--- precompile/contracts/warp/predicate_test.go | 36 ++++++++++----------- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index 480e69f917..663ef04778 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -23,7 +23,7 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/validators" - "github.com/ava-labs/avalanchego/utils" + agoUtils "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/set" @@ -34,13 +34,13 @@ import ( "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/params" - corethUtils "github.com/ava-labs/coreth/utils" + "github.com/ava-labs/coreth/utils" ) func TestEthTxGossip(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := corethUtils.TestSnowContext() + snowCtx := utils.TestSnowContext() validatorState := &validators.TestState{} snowCtx.ValidatorState = validatorState @@ -103,7 +103,7 @@ func TestEthTxGossip(t *testing.T) { require.NoError(err) request := &sdk.PullGossipRequest{ Filter: emptyBloomFilterBytes, - Salt: utils.RandomBytes(32), + Salt: agoUtils.RandomBytes(32), } requestBytes, err := proto.Marshal(request) @@ -161,7 +161,7 @@ func TestEthTxGossip(t *testing.T) { func TestAtomicTxGossip(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := corethUtils.TestSnowContext() + snowCtx := utils.TestSnowContext() snowCtx.AVAXAssetID = ids.GenerateTestID() snowCtx.XChainID = ids.GenerateTestID() validatorState := &validators.TestState{ @@ -231,7 +231,7 @@ func TestAtomicTxGossip(t *testing.T) { require.NoError(err) request := &sdk.PullGossipRequest{ Filter: emptyBloomFilterBytes, - Salt: utils.RandomBytes(32), + Salt: agoUtils.RandomBytes(32), } requestBytes, err := proto.Marshal(request) @@ -297,7 +297,7 @@ func TestAtomicTxGossip(t *testing.T) { func TestEthTxPushGossipOutbound(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := corethUtils.TestSnowContext() + snowCtx := utils.TestSnowContext() sender := &common.FakeSender{ SentAppGossip: make(chan []byte, 1), } @@ -354,7 +354,7 @@ func TestEthTxPushGossipOutbound(t *testing.T) { func TestEthTxPushGossipInbound(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := corethUtils.TestSnowContext() + snowCtx := utils.TestSnowContext() sender := &common.FakeSender{ SentAppGossip: make(chan []byte, 1), @@ -423,7 +423,7 @@ func TestEthTxPushGossipInbound(t *testing.T) { func TestAtomicTxPushGossipOutbound(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := corethUtils.TestSnowContext() + snowCtx := utils.TestSnowContext() snowCtx.AVAXAssetID = ids.GenerateTestID() snowCtx.XChainID = ids.GenerateTestID() validatorState := &validators.TestState{ @@ -496,7 +496,7 @@ func TestAtomicTxPushGossipOutbound(t *testing.T) { func TestAtomicTxPushGossipInbound(t *testing.T) { require := require.New(t) ctx := context.Background() - snowCtx := corethUtils.TestSnowContext() + snowCtx := utils.TestSnowContext() snowCtx.AVAXAssetID = ids.GenerateTestID() snowCtx.XChainID = ids.GenerateTestID() validatorState := &validators.TestState{ diff --git a/precompile/contracts/warp/contract_test.go b/precompile/contracts/warp/contract_test.go index c45f7a5946..0267a01157 100644 --- a/precompile/contracts/warp/contract_test.go +++ b/precompile/contracts/warp/contract_test.go @@ -9,16 +9,17 @@ import ( "testing" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/utils" + agoUtils "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/platformvm/warp" avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload" + "github.com/ava-labs/coreth/core/state" "github.com/ava-labs/coreth/precompile/contract" "github.com/ava-labs/coreth/precompile/testutils" "github.com/ava-labs/coreth/predicate" - corethUtils "github.com/ava-labs/coreth/utils" + "github.com/ava-labs/coreth/utils" "github.com/ava-labs/coreth/vmerrs" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" @@ -27,7 +28,7 @@ import ( func TestGetBlockchainID(t *testing.T) { callerAddr := common.HexToAddress("0x0123") - defaultSnowCtx := corethUtils.TestSnowContext() + defaultSnowCtx := utils.TestSnowContext() blockchainID := defaultSnowCtx.ChainID tests := map[string]testutils.PrecompileTest{ @@ -85,9 +86,9 @@ func TestGetBlockchainID(t *testing.T) { func TestSendWarpMessage(t *testing.T) { callerAddr := common.HexToAddress("0x0123") - defaultSnowCtx := corethUtils.TestSnowContext() + defaultSnowCtx := utils.TestSnowContext() blockchainID := defaultSnowCtx.ChainID - sendWarpMessagePayload := utils.RandomBytes(100) + sendWarpMessagePayload := agoUtils.RandomBytes(100) sendWarpMessageInput, err := PackSendWarpMessage(sendWarpMessagePayload) require.NoError(t, err) diff --git a/precompile/contracts/warp/predicate_test.go b/precompile/contracts/warp/predicate_test.go index 88df1c534e..aaa9859b07 100644 --- a/precompile/contracts/warp/predicate_test.go +++ b/precompile/contracts/warp/predicate_test.go @@ -13,7 +13,7 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/validators" - "github.com/ava-labs/avalanchego/utils" + agoUtils "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/set" @@ -23,7 +23,7 @@ import ( "github.com/ava-labs/coreth/precompile/precompileconfig" "github.com/ava-labs/coreth/precompile/testutils" "github.com/ava-labs/coreth/predicate" - corethUtils "github.com/ava-labs/coreth/utils" + "github.com/ava-labs/coreth/utils" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" @@ -32,7 +32,7 @@ import ( const pChainHeight uint64 = 1337 var ( - _ utils.Sortable[*testValidator] = (*testValidator)(nil) + _ agoUtils.Sortable[*testValidator] = (*testValidator)(nil) errTest = errors.New("non-nil error") networkID = uint32(54321) @@ -60,7 +60,7 @@ func init() { for i := 0; i < numTestVdrs; i++ { testVdrs = append(testVdrs, newTestValidator()) } - utils.Sort(testVdrs) + agoUtils.Sort(testVdrs) vdrs = map[ids.NodeID]*validators.GetValidatorOutput{ testVdrs[0].nodeID: { @@ -198,7 +198,7 @@ func createSnowCtx(validatorRanges []validatorRange) *snow.Context { } } - snowCtx := corethUtils.TestSnowContext() + snowCtx := utils.TestSnowContext() state := &validators.TestState{ GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) { return sourceSubnetID, nil @@ -214,7 +214,7 @@ func createSnowCtx(validatorRanges []validatorRange) *snow.Context { func createValidPredicateTest(snowCtx *snow.Context, numKeys uint64, predicateBytes []byte) testutils.PredicateTest { return testutils.PredicateTest{ - Config: NewDefaultConfig(corethUtils.NewUint64(0)), + Config: NewDefaultConfig(utils.NewUint64(0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -232,7 +232,7 @@ func TestWarpMessageFromPrimaryNetwork(t *testing.T) { require := require.New(t) numKeys := 10 cChainID := ids.GenerateTestID() - addressedCall, err := payload.NewAddressedCall(utils.RandomBytes(20), utils.RandomBytes(100)) + addressedCall, err := payload.NewAddressedCall(agoUtils.RandomBytes(20), agoUtils.RandomBytes(100)) require.NoError(err) unsignedMsg, err := avalancheWarp.NewUnsignedMessage(networkID, cChainID, addressedCall.Bytes()) require.NoError(err) @@ -263,7 +263,7 @@ func TestWarpMessageFromPrimaryNetwork(t *testing.T) { predicateBytes := predicate.PackPredicate(warpMsg.Bytes()) - snowCtx := corethUtils.TestSnowContext() + snowCtx := utils.TestSnowContext() snowCtx.SubnetID = ids.GenerateTestID() snowCtx.ChainID = ids.GenerateTestID() snowCtx.CChainID = cChainID @@ -280,7 +280,7 @@ func TestWarpMessageFromPrimaryNetwork(t *testing.T) { } test := testutils.PredicateTest{ - Config: NewDefaultConfig(corethUtils.NewUint64(0)), + Config: NewDefaultConfig(utils.NewUint64(0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -310,7 +310,7 @@ func TestInvalidPredicatePacking(t *testing.T) { predicateBytes = append(predicateBytes, byte(0x01)) // Invalidate the predicate byte packing test := testutils.PredicateTest{ - Config: NewDefaultConfig(corethUtils.NewUint64(0)), + Config: NewDefaultConfig(utils.NewUint64(0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -341,7 +341,7 @@ func TestInvalidWarpMessage(t *testing.T) { predicateBytes := predicate.PackPredicate(warpMsgBytes) test := testutils.PredicateTest{ - Config: NewDefaultConfig(corethUtils.NewUint64(0)), + Config: NewDefaultConfig(utils.NewUint64(0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -386,7 +386,7 @@ func TestInvalidAddressedPayload(t *testing.T) { predicateBytes := predicate.PackPredicate(warpMsgBytes) test := testutils.PredicateTest{ - Config: NewDefaultConfig(corethUtils.NewUint64(0)), + Config: NewDefaultConfig(utils.NewUint64(0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -402,7 +402,7 @@ func TestInvalidAddressedPayload(t *testing.T) { } func TestInvalidBitSet(t *testing.T) { - addressedCall, err := payload.NewAddressedCall(utils.RandomBytes(20), utils.RandomBytes(100)) + addressedCall, err := payload.NewAddressedCall(agoUtils.RandomBytes(20), agoUtils.RandomBytes(100)) require.NoError(t, err) unsignedMsg, err := avalancheWarp.NewUnsignedMessage( networkID, @@ -431,7 +431,7 @@ func TestInvalidBitSet(t *testing.T) { }) predicateBytes := predicate.PackPredicate(msg.Bytes()) test := testutils.PredicateTest{ - Config: NewDefaultConfig(corethUtils.NewUint64(0)), + Config: NewDefaultConfig(utils.NewUint64(0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -477,7 +477,7 @@ func TestWarpSignatureWeightsDefaultQuorumNumerator(t *testing.T) { expectedPredicateResults.Add(0) } tests[fmt.Sprintf("default quorum %d signature(s)", numSigners)] = testutils.PredicateTest{ - Config: NewDefaultConfig(corethUtils.NewUint64(0)), + Config: NewDefaultConfig(utils.NewUint64(0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -532,7 +532,7 @@ func TestWarpMultiplePredicates(t *testing.T) { } tests[fmt.Sprintf("multiple predicates %v", validMessageIndices)] = testutils.PredicateTest{ - Config: NewDefaultConfig(corethUtils.NewUint64(0)), + Config: NewDefaultConfig(utils.NewUint64(0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -575,7 +575,7 @@ func TestWarpSignatureWeightsNonDefaultQuorumNumerator(t *testing.T) { } name := fmt.Sprintf("non-default quorum %d signature(s)", numSigners) tests[name] = testutils.PredicateTest{ - Config: NewConfig(corethUtils.NewUint64(0), uint64(nonDefaultQuorumNumerator)), + Config: NewConfig(utils.NewUint64(0), uint64(nonDefaultQuorumNumerator)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -664,7 +664,7 @@ func initWarpPredicateTests() { } } - snowCtx := corethUtils.TestSnowContext() + snowCtx := utils.TestSnowContext() snowCtx.NetworkID = networkID state := &validators.TestState{ GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) {