Skip to content

Commit

Permalink
ACP 118 reference implementation (#3218)
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-schultz authored Jul 26, 2024
1 parent 553179e commit 321e727
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 17 deletions.
8 changes: 8 additions & 0 deletions network/p2p/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import (
"github.com/ava-labs/avalanchego/utils/logging"
)

// Standardized identifiers for application protocol handlers
const (
TxGossipHandlerID = iota
AtomicTxGossipHandlerID
// SignatureRequestHandlerID is specified in ACP-118: https://github.com/avalanche-foundation/ACPs/tree/main/ACPs/118-warp-signature-request
SignatureRequestHandlerID
)

var (
_ Handler = (*NoOpHandler)(nil)
_ Handler = (*TestHandler)(nil)
Expand Down
159 changes: 152 additions & 7 deletions proto/pb/sdk/sdk.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions proto/sdk/sdk.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,21 @@ message PullGossipResponse {
message PushGossip {
repeated bytes gossip = 1;
}

// SignatureRequest is an AppRequest message type for requesting
// a BLS signature over a Warp message, as defined in ACP-118:
// https://github.com/avalanche-foundation/ACPs/tree/main/ACPs/118-warp-signature-request
message SignatureRequest {
// Warp message to be signed
bytes message = 1;
// Justification for the message
bytes justification = 2;
}

// SignatureRespnose is an AppResponse message type for providing
// a requested BLS signature over a Warp message, as defined in ACP-118:
// https://github.com/avalanche-foundation/ACPs/tree/main/ACPs/118-warp-signature-request
message SignatureResponse {
// BLS signature over the Warp message
bytes signature = 1;
}
6 changes: 2 additions & 4 deletions vms/avm/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"github.com/ava-labs/avalanchego/vms/avm/txs/mempool"
)

const txGossipHandlerID = 0

var (
_ common.AppHandler = (*Network)(nil)
_ validators.Connector = (*Network)(nil)
Expand Down Expand Up @@ -68,7 +66,7 @@ func New(
config.MaxValidatorSetStaleness,
)
txGossipClient := p2pNetwork.NewClient(
txGossipHandlerID,
p2p.TxGossipHandlerID,
p2p.WithValidatorSampling(validators),
)
txGossipMetrics, err := gossip.NewMetrics(registerer, "tx")
Expand Down Expand Up @@ -157,7 +155,7 @@ func New(
appRequestHandler: validatorHandler,
}

if err := p2pNetwork.AddHandler(txGossipHandlerID, txGossipHandler); err != nil {
if err := p2pNetwork.AddHandler(p2p.TxGossipHandlerID, txGossipHandler); err != nil {
return nil, err
}

Expand Down
6 changes: 2 additions & 4 deletions vms/platformvm/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool"
)

const TxGossipHandlerID = 0

var errMempoolDisabledWithPartialSync = errors.New("mempool is disabled partial syncing")

type Network struct {
Expand Down Expand Up @@ -66,7 +64,7 @@ func New(
config.MaxValidatorSetStaleness,
)
txGossipClient := p2pNetwork.NewClient(
TxGossipHandlerID,
p2p.TxGossipHandlerID,
p2p.WithValidatorSampling(validators),
)
txGossipMetrics, err := gossip.NewMetrics(registerer, "tx")
Expand Down Expand Up @@ -154,7 +152,7 @@ func New(
appRequestHandler: validatorHandler,
}

if err := p2pNetwork.AddHandler(TxGossipHandlerID, txGossipHandler); err != nil {
if err := p2pNetwork.AddHandler(p2p.TxGossipHandlerID, txGossipHandler); err != nil {
return nil, err
}

Expand Down
3 changes: 1 addition & 2 deletions vms/platformvm/vm_regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/block"
"github.com/ava-labs/avalanchego/vms/platformvm/config"
"github.com/ava-labs/avalanchego/vms/platformvm/metrics"
"github.com/ava-labs/avalanchego/vms/platformvm/network"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
"github.com/ava-labs/avalanchego/vms/platformvm/state"
Expand Down Expand Up @@ -2441,7 +2440,7 @@ func TestValidatorSetRaceCondition(t *testing.T) {
require.NoError(err)

appRequestBytes := p2p.PrefixMessage(
p2p.ProtocolPrefix(network.TxGossipHandlerID),
p2p.ProtocolPrefix(p2p.TxGossipHandlerID),
protocolAppRequestBytest,
)

Expand Down

0 comments on commit 321e727

Please sign in to comment.