-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sign validator uptime warp msg (#1367)
* Bump avalanchego to master * always sign uptime messages (testing branch) * nits * cleanup * assign to correct `err` * fix handler * move ValidatorUptime type to subnet-evm * disable always signing * implement on the type itself * remove unneeded code * fix ut * add validator state * add pausable uptime manager * remove stuttering name * rename state listener * add uptime tracking to VM * remove unused param * add wg for update validators * update state before network shutdown * restart bootstrapping status in test * add get validator to state * rename uptime to validator * fix mock state * tests * Update plugin/evm/validators/state.go Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org> Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com> * use update enum * Update plugin/evm/validators/state.go Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org> Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com> * Update plugin/evm/validators/state.go Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org> Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com> * respond to comments * update avalanchego dep branch * reviews * reword errs * fix test changes * fix upgrades after deactivating latest in context * use test branch from avalanchego * use branch commit for ava version * update e2e ava version * update avago dep * remove extra line... * export struct * implement acp118 signer and verifier * avoid revalidating in sign * refactor warp backend to use acp118 handler * prune warp db before backend init * add cache tests * remove uptime msg type * add cache test * fix linter * add validator uptimes * bump avago getcurrentvalidators branch * rename get validator IDs to NodeIDs * sign uptime warp msg base on uptime calculator * add tests * reviews * conflict fix * custom err msg * add listener mock * bump avago test branch * remove config * remove api changes * Revert "remove api changes" This reverts commit 8ef763f. * remove wrapped cache * use non-version db for validatorsDB * remove errs from resume and pause * check after stopping * use expectedTime in tests * reviews * Update plugin/evm/vm.go Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org> Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com> * fix len * fix tests * update avago branch * use ctx from utils * add empty check for source address * nits * remove log * disable validators api by default * fix test context * use interfaces from pkgs * improve comments * Uptime validation nits (#1378) * add uptime warp example * remove log * nit unused interface * add weight and isSov as fields * use validator struct in AddValidator * add comments to example file * fix test * add new fields to tests --------- Signed-off-by: Ceyhun Onur <ceyhun.onur@avalabs.org> * Update plugin/evm/validators/state.go Co-authored-by: Michael Kaplan <55204436+michaelkaplan13@users.noreply.github.com> Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com> * pass locker * rename addresscall verifier fn * new fields and refactorings * add new fields * merge nits * fix linter * clarify comments * update comment * remove getnodeID * bump to poc branch * enable validators API by default * reviews * reviews * update comment * update to avago master * revert test change --------- Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com> Signed-off-by: Ceyhun Onur <ceyhun.onur@avalabs.org> Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org> Co-authored-by: Michael Kaplan <55204436+michaelkaplan13@users.noreply.github.com>
- Loading branch information
1 parent
fb40c50
commit f1d549c
Showing
11 changed files
with
428 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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,124 @@ | ||
// 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" | ||
) | ||
|
||
// An example application demonstrating how to request a signature for | ||
// an uptime message from a node running locally. | ||
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") | ||
// 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 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,64 @@ | ||
package validatorstest | ||
|
||
import ( | ||
"time" | ||
|
||
ids "github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/utils/set" | ||
"github.com/ava-labs/subnet-evm/plugin/evm/validators/interfaces" | ||
) | ||
|
||
var NoOpState interfaces.State = &noOpState{} | ||
|
||
type noOpState struct{} | ||
|
||
func (n *noOpState) GetStatus(vID ids.ID) (bool, error) { return false, nil } | ||
|
||
func (n *noOpState) GetValidationIDs() set.Set[ids.ID] { return set.NewSet[ids.ID](0) } | ||
|
||
func (n *noOpState) GetNodeIDs() set.Set[ids.NodeID] { return set.NewSet[ids.NodeID](0) } | ||
|
||
func (n *noOpState) GetValidator(vID ids.ID) (interfaces.Validator, error) { | ||
return interfaces.Validator{}, nil | ||
} | ||
|
||
func (n *noOpState) GetNodeID(vID ids.ID) (ids.NodeID, error) { return ids.NodeID{}, nil } | ||
|
||
func (n *noOpState) AddValidator(vdr interfaces.Validator) error { | ||
return nil | ||
} | ||
|
||
func (n *noOpState) UpdateValidator(vdr interfaces.Validator) error { | ||
return nil | ||
} | ||
|
||
func (n *noOpState) DeleteValidator(vID ids.ID) error { | ||
return nil | ||
} | ||
func (n *noOpState) WriteState() error { return nil } | ||
|
||
func (n *noOpState) SetStatus(vID ids.ID, isActive bool) error { return nil } | ||
|
||
func (n *noOpState) SetWeight(vID ids.ID, newWeight uint64) error { return nil } | ||
|
||
func (n *noOpState) RegisterListener(interfaces.StateCallbackListener) {} | ||
|
||
func (n *noOpState) GetUptime( | ||
nodeID ids.NodeID, | ||
) (upDuration time.Duration, lastUpdated time.Time, err error) { | ||
return 0, time.Time{}, nil | ||
} | ||
|
||
func (n *noOpState) SetUptime( | ||
nodeID ids.NodeID, | ||
upDuration time.Duration, | ||
lastUpdated time.Time, | ||
) error { | ||
return nil | ||
} | ||
|
||
func (n *noOpState) GetStartTime( | ||
nodeID ids.NodeID, | ||
) (startTime time.Time, err error) { | ||
return time.Time{}, nil | ||
} |
This file contains 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 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 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 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 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 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.