-
Notifications
You must be signed in to change notification settings - Fork 273
Uptime validation nits #1378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ceyonur
merged 9 commits into
sign-validator-uptime-warp-msg
from
uptime-validation-nits
Nov 6, 2024
Merged
Uptime validation nits #1378
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f0bccd9
add uptime warp example
ceyonur b3bb884
remove log
ceyonur 6d19703
nit unused interface
ceyonur ecf312d
add weight and isSov as fields
ceyonur 0b34a6d
use validator struct in AddValidator
ceyonur 7c6a1f4
add comments to example file
ceyonur 42c7c46
Merge branch 'sign-validator-uptime-warp-msg' into uptime-validation-…
ceyonur 0bff184
fix test
ceyonur f4c1f37
add new fields to tests
ceyonur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// 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/sdk" | ||
"github.com/ava-labs/avalanchego/snow/networking/router" | ||
"github.com/ava-labs/avalanchego/utils/compression" | ||
"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" | ||
"github.com/ava-labs/subnet-evm/warp/messages" | ||
|
||
p2pmessage "github.com/ava-labs/avalanchego/message" | ||
) | ||
|
||
func main() { | ||
uri := primary.LocalAPIURI | ||
// The following IDs are placeholders and should be replaced with real values | ||
// before running the code. | ||
// The validationID is for the validation period that the uptime message is signed for. | ||
validationID := ids.FromStringOrPanic("p3NUAY4PbcAnyCyvUTjGVjezNEQCdnVdfAbJcZScvKpxP5tJr") | ||
darioush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// The sourceChainID is the ID of the chain. | ||
sourceChainID := ids.FromStringOrPanic("2UZWB4xjNadRcHSpXarQoCryiVdcGWoT5w1dUztNfMKkAd2hJX") | ||
reqUptime := uint64(3486) | ||
infoClient := info.NewClient(uri) | ||
networkID, err := infoClient.GetNetworkID(context.Background()) | ||
if err != nil { | ||
log.Fatalf("failed to fetch network ID: %s\n", err) | ||
} | ||
|
||
validatorUptime, err := messages.NewValidatorUptime(validationID, reqUptime) | ||
if err != nil { | ||
log.Fatalf("failed to create validatorUptime message: %s\n", err) | ||
} | ||
|
||
addressedCall, err := payload.NewAddressedCall( | ||
nil, | ||
validatorUptime.Bytes(), | ||
) | ||
if err != nil { | ||
log.Fatalf("failed to create AddressedCall message: %s\n", err) | ||
} | ||
|
||
unsignedWarp, err := warp.NewUnsignedMessage( | ||
networkID, | ||
sourceChainID, | ||
addressedCall.Bytes(), | ||
) | ||
if err != nil { | ||
log.Fatalf("failed to create unsigned Warp message: %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(), | ||
}) | ||
if err != nil { | ||
log.Fatalf("failed to marshal SignatureRequest: %s\n", err) | ||
} | ||
|
||
appRequest, err := messageBuilder.AppRequest( | ||
sourceChainID, | ||
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) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.