Skip to content

Commit

Permalink
Embed noop handler for all unhandled messages (#2288)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu authored Nov 10, 2023
1 parent 86201ae commit b8746de
Showing 1 changed file with 8 additions and 42 deletions.
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

0 comments on commit b8746de

Please sign in to comment.