Skip to content
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

ACP-77: Allow xsvm to sign arbitrary warp messages #3448

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions vms/example/xsvm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import (
"net/http"

"github.com/gorilla/rpc/v2"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/versiondb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/network/p2p"
"github.com/ava-labs/avalanchego/network/p2p/acp118"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/consensus/snowman"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/json"
"github.com/ava-labs/avalanchego/version"
"github.com/ava-labs/avalanchego/vms/example/xsvm/api"
"github.com/ava-labs/avalanchego/vms/example/xsvm/builder"
"github.com/ava-labs/avalanchego/vms/example/xsvm/chain"
Expand All @@ -37,7 +39,7 @@ var (
)

type VM struct {
common.AppHandler
*p2p.Network

chainContext *snow.Context
db database.Database
Expand All @@ -57,14 +59,38 @@ func (vm *VM) Initialize(
_ []byte,
engineChan chan<- common.Message,
_ []*common.Fx,
_ common.AppSender,
appSender common.AppSender,
) error {
vm.AppHandler = common.NewNoOpAppHandler(chainContext.Log)

chainContext.Log.Info("initializing xsvm",
zap.Stringer("version", Version),
)

metrics := prometheus.NewRegistry()
err := chainContext.Metrics.Register("p2p", metrics)
if err != nil {
return err
}

vm.Network, err = p2p.NewNetwork(
chainContext.Log,
appSender,
metrics,
"",
)
if err != nil {
return err
}

// Allow signing of all warp messages. This is not typically safe, but is
// allowed for this example.
acp118Handler := acp118.NewHandler(
acp118Verifier{},
chainContext.WarpSigner,
)
if err := vm.Network.AddHandler(p2p.SignatureRequestHandlerID, acp118Handler); err != nil {
return err
}

vm.chainContext = chainContext
vm.db = db
g, err := genesis.Parse(genesisBytes)
Expand Down Expand Up @@ -132,14 +158,6 @@ func (*VM) HealthCheck(context.Context) (interface{}, error) {
return http.StatusOK, nil
}

func (*VM) Connected(context.Context, ids.NodeID, *version.Application) error {
return nil
}

func (*VM) Disconnected(context.Context, ids.NodeID) error {
return nil
}

func (vm *VM) GetBlock(_ context.Context, blkID ids.ID) (snowman.Block, error) {
return vm.chain.GetBlock(blkID)
}
Expand Down
21 changes: 21 additions & 0 deletions vms/example/xsvm/warp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package xsvm

import (
"context"

"github.com/ava-labs/avalanchego/network/p2p/acp118"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
)

var _ acp118.Verifier = (*acp118Verifier)(nil)

// acp118Verifier allows signing all warp messages
type acp118Verifier struct{}
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved

func (acp118Verifier) Verify(context.Context, *warp.UnsignedMessage, []byte) *common.AppError {
return nil
}
Loading