Skip to content

Remove network context #2543

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

Merged
merged 1 commit into from
Dec 22, 2023
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
2 changes: 1 addition & 1 deletion vms/platformvm/block/builder/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func newEnvironment(t *testing.T) *environment {

txVerifier := network.NewLockedTxVerifier(&res.ctx.Lock, res.blkManager)
res.network = network.New(
res.backend.Ctx,
logging.NoLog{},
txVerifier,
res.mempool,
res.backend.Config.PartialSyncPrimaryNetwork,
Expand Down
28 changes: 14 additions & 14 deletions vms/platformvm/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/ava-labs/avalanchego/cache"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/vms/components/message"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool"
Expand All @@ -36,7 +36,7 @@ type network struct {
// We embed a noop handler for all unhandled messages
common.AppHandler

ctx *snow.Context
log logging.Logger
txVerifier TxVerifier
mempool mempool.Mempool
partialSyncPrimaryNetwork bool
Expand All @@ -48,16 +48,16 @@ type network struct {
}

func New(
ctx *snow.Context,
log logging.Logger,
txVerifier TxVerifier,
mempool mempool.Mempool,
partialSyncPrimaryNetwork bool,
appSender common.AppSender,
) Network {
return &network{
AppHandler: common.NewNoOpAppHandler(ctx.Log),
AppHandler: common.NewNoOpAppHandler(log),

ctx: ctx,
log: log,
txVerifier: txVerifier,
mempool: mempool,
partialSyncPrimaryNetwork: partialSyncPrimaryNetwork,
Expand All @@ -67,37 +67,37 @@ func New(
}

func (n *network) AppGossip(ctx context.Context, nodeID ids.NodeID, msgBytes []byte) error {
n.ctx.Log.Debug("called AppGossip message handler",
n.log.Debug("called AppGossip message handler",
zap.Stringer("nodeID", nodeID),
zap.Int("messageLen", len(msgBytes)),
)

if n.partialSyncPrimaryNetwork {
n.ctx.Log.Debug("dropping AppGossip message",
n.log.Debug("dropping AppGossip message",
zap.String("reason", "primary network is not being fully synced"),
)
return nil
}

msgIntf, err := message.Parse(msgBytes)
if err != nil {
n.ctx.Log.Debug("dropping AppGossip message",
n.log.Debug("dropping AppGossip message",
zap.String("reason", "failed to parse message"),
)
return nil
}

msg, ok := msgIntf.(*message.Tx)
if !ok {
n.ctx.Log.Debug("dropping unexpected message",
n.log.Debug("dropping unexpected message",
zap.Stringer("nodeID", nodeID),
)
return nil
}

tx, err := txs.Parse(txs.Codec, msg.Tx)
if err != nil {
n.ctx.Log.Verbo("received invalid tx",
n.log.Verbo("received invalid tx",
zap.Stringer("nodeID", nodeID),
zap.Binary("tx", msg.Tx),
zap.Error(err),
Expand Down Expand Up @@ -145,7 +145,7 @@ func (n *network) issueTx(tx *txs.Tx) error {

// Verify the tx at the currently preferred state
if err := n.txVerifier.VerifyTx(tx); err != nil {
n.ctx.Log.Debug("tx failed verification",
n.log.Debug("tx failed verification",
zap.Stringer("txID", txID),
zap.Error(err),
)
Expand All @@ -161,7 +161,7 @@ func (n *network) issueTx(tx *txs.Tx) error {
}

if err := n.mempool.Add(tx); err != nil {
n.ctx.Log.Debug("tx failed to be added to the mempool",
n.log.Debug("tx failed to be added to the mempool",
zap.Stringer("txID", txID),
zap.Error(err),
)
Expand All @@ -186,12 +186,12 @@ func (n *network) gossipTx(ctx context.Context, txID ids.ID, msgBytes []byte) {
return
}

n.ctx.Log.Debug("gossiping tx",
n.log.Debug("gossiping tx",
zap.Stringer("txID", txID),
)

if err := n.appSender.SendAppGossip(ctx, msgBytes); err != nil {
n.ctx.Log.Error("failed to gossip tx",
n.log.Error("failed to gossip tx",
zap.Stringer("txID", txID),
zap.Error(err),
)
Expand Down
13 changes: 3 additions & 10 deletions vms/platformvm/network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"go.uber.org/mock/gomock"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/vms/components/avax"
Expand Down Expand Up @@ -166,9 +165,7 @@ func TestNetworkAppGossip(t *testing.T) {
ctrl := gomock.NewController(t)

n := New(
&snow.Context{
Log: logging.NoLog{},
},
logging.NoLog{},
testTxVerifier{},
tt.mempoolFunc(ctrl),
tt.partialSyncPrimaryNetwork,
Expand Down Expand Up @@ -293,9 +290,7 @@ func TestNetworkIssueTx(t *testing.T) {
ctrl := gomock.NewController(t)

n := New(
&snow.Context{
Log: logging.NoLog{},
},
logging.NoLog{},
tt.txVerifier,
tt.mempoolFunc(ctrl),
tt.partialSyncPrimaryNetwork,
Expand All @@ -314,9 +309,7 @@ func TestNetworkGossipTx(t *testing.T) {
appSender := common.NewMockSender(ctrl)

nIntf := New(
&snow.Context{
Log: logging.NoLog{},
},
logging.NoLog{},
testTxVerifier{},
mempool.NewMockMempool(ctrl),
false,
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (vm *VM) Initialize(

txVerifier := network.NewLockedTxVerifier(&txExecutorBackend.Ctx.Lock, vm.manager)
vm.Network = network.New(
txExecutorBackend.Ctx,
chainCtx.Log,
txVerifier,
mempool,
txExecutorBackend.Config.PartialSyncPrimaryNetwork,
Expand Down