From 43d5b435a644cc8060eb8a7cb134fed063fadeed Mon Sep 17 00:00:00 2001 From: marun Date: Thu, 3 Oct 2024 15:09:30 -0700 Subject: [PATCH 1/2] [testing] Fix bootstrap monitor e2e image build error check (#3443) --- tests/fixture/bootstrapmonitor/e2e/e2e_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/fixture/bootstrapmonitor/e2e/e2e_test.go b/tests/fixture/bootstrapmonitor/e2e/e2e_test.go index 3ed7ebd6b60e..2f5a319fc02d 100644 --- a/tests/fixture/bootstrapmonitor/e2e/e2e_test.go +++ b/tests/fixture/bootstrapmonitor/e2e/e2e_test.go @@ -251,9 +251,7 @@ func buildImage(tc tests.TestContext, imageName string, forceNewHash bool, scrip "SKIP_BUILD_RACE=1", ) output, err := cmd.CombinedOutput() - if err != nil { - require.FailNow("Image build failed: %v\nWith output: %s", err, output) - } + require.NoError(err, "Image build failed: %s", output) } // newNodeStatefulSet returns a statefulset for an avalanchego node. From 5533b8c657de2253046407394b08909bc9970933 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Mon, 7 Oct 2024 16:08:31 -0400 Subject: [PATCH 2/2] Update examples --- .../primary/examples/convert-subnet/main.go | 2 +- .../register-subnet-validator/main.go | 2 +- .../set-subnet-validator-weight/main.go | 6 +- .../examples/sign-subnet-conversion/main.go | 2 +- .../main.go | 86 +---------- .../main.go | 137 ++++++++++++++++++ .../main.go | 107 ++++++++------ 7 files changed, 207 insertions(+), 135 deletions(-) create mode 100644 wallet/subnet/primary/examples/sign-subnet-validator-removal-genesis/main.go rename wallet/subnet/primary/examples/{sign-subnet-validator-removal => sign-subnet-validator-removal-registration}/main.go (73%) diff --git a/wallet/subnet/primary/examples/convert-subnet/main.go b/wallet/subnet/primary/examples/convert-subnet/main.go index b7133488f6ef..c306aca3549d 100644 --- a/wallet/subnet/primary/examples/convert-subnet/main.go +++ b/wallet/subnet/primary/examples/convert-subnet/main.go @@ -24,7 +24,7 @@ func main() { uri := "http://localhost:9700" kc := secp256k1fx.NewKeychain(key) subnetID := ids.FromStringOrPanic("2DeHa7Qb6sufPkmQcFWG2uCd4pBPv9WB6dkzroiMQhd1NSRtof") - chainID := ids.FromStringOrPanic("E8nTR9TtRwfkS7XFjTYUYHENQ91mkPMtDUwwCeu7rNgBBtkqu") + chainID := ids.FromStringOrPanic("4R1dLAnG45P3rbdJB2dWuKdVRZF3dLMKgfJ8J6wKSQvYFVUhb") addressHex := "" weight := units.Schmeckle diff --git a/wallet/subnet/primary/examples/register-subnet-validator/main.go b/wallet/subnet/primary/examples/register-subnet-validator/main.go index 05d51aa1719b..b0d1b0a2c653 100644 --- a/wallet/subnet/primary/examples/register-subnet-validator/main.go +++ b/wallet/subnet/primary/examples/register-subnet-validator/main.go @@ -29,7 +29,7 @@ func main() { uri := "http://localhost:9710" kc := secp256k1fx.NewKeychain(key) subnetID := ids.FromStringOrPanic("2DeHa7Qb6sufPkmQcFWG2uCd4pBPv9WB6dkzroiMQhd1NSRtof") - chainID := ids.FromStringOrPanic("2BMFrJ9xeh5JdwZEx6uuFcjfZC2SV2hdbMT8ee5HrvjtfJb5br") + chainID := ids.FromStringOrPanic("4R1dLAnG45P3rbdJB2dWuKdVRZF3dLMKgfJ8J6wKSQvYFVUhb") addressHex := "" weight := uint64(1) diff --git a/wallet/subnet/primary/examples/set-subnet-validator-weight/main.go b/wallet/subnet/primary/examples/set-subnet-validator-weight/main.go index 35e7ce264104..aacf99ba1f9e 100644 --- a/wallet/subnet/primary/examples/set-subnet-validator-weight/main.go +++ b/wallet/subnet/primary/examples/set-subnet-validator-weight/main.go @@ -26,11 +26,11 @@ func main() { key := genesis.EWOQKey uri := primary.LocalAPIURI kc := secp256k1fx.NewKeychain(key) - chainID := ids.FromStringOrPanic("2BMFrJ9xeh5JdwZEx6uuFcjfZC2SV2hdbMT8ee5HrvjtfJb5br") + chainID := ids.FromStringOrPanic("4R1dLAnG45P3rbdJB2dWuKdVRZF3dLMKgfJ8J6wKSQvYFVUhb") addressHex := "" - validationID := ids.FromStringOrPanic("2Y3ZZZXxpzm46geqVuqFXeSFVbeKihgrfeXRDaiF4ds6R2N8M5") + validationID := ids.FromStringOrPanic("9FAftNgNBrzHUMMApsSyV6RcFiL9UmCbvsCu28xdLV2mQ7CMo") nonce := uint64(1) - weight := uint64(2) + weight := uint64(0) address, err := hex.DecodeString(addressHex) if err != nil { diff --git a/wallet/subnet/primary/examples/sign-subnet-conversion/main.go b/wallet/subnet/primary/examples/sign-subnet-conversion/main.go index 87f159855853..1d3fdd7a47de 100644 --- a/wallet/subnet/primary/examples/sign-subnet-conversion/main.go +++ b/wallet/subnet/primary/examples/sign-subnet-conversion/main.go @@ -32,7 +32,7 @@ import ( func main() { uri := primary.LocalAPIURI subnetID := ids.FromStringOrPanic("2DeHa7Qb6sufPkmQcFWG2uCd4pBPv9WB6dkzroiMQhd1NSRtof") - conversionID := ids.FromStringOrPanic("d84X4xQeXkAhnLQi2BqDyG6AEGbdJVGJCwx6a4c3UnBhD9vpZ") + conversionID := ids.FromStringOrPanic("28tfqwucuoH7oWxmVYDVQ2C1ehdYecF5mzwNmX2t1dTu1S5vHE") infoClient := info.NewClient(uri) networkID, err := infoClient.GetNetworkID(context.Background()) if err != nil { diff --git a/wallet/subnet/primary/examples/sign-subnet-validator-registration/main.go b/wallet/subnet/primary/examples/sign-subnet-validator-registration/main.go index 6506d2477c2c..71524515ab9e 100644 --- a/wallet/subnet/primary/examples/sign-subnet-validator-registration/main.go +++ b/wallet/subnet/primary/examples/sign-subnet-validator-registration/main.go @@ -5,7 +5,6 @@ package main import ( "context" - "encoding/json" "log" "net/netip" "time" @@ -14,6 +13,7 @@ import ( "google.golang.org/protobuf/proto" "github.com/ava-labs/avalanchego/api/info" + "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/network/p2p" "github.com/ava-labs/avalanchego/network/peer" "github.com/ava-labs/avalanchego/proto/pb/sdk" @@ -29,90 +29,15 @@ import ( warpmessage "github.com/ava-labs/avalanchego/vms/platformvm/warp/message" ) -var registerSubnetValidatorJSON = []byte(`{ - "subnetID": "2DeHa7Qb6sufPkmQcFWG2uCd4pBPv9WB6dkzroiMQhd1NSRtof", - "nodeID": "0xb628ee3952a5de80fadd31ab030a67189edb1410", - "blsPublicKey": [ - 143, - 167, - 255, - 128, - 221, - 92, - 126, - 190, - 134, - 189, - 157, - 166, - 6, - 55, - 92, - 125, - 223, - 231, - 71, - 85, - 122, - 110, - 110, - 49, - 215, - 14, - 1, - 226, - 146, - 140, - 73, - 75, - 113, - 163, - 138, - 158, - 34, - 207, - 99, - 36, - 137, - 55, - 191, - 28, - 186, - 24, - 49, - 199 - ], - "expiry": 1727975059, - "remainingBalanceOwner": { - "threshold": 0, - "addresses": null - }, - "disableOwner": { - "threshold": 0, - "addresses": null - }, - "weight": 1 -}`) - func main() { uri := primary.LocalAPIURI + validationID := ids.FromStringOrPanic("2DWCCiYb7xRTRHeKybkLY5ygRhZ1CWhtHgLuUCJBxktRnUYdCT") infoClient := info.NewClient(uri) networkID, err := infoClient.GetNetworkID(context.Background()) if err != nil { log.Fatalf("failed to fetch network ID: %s\n", err) } - var registerSubnetValidator warpmessage.RegisterSubnetValidator - err = json.Unmarshal(registerSubnetValidatorJSON, ®isterSubnetValidator) - if err != nil { - log.Fatalf("failed to unmarshal RegisterSubnetValidator message: %s\n", err) - } - err = warpmessage.Initialize(®isterSubnetValidator) - if err != nil { - log.Fatalf("failed to initialize RegisterSubnetValidator message: %s\n", err) - } - - validationID := registerSubnetValidator.ValidationID() subnetValidatorRegistration, err := warpmessage.NewSubnetValidatorRegistration( validationID, true, @@ -153,7 +78,7 @@ func main() { log.Fatalf("failed to start peer: %s\n", err) } - mesageBuilder, err := p2pmessage.NewCreator( + messageBuilder, err := p2pmessage.NewCreator( logging.NoLog{}, prometheus.NewRegistry(), compression.TypeZstd, @@ -164,14 +89,13 @@ func main() { } appRequestPayload, err := proto.Marshal(&sdk.SignatureRequest{ - Message: unsignedWarp.Bytes(), - Justification: registerSubnetValidator.Bytes(), + Message: unsignedWarp.Bytes(), }) if err != nil { log.Fatalf("failed to marshal SignatureRequest: %s\n", err) } - appRequest, err := mesageBuilder.AppRequest( + appRequest, err := messageBuilder.AppRequest( constants.PlatformChainID, 0, time.Hour, diff --git a/wallet/subnet/primary/examples/sign-subnet-validator-removal-genesis/main.go b/wallet/subnet/primary/examples/sign-subnet-validator-removal-genesis/main.go new file mode 100644 index 000000000000..7b4eb57e0d69 --- /dev/null +++ b/wallet/subnet/primary/examples/sign-subnet-validator-removal-genesis/main.go @@ -0,0 +1,137 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package main + +import ( + "context" + "log" + "net/netip" + "time" + + "github.com/prometheus/client_golang/prometheus" + "google.golang.org/protobuf/proto" + + "github.com/ava-labs/avalanchego/api/info" + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/network/p2p" + "github.com/ava-labs/avalanchego/network/peer" + "github.com/ava-labs/avalanchego/proto/pb/platformvm" + "github.com/ava-labs/avalanchego/proto/pb/sdk" + "github.com/ava-labs/avalanchego/snow/networking/router" + "github.com/ava-labs/avalanchego/utils/compression" + "github.com/ava-labs/avalanchego/utils/constants" + "github.com/ava-labs/avalanchego/utils/logging" + "github.com/ava-labs/avalanchego/vms/platformvm/warp" + "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload" + "github.com/ava-labs/avalanchego/wallet/subnet/primary" + + p2pmessage "github.com/ava-labs/avalanchego/message" + warpmessage "github.com/ava-labs/avalanchego/vms/platformvm/warp/message" +) + +func main() { + uri := primary.LocalAPIURI + subnetID := ids.FromStringOrPanic("2DeHa7Qb6sufPkmQcFWG2uCd4pBPv9WB6dkzroiMQhd1NSRtof") + validationIndex := uint32(0) + infoClient := info.NewClient(uri) + networkID, err := infoClient.GetNetworkID(context.Background()) + if err != nil { + log.Fatalf("failed to fetch network ID: %s\n", err) + } + + validationID := subnetID.Append(validationIndex) + subnetValidatorRegistration, err := warpmessage.NewSubnetValidatorRegistration( + validationID, + false, + ) + if err != nil { + log.Fatalf("failed to create SubnetValidatorRegistration message: %s\n", err) + } + + addressedCall, err := payload.NewAddressedCall( + nil, + subnetValidatorRegistration.Bytes(), + ) + if err != nil { + log.Fatalf("failed to create AddressedCall message: %s\n", err) + } + + unsignedWarp, err := warp.NewUnsignedMessage( + networkID, + constants.PlatformChainID, + addressedCall.Bytes(), + ) + if err != nil { + log.Fatalf("failed to create unsigned Warp message: %s\n", err) + } + + justification := platformvm.SubnetValidatorRegistrationJustification{ + Preimage: &platformvm.SubnetValidatorRegistrationJustification_ConvertSubnetTxData{ + ConvertSubnetTxData: &platformvm.SubnetIDIndex{ + SubnetId: subnetID[:], + Index: validationIndex, + }, + }, + } + justificationBytes, err := proto.Marshal(&justification) + if err != nil { + log.Fatalf("failed to create justification: %s\n", err) + } + + p, err := peer.StartTestPeer( + context.Background(), + netip.AddrPortFrom( + netip.AddrFrom4([4]byte{127, 0, 0, 1}), + 9651, + ), + networkID, + router.InboundHandlerFunc(func(_ context.Context, msg p2pmessage.InboundMessage) { + log.Printf("received %s: %s", msg.Op(), msg.Message()) + }), + ) + if err != nil { + log.Fatalf("failed to start peer: %s\n", err) + } + + messageBuilder, err := p2pmessage.NewCreator( + logging.NoLog{}, + prometheus.NewRegistry(), + compression.TypeZstd, + time.Hour, + ) + if err != nil { + log.Fatalf("failed to create message builder: %s\n", err) + } + + appRequestPayload, err := proto.Marshal(&sdk.SignatureRequest{ + Message: unsignedWarp.Bytes(), + Justification: justificationBytes, + }) + if err != nil { + log.Fatalf("failed to marshal SignatureRequest: %s\n", err) + } + + appRequest, err := messageBuilder.AppRequest( + constants.PlatformChainID, + 0, + time.Hour, + p2p.PrefixMessage( + p2p.ProtocolPrefix(p2p.SignatureRequestHandlerID), + appRequestPayload, + ), + ) + if err != nil { + log.Fatalf("failed to create AppRequest: %s\n", err) + } + + p.Send(context.Background(), appRequest) + + time.Sleep(5 * time.Second) + + p.StartClose() + err = p.AwaitClosed(context.Background()) + if err != nil { + log.Fatalf("failed to close peer: %s\n", err) + } +} diff --git a/wallet/subnet/primary/examples/sign-subnet-validator-removal/main.go b/wallet/subnet/primary/examples/sign-subnet-validator-removal-registration/main.go similarity index 73% rename from wallet/subnet/primary/examples/sign-subnet-validator-removal/main.go rename to wallet/subnet/primary/examples/sign-subnet-validator-removal-registration/main.go index 02ae39abef7d..aab951eadab6 100644 --- a/wallet/subnet/primary/examples/sign-subnet-validator-removal/main.go +++ b/wallet/subnet/primary/examples/sign-subnet-validator-removal-registration/main.go @@ -16,6 +16,7 @@ import ( "github.com/ava-labs/avalanchego/api/info" "github.com/ava-labs/avalanchego/network/p2p" "github.com/ava-labs/avalanchego/network/peer" + "github.com/ava-labs/avalanchego/proto/pb/platformvm" "github.com/ava-labs/avalanchego/proto/pb/sdk" "github.com/ava-labs/avalanchego/snow/networking/router" "github.com/ava-labs/avalanchego/utils/compression" @@ -31,58 +32,58 @@ import ( var registerSubnetValidatorJSON = []byte(`{ "subnetID": "2DeHa7Qb6sufPkmQcFWG2uCd4pBPv9WB6dkzroiMQhd1NSRtof", - "nodeID": "0xb628ee3952a5de80fadd31ab030a67189edb1410", + "nodeID": "0x550f3c8f2ebd89e6a69adca196bea38a1b4d65bc", "blsPublicKey": [ - 143, - 167, - 255, - 128, - 221, - 92, - 126, - 190, - 134, - 189, - 157, - 166, + 178, + 119, + 51, + 152, + 247, + 239, + 52, + 16, + 89, + 246, 6, - 55, - 92, - 125, - 223, - 231, - 71, - 85, - 122, - 110, - 110, - 49, - 215, - 14, - 1, - 226, - 146, - 140, - 73, + 11, + 76, + 81, + 114, + 139, + 141, + 251, + 127, + 202, + 205, + 177, + 62, 75, - 113, - 163, - 138, - 158, - 34, + 152, 207, - 99, - 36, - 137, - 55, - 191, - 28, - 186, - 24, - 49, - 199 + 170, + 120, + 86, + 213, + 226, + 226, + 104, + 135, + 245, + 231, + 226, + 223, + 64, + 19, + 242, + 246, + 227, + 12, + 223, + 23, + 193, + 219 ], - "expiry": 1727975059, + "expiry": 1728331617, "remainingBalanceOwner": { "threshold": 0, "addresses": null @@ -138,6 +139,16 @@ func main() { log.Fatalf("failed to create unsigned Warp message: %s\n", err) } + justification := platformvm.SubnetValidatorRegistrationJustification{ + Preimage: &platformvm.SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage{ + RegisterSubnetValidatorMessage: registerSubnetValidator.Bytes(), + }, + } + justificationBytes, err := proto.Marshal(&justification) + if err != nil { + log.Fatalf("failed to create justification: %s\n", err) + } + p, err := peer.StartTestPeer( context.Background(), netip.AddrPortFrom( @@ -165,7 +176,7 @@ func main() { appRequestPayload, err := proto.Marshal(&sdk.SignatureRequest{ Message: unsignedWarp.Bytes(), - Justification: registerSubnetValidator.Bytes(), + Justification: justificationBytes, }) if err != nil { log.Fatalf("failed to marshal SignatureRequest: %s\n", err)