Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Oct 7, 2024
2 parents 5dcea34 + bc87fcb commit a6fcb1f
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 138 deletions.
4 changes: 1 addition & 3 deletions tests/fixture/bootstrapmonitor/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion wallet/subnet/primary/examples/convert-subnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {
uri := "http://localhost:9700"
kc := secp256k1fx.NewKeychain(key)
subnetID := ids.FromStringOrPanic("2DeHa7Qb6sufPkmQcFWG2uCd4pBPv9WB6dkzroiMQhd1NSRtof")
chainID := ids.FromStringOrPanic("2BMFrJ9xeh5JdwZEx6uuFcjfZC2SV2hdbMT8ee5HrvjtfJb5br")
chainID := ids.FromStringOrPanic("4R1dLAnG45P3rbdJB2dWuKdVRZF3dLMKgfJ8J6wKSQvYFVUhb")
addressHex := ""
weight := units.Schmeckle

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main

import (
"context"
"encoding/json"
"log"
"net/netip"
"time"
Expand All @@ -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"
Expand All @@ -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, &registerSubnetValidator)
if err != nil {
log.Fatalf("failed to unmarshal RegisterSubnetValidator message: %s\n", err)
}
err = warpmessage.Initialize(&registerSubnetValidator)
if err != nil {
log.Fatalf("failed to initialize RegisterSubnetValidator message: %s\n", err)
}

validationID := registerSubnetValidator.ValidationID()
subnetValidatorRegistration, err := warpmessage.NewSubnetValidatorRegistration(
validationID,
true,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading

0 comments on commit a6fcb1f

Please sign in to comment.