mirror of
https://github.com/luxfi/node.git
synced 2026-07-27 03:39:39 +00:00
node: ZAP-native everywhere — kill every //go:build grpc path
The companion commit `7496606282` retired the gRPC fallback inside
vms/rpcchainvm/. This commit closes the loop by deleting every
remaining `//go:build grpc` file under node/, removing the dual-build
plumbing entirely. ZAP is the only wire protocol; there is no
`-tags=grpc` opt-in.
Per the "one and only one way to do everything" mandate, the
backwards-compat scaffolding (gRPC adapters, protoc stubs, connect-go
example handlers, OTLP gRPC exporter, x/sync gRPC sync engine,
keystore-over-gRPC client/server, rpcwarp gRPC signer, gRPC alias
reader) is removed forward-only — no aliases, no deprecation period.
Deletions (84 files):
- proto/pb/{aliasreader,http,io,keystore,message,messenger,net,p2p,
platformvm,rpcdb,sdk,sender,sharedmemory,signer,sync,
validatorstate,vm,warp}/ — protoc stubs (entire tree)
- proto/{p2p,platformvm,sync,vm}/*_grpc.go — gRPC type re-exports
- db/rpcdb/{grpc_server,grpc_client,grpc_test}.go — rpcdb gRPC adapter
- service/keystore/rpckeystore/ — keystore-over-gRPC (dead consumer)
- x/sync/ — entire merkledb sync engine (100% gRPC-tagged)
- internal/ids/rpcaliasreader/ — gRPC alias reader (dead consumer)
- connectproto/ — connect-go XSVM ping handler scaffolding
- vms/platformvm/warp/rpcwarp/{client,server}.go — gRPC warp signer
- vms/platformvm/network/warp.go — protobuf-based warp justification
handler (warp_zap.go retains the no-op verifier consumers expect)
- vms/components/message/message_grpc.go + message_test.go
- vms/example/xsvm/api/ping.go + vm_http_grpc.go + cmd/{run,xsvm}/
- wallet/network/primary/examples/sign-l1-validator-* (5 dead
example main packages)
- trace/{exporter_grpc,exporter_type,exporter_type_test,noop,tracer}.go
(OTLP gRPC exporter + duplicate Tracer types — trace_zap.go has
the canonical Tracer interface + no-op tracer)
- message/bft_grpc.go (Simplex BFT wrapper)
Edits (9 files): every surviving `_zap.go` drops its `//go:build !grpc`
constraint (the files are unconditional now) and drops stale
"ZAP version" / "ZAP mode" inline comments.
Doc updates:
- LLM.md ZAP Transport section: remove the `-tags=grpc` opt-in
language. Replace with "ZAP is the only wire protocol... there is
one and only one way". Update Latest Tag to v1.26.31. Update the
rpcdb topology section to reflect single-adapter state.
go.mod: connectrpc.com/connect, connectrpc.com/grpcreflect,
otlptracegrpc moved out of direct deps. google.golang.org/grpc +
protobuf demoted to indirect (still pulled transitively via luxfi/dex).
Verified:
- `go build ./...` (default, no tags) clean
- `go test ./db/rpcdb/... ./trace/... ./message/... ./vms/rpcchainvm/...
./vms/components/message/... ./vms/platformvm/network/...
./vms/example/xsvm/... ./service/keystore/... ./proto/...` clean
- `grep -rln '//go:build grpc' --include='*.go' node/` returns zero
- `grep -rln '//go:build !grpc' --include='*.go' node/` returns zero
- `grep -rln 'google.golang.org/grpc' --include='*.go' node/` returns
zero (only transitive deps remain in go.sum)
Pre-existing TestGraniteNetworkIDConfiguration failure in tests/ is
unrelated — fails on the parent commit too (verified via stash).
This commit is contained in:
@@ -1,124 +0,0 @@
|
||||
//go:build grpc
|
||||
|
||||
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/luxfi/metric"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
compression "github.com/luxfi/compress"
|
||||
"github.com/luxfi/constants"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/network/peer"
|
||||
"github.com/luxfi/node/proto/pb/sdk"
|
||||
"github.com/luxfi/node/vms/platformvm/warp"
|
||||
"github.com/luxfi/node/vms/platformvm/warp/payload"
|
||||
"github.com/luxfi/node/wallet/network/primary"
|
||||
p2psdk "github.com/luxfi/p2p"
|
||||
"github.com/luxfi/sdk/info"
|
||||
|
||||
p2pmessage "github.com/luxfi/node/message"
|
||||
warpmessage "github.com/luxfi/node/vms/platformvm/warp/message"
|
||||
)
|
||||
|
||||
type simpleInboundHandler struct{}
|
||||
|
||||
func (h *simpleInboundHandler) HandleInbound(_ context.Context, msg p2pmessage.InboundMessage) {
|
||||
log.Printf("received %s: %s", msg.Op(), msg.Message())
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
l1ValidatorRegistration, err := warpmessage.NewL1ValidatorRegistration(
|
||||
validationID,
|
||||
true,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create L1ValidatorRegistration message: %s\n", err)
|
||||
}
|
||||
|
||||
addressedCall, err := payload.NewAddressedCall(
|
||||
nil,
|
||||
l1ValidatorRegistration.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)
|
||||
}
|
||||
|
||||
p, err := peer.StartTestPeer(
|
||||
context.Background(),
|
||||
netip.AddrPortFrom(
|
||||
netip.AddrFrom4([4]byte{127, 0, 0, 1}),
|
||||
9651,
|
||||
),
|
||||
networkID,
|
||||
&simpleInboundHandler{},
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to start peer: %s\n", err)
|
||||
}
|
||||
|
||||
messageBuilder, err := p2pmessage.NewCreator(
|
||||
|
||||
metric.NewNoOpRegistry(),
|
||||
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.Request(
|
||||
constants.PlatformChainID,
|
||||
0,
|
||||
time.Hour,
|
||||
p2psdk.PrefixMessage(
|
||||
p2psdk.ProtocolPrefix(0), // SignatureRequestHandlerID placeholder
|
||||
appRequestPayload,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create Request: %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)
|
||||
}
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
//go:build grpc
|
||||
|
||||
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/luxfi/metric"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
compression "github.com/luxfi/compress"
|
||||
"github.com/luxfi/constants"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/network/peer"
|
||||
"github.com/luxfi/node/proto/platformvm"
|
||||
"github.com/luxfi/node/proto/pb/sdk"
|
||||
"github.com/luxfi/node/vms/platformvm/warp"
|
||||
"github.com/luxfi/node/vms/platformvm/warp/payload"
|
||||
"github.com/luxfi/node/wallet/network/primary"
|
||||
p2psdk "github.com/luxfi/p2p"
|
||||
"github.com/luxfi/sdk/info"
|
||||
|
||||
p2pmessage "github.com/luxfi/node/message"
|
||||
warpmessage "github.com/luxfi/node/vms/platformvm/warp/message"
|
||||
)
|
||||
|
||||
type simpleInboundHandler struct{}
|
||||
|
||||
func (h *simpleInboundHandler) HandleInbound(_ context.Context, msg p2pmessage.InboundMessage) {
|
||||
log.Printf("received %s: %s", msg.Op(), msg.Message())
|
||||
}
|
||||
|
||||
func main() {
|
||||
uri := primary.LocalAPIURI
|
||||
netID := 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 := netID.Append(validationIndex)
|
||||
l1ValidatorRegistration, err := warpmessage.NewL1ValidatorRegistration(
|
||||
validationID,
|
||||
false,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create L1ValidatorRegistration message: %s\n", err)
|
||||
}
|
||||
|
||||
addressedCall, err := payload.NewAddressedCall(
|
||||
nil,
|
||||
l1ValidatorRegistration.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.L1ValidatorRegistrationJustification{
|
||||
Preimage: &platformvm.L1ValidatorRegistrationJustification_ConvertNetworkToL1TxData{
|
||||
ConvertNetworkToL1TxData: &platformvm.ChainIDIndex{
|
||||
ChainId: netID[:],
|
||||
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,
|
||||
&simpleInboundHandler{},
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to start peer: %s\n", err)
|
||||
}
|
||||
|
||||
messageBuilder, err := p2pmessage.NewCreator(
|
||||
|
||||
metric.NewNoOpRegistry(),
|
||||
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.Request(
|
||||
constants.PlatformChainID,
|
||||
0,
|
||||
time.Hour,
|
||||
p2psdk.PrefixMessage(
|
||||
p2psdk.ProtocolPrefix(0), // SignatureRequestHandlerID placeholder
|
||||
appRequestPayload,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create Request: %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)
|
||||
}
|
||||
}
|
||||
@@ -1,241 +0,0 @@
|
||||
//go:build grpc
|
||||
|
||||
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/luxfi/metric"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
compression "github.com/luxfi/compress"
|
||||
consensuscore "github.com/luxfi/consensus/core"
|
||||
"github.com/luxfi/constants"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/network/peer"
|
||||
"github.com/luxfi/node/proto/platformvm"
|
||||
"github.com/luxfi/node/proto/pb/sdk"
|
||||
"github.com/luxfi/node/vms/platformvm/warp"
|
||||
"github.com/luxfi/node/vms/platformvm/warp/payload"
|
||||
"github.com/luxfi/node/wallet/network/primary"
|
||||
p2psdk "github.com/luxfi/p2p"
|
||||
"github.com/luxfi/sdk/info"
|
||||
|
||||
p2pmessage "github.com/luxfi/node/message"
|
||||
warpmessage "github.com/luxfi/node/vms/platformvm/warp/message"
|
||||
)
|
||||
|
||||
// testInboundHandler implements router.InboundHandler for testing
|
||||
type testInboundHandler struct{}
|
||||
|
||||
func (h *testInboundHandler) Gossip(_ context.Context, _ ids.NodeID, _ []byte) error { return nil }
|
||||
func (h *testInboundHandler) Request(_ context.Context, _ ids.NodeID, _ uint32, _ time.Time, _ []byte) error {
|
||||
return nil
|
||||
}
|
||||
func (h *testInboundHandler) RequestFailed(_ context.Context, _ ids.NodeID, _ uint32, _ *consensuscore.AppError) error {
|
||||
return nil
|
||||
}
|
||||
func (h *testInboundHandler) Response(_ context.Context, _ ids.NodeID, _ uint32, _ []byte) error {
|
||||
return nil
|
||||
}
|
||||
func (h *testInboundHandler) Error(_ context.Context, _ ids.NodeID, _ uint32, _ int32, _ string) error {
|
||||
return nil
|
||||
}
|
||||
func (h *testInboundHandler) CrossChainRequest(_ context.Context, _ ids.ID, _ uint32, _ time.Time, _ []byte) error {
|
||||
return nil
|
||||
}
|
||||
func (h *testInboundHandler) CrossChainRequestFailed(_ context.Context, _ ids.ID, _ uint32, _ *consensuscore.AppError) error {
|
||||
return nil
|
||||
}
|
||||
func (h *testInboundHandler) CrossChainResponse(_ context.Context, _ ids.ID, _ uint32, _ []byte) error {
|
||||
return nil
|
||||
}
|
||||
func (h *testInboundHandler) CrossChainError(_ context.Context, _ ids.ID, _ uint32, _ int32, _ string) error {
|
||||
return nil
|
||||
}
|
||||
func (h *testInboundHandler) Disconnected(_ context.Context, _ ids.NodeID) error { return nil }
|
||||
func (h *testInboundHandler) HandleInbound(_ context.Context, _ p2pmessage.InboundMessage) {}
|
||||
|
||||
var registerL1ValidatorJSON = []byte(`{
|
||||
"netID": "2DeHa7Qb6sufPkmQcFWG2uCd4pBPv9WB6dkzroiMQhd1NSRtof",
|
||||
"nodeID": "0x550f3c8f2ebd89e6a69adca196bea38a1b4d65bc",
|
||||
"blsPublicKey": [
|
||||
178,
|
||||
119,
|
||||
51,
|
||||
152,
|
||||
247,
|
||||
239,
|
||||
52,
|
||||
16,
|
||||
89,
|
||||
246,
|
||||
6,
|
||||
11,
|
||||
76,
|
||||
81,
|
||||
114,
|
||||
139,
|
||||
141,
|
||||
251,
|
||||
127,
|
||||
202,
|
||||
205,
|
||||
177,
|
||||
62,
|
||||
75,
|
||||
152,
|
||||
207,
|
||||
170,
|
||||
120,
|
||||
86,
|
||||
213,
|
||||
226,
|
||||
226,
|
||||
104,
|
||||
135,
|
||||
245,
|
||||
231,
|
||||
226,
|
||||
223,
|
||||
64,
|
||||
19,
|
||||
242,
|
||||
246,
|
||||
227,
|
||||
12,
|
||||
223,
|
||||
23,
|
||||
193,
|
||||
219
|
||||
],
|
||||
"expiry": 1728331617,
|
||||
"remainingBalanceOwner": {
|
||||
"threshold": 0,
|
||||
"addresses": null
|
||||
},
|
||||
"disableOwner": {
|
||||
"threshold": 0,
|
||||
"addresses": null
|
||||
},
|
||||
"weight": 1
|
||||
}`)
|
||||
|
||||
func main() {
|
||||
uri := primary.LocalAPIURI
|
||||
infoClient := info.NewClient(uri)
|
||||
networkID, err := infoClient.GetNetworkID(context.Background())
|
||||
if err != nil {
|
||||
log.Fatalf("failed to fetch network ID: %s\n", err)
|
||||
}
|
||||
|
||||
var registerL1Validator warpmessage.RegisterL1Validator
|
||||
err = json.Unmarshal(registerL1ValidatorJSON, ®isterL1Validator)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to unmarshal RegisterL1Validator message: %s\n", err)
|
||||
}
|
||||
err = warpmessage.Initialize(®isterL1Validator)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to initialize RegisterL1Validator message: %s\n", err)
|
||||
}
|
||||
|
||||
validationID := registerL1Validator.ValidationID()
|
||||
l1ValidatorRegistration, err := warpmessage.NewL1ValidatorRegistration(
|
||||
validationID,
|
||||
false,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create L1ValidatorRegistration message: %s\n", err)
|
||||
}
|
||||
|
||||
addressedCall, err := payload.NewAddressedCall(
|
||||
nil,
|
||||
l1ValidatorRegistration.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.L1ValidatorRegistrationJustification{
|
||||
Preimage: &platformvm.L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage{
|
||||
RegisterL1ValidatorMessage: registerL1Validator.Bytes(),
|
||||
},
|
||||
}
|
||||
justificationBytes, err := proto.Marshal(&justification)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create justification: %s\n", err)
|
||||
}
|
||||
|
||||
// Create inbound handler for messages
|
||||
inboundHandler := &testInboundHandler{}
|
||||
|
||||
p, err := peer.StartTestPeer(
|
||||
context.Background(),
|
||||
netip.AddrPortFrom(
|
||||
netip.AddrFrom4([4]byte{127, 0, 0, 1}),
|
||||
9651,
|
||||
),
|
||||
networkID,
|
||||
inboundHandler,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to start peer: %s\n", err)
|
||||
}
|
||||
|
||||
messageBuilder, err := p2pmessage.NewCreator(
|
||||
|
||||
metric.NewNoOpRegistry(),
|
||||
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.Request(
|
||||
constants.PlatformChainID,
|
||||
0,
|
||||
time.Hour,
|
||||
p2psdk.PrefixMessage(
|
||||
p2psdk.ProtocolPrefix(0), // SignatureRequestHandlerID placeholder,
|
||||
appRequestPayload,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create Request: %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)
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
//go:build grpc
|
||||
|
||||
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/luxfi/metric"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
compression "github.com/luxfi/compress"
|
||||
"github.com/luxfi/constants"
|
||||
"github.com/luxfi/node/network/peer"
|
||||
"github.com/luxfi/node/proto/pb/sdk"
|
||||
"github.com/luxfi/node/vms/platformvm/warp"
|
||||
"github.com/luxfi/node/vms/platformvm/warp/payload"
|
||||
"github.com/luxfi/node/wallet/network/primary"
|
||||
p2psdk "github.com/luxfi/p2p"
|
||||
"github.com/luxfi/sdk/info"
|
||||
|
||||
p2pmessage "github.com/luxfi/node/message"
|
||||
warpmessage "github.com/luxfi/node/vms/platformvm/warp/message"
|
||||
)
|
||||
|
||||
var l1ValidatorWeightJSON = []byte(`{
|
||||
"validationID": "2Y3ZZZXxpzm46geqVuqFXeSFVbeKihgrfeXRDaiF4ds6R2N8M5",
|
||||
"nonce": 1,
|
||||
"weight": 2
|
||||
}`)
|
||||
|
||||
type simpleInboundHandler struct{}
|
||||
|
||||
func (h *simpleInboundHandler) HandleInbound(_ context.Context, msg p2pmessage.InboundMessage) {
|
||||
log.Printf("received %s: %s", msg.Op(), msg.Message())
|
||||
}
|
||||
|
||||
func main() {
|
||||
uri := primary.LocalAPIURI
|
||||
infoClient := info.NewClient(uri)
|
||||
networkID, err := infoClient.GetNetworkID(context.Background())
|
||||
if err != nil {
|
||||
log.Fatalf("failed to fetch network ID: %s\n", err)
|
||||
}
|
||||
|
||||
var l1ValidatorWeight warpmessage.L1ValidatorWeight
|
||||
err = json.Unmarshal(l1ValidatorWeightJSON, &l1ValidatorWeight)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to unmarshal L1ValidatorWeight message: %s\n", err)
|
||||
}
|
||||
err = warpmessage.Initialize(&l1ValidatorWeight)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to initialize L1ValidatorWeight message: %s\n", err)
|
||||
}
|
||||
|
||||
addressedCall, err := payload.NewAddressedCall(
|
||||
nil,
|
||||
l1ValidatorWeight.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)
|
||||
}
|
||||
|
||||
p, err := peer.StartTestPeer(
|
||||
context.Background(),
|
||||
netip.AddrPortFrom(
|
||||
netip.AddrFrom4([4]byte{127, 0, 0, 1}),
|
||||
9651,
|
||||
),
|
||||
networkID,
|
||||
&simpleInboundHandler{},
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to start peer: %s\n", err)
|
||||
}
|
||||
|
||||
messageBuilder, err := p2pmessage.NewCreator(
|
||||
|
||||
metric.NewNoOpRegistry(),
|
||||
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.Request(
|
||||
constants.PlatformChainID,
|
||||
0,
|
||||
time.Hour,
|
||||
p2psdk.PrefixMessage(
|
||||
p2psdk.ProtocolPrefix(0), // SignatureRequestHandlerID placeholder,
|
||||
appRequestPayload,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create Request: %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)
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
//go:build grpc
|
||||
|
||||
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/luxfi/metric"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
compression "github.com/luxfi/compress"
|
||||
"github.com/luxfi/constants"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/network/peer"
|
||||
"github.com/luxfi/node/proto/pb/sdk"
|
||||
"github.com/luxfi/node/vms/platformvm/warp"
|
||||
"github.com/luxfi/node/vms/platformvm/warp/payload"
|
||||
"github.com/luxfi/node/wallet/network/primary"
|
||||
p2psdk "github.com/luxfi/p2p"
|
||||
"github.com/luxfi/sdk/info"
|
||||
|
||||
p2pmessage "github.com/luxfi/node/message"
|
||||
warpmessage "github.com/luxfi/node/vms/platformvm/warp/message"
|
||||
)
|
||||
|
||||
type simpleInboundHandler struct{}
|
||||
|
||||
func (h *simpleInboundHandler) HandleInbound(_ context.Context, msg p2pmessage.InboundMessage) {
|
||||
log.Printf("received %s: %s", msg.Op(), msg.Message())
|
||||
}
|
||||
|
||||
func main() {
|
||||
uri := primary.LocalAPIURI
|
||||
netID := ids.FromStringOrPanic("2DeHa7Qb6sufPkmQcFWG2uCd4pBPv9WB6dkzroiMQhd1NSRtof")
|
||||
conversionID := ids.FromStringOrPanic("28tfqwucuoH7oWxmVYDVQ2C1ehdYecF5mzwNmX2t1dTu1S5vHE")
|
||||
infoClient := info.NewClient(uri)
|
||||
networkID, err := infoClient.GetNetworkID(context.Background())
|
||||
if err != nil {
|
||||
log.Fatalf("failed to fetch network ID: %s\n", err)
|
||||
}
|
||||
|
||||
chainToL1Conversion, err := warpmessage.NewChainToL1Conversion(conversionID)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create NetToL1Conversion message: %s\n", err)
|
||||
}
|
||||
|
||||
addressedCall, err := payload.NewAddressedCall(
|
||||
nil,
|
||||
chainToL1Conversion.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)
|
||||
}
|
||||
|
||||
p, err := peer.StartTestPeer(
|
||||
context.Background(),
|
||||
netip.AddrPortFrom(
|
||||
netip.AddrFrom4([4]byte{127, 0, 0, 1}),
|
||||
9651,
|
||||
),
|
||||
networkID,
|
||||
&simpleInboundHandler{},
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to start peer: %s\n", err)
|
||||
}
|
||||
|
||||
messageBuilder, err := p2pmessage.NewCreator(
|
||||
|
||||
metric.NewNoOpRegistry(),
|
||||
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: netID[:],
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("failed to marshal SignatureRequest: %s\n", err)
|
||||
}
|
||||
|
||||
appRequest, err := messageBuilder.Request(
|
||||
constants.PlatformChainID,
|
||||
0,
|
||||
time.Hour,
|
||||
p2psdk.PrefixMessage(
|
||||
p2psdk.ProtocolPrefix(0), // SignatureRequestHandlerID placeholder,
|
||||
appRequestPayload,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create Request: %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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user