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

Embed noop handler for all unhandled messages #2288

Merged
merged 1 commit into from
Nov 10, 2023
Merged
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
50 changes: 8 additions & 42 deletions vms/platformvm/block/builder/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package builder
import (
"context"
"fmt"
"time"

"go.uber.org/zap"

Expand All @@ -20,11 +19,9 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
)

const (
// We allow [recentCacheSize] to be fairly large because we only store hashes
// in the cache, not entire transactions.
recentCacheSize = 512
)
// We allow [recentCacheSize] to be fairly large because we only store hashes
// in the cache, not entire transactions.
const recentCacheSize = 512

var _ Network = (*network)(nil)

Expand All @@ -36,6 +33,9 @@ type Network interface {
}

type network struct {
// We embed a noop handler for all unhandled messages
common.AppHandler

ctx *snow.Context
blkBuilder *builder

Expand All @@ -50,49 +50,15 @@ func NewNetwork(
appSender common.AppSender,
) Network {
return &network{
AppHandler: common.NewNoOpAppHandler(ctx.Log),

ctx: ctx,
blkBuilder: blkBuilder,
appSender: appSender,
recentTxs: &cache.LRU[ids.ID, struct{}]{Size: recentCacheSize},
}
}

func (*network) CrossChainAppRequestFailed(context.Context, ids.ID, uint32) error {
// This VM currently only supports gossiping of txs, so there are no
// requests.
return nil
}

func (*network) CrossChainAppRequest(context.Context, ids.ID, uint32, time.Time, []byte) error {
// This VM currently only supports gossiping of txs, so there are no
// requests.
return nil
}

func (*network) CrossChainAppResponse(context.Context, ids.ID, uint32, []byte) error {
// This VM currently only supports gossiping of txs, so there are no
// requests.
return nil
}

func (*network) AppRequestFailed(context.Context, ids.NodeID, uint32) error {
// This VM currently only supports gossiping of txs, so there are no
// requests.
return nil
}

func (*network) AppRequest(context.Context, ids.NodeID, uint32, time.Time, []byte) error {
// This VM currently only supports gossiping of txs, so there are no
// requests.
return nil
}

func (*network) AppResponse(context.Context, ids.NodeID, uint32, []byte) error {
// This VM currently only supports gossiping of txs, so there are no
// requests.
return nil
}

func (n *network) AppGossip(_ context.Context, nodeID ids.NodeID, msgBytes []byte) error {
n.ctx.Log.Debug("called AppGossip message handler",
zap.Stringer("nodeID", nodeID),
Expand Down
Loading