Skip to content

Commit

Permalink
Allow issuing transactions when using partial-sync (#3570)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Dec 2, 2024
1 parent 01eb14a commit f9d4e39
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 39 deletions.
12 changes: 11 additions & 1 deletion vms/platformvm/block/executor/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (
var (
_ Manager = (*manager)(nil)

ErrChainNotSynced = errors.New("chain not synced")
ErrChainNotSynced = errors.New("chain not synced")
ErrImportTxWhilePartialSyncing = errors.New("issuing an import tx is not allowed while partial syncing")
)

type Manager interface {
Expand Down Expand Up @@ -124,6 +125,15 @@ func (m *manager) VerifyTx(tx *txs.Tx) error {
return ErrChainNotSynced
}

// If partial sync is enabled, this node isn't guaranteed to have the full
// UTXO set from shared memory. To avoid issuing invalid transactions,
// issuance of an ImportTx during this state is completely disallowed.
if m.txExecutorBackend.Config.PartialSyncPrimaryNetwork {
if _, isImportTx := tx.Unsigned.(*txs.ImportTx); isImportTx {
return ErrImportTxWhilePartialSyncing
}
}

recommendedPChainHeight, err := m.ctx.ValidatorState.GetMinimumHeight(context.TODO())
if err != nil {
return fmt.Errorf("failed to fetch P-chain height: %w", err)
Expand Down
22 changes: 2 additions & 20 deletions vms/platformvm/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package network

import (
"context"
"errors"
"sync"
"time"

Expand All @@ -26,8 +25,6 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
)

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

type Network struct {
*p2p.Network

Expand Down Expand Up @@ -188,18 +185,12 @@ func New(
}

func (n *Network) PushGossip(ctx context.Context) {
// TODO: Even though the node is running partial sync, we should support
// issuing transactions from the RPC.
if n.partialSyncPrimaryNetwork {
return
}

gossip.Every(ctx, n.log, n.txPushGossiper, n.txPushGossipFrequency)
}

func (n *Network) PullGossip(ctx context.Context) {
// If the node is running partial sync, we should not perform any pull
// gossip.
// If the node is running partial sync, we do not perform any pull gossip
// because we should never be a validator.
if n.partialSyncPrimaryNetwork {
return
}
Expand All @@ -219,15 +210,6 @@ func (n *Network) AppGossip(ctx context.Context, nodeID ids.NodeID, msgBytes []b
}

func (n *Network) IssueTxFromRPC(tx *txs.Tx) error {
// If we are partially syncing the Primary Network, we should not be
// maintaining the transaction mempool locally.
//
// TODO: We should still push the transaction to some peers when partial
// syncing.
if n.partialSyncPrimaryNetwork {
return errMempoolDisabledWithPartialSync
}

if err := n.mempool.Add(tx); err != nil {
return err
}
Expand Down
24 changes: 6 additions & 18 deletions vms/platformvm/network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ func TestNetworkIssueTxFromRPC(t *testing.T) {
tx := &txs.Tx{}

type test struct {
name string
mempoolFunc func(*gomock.Controller) pmempool.Mempool
txVerifier testTxVerifier
partialSyncPrimaryNetwork bool
appSenderFunc func(*gomock.Controller) common.AppSender
expectedErr error
name string
mempoolFunc func(*gomock.Controller) pmempool.Mempool
txVerifier testTxVerifier
appSenderFunc func(*gomock.Controller) common.AppSender
expectedErr error
}

tests := []test{
Expand Down Expand Up @@ -129,17 +128,6 @@ func TestNetworkIssueTxFromRPC(t *testing.T) {
},
expectedErr: errTest,
},
{
name: "mempool is disabled if primary network is not being fully synced",
mempoolFunc: func(ctrl *gomock.Controller) pmempool.Mempool {
return mempoolmock.NewMempool(ctrl)
},
partialSyncPrimaryNetwork: true,
appSenderFunc: func(ctrl *gomock.Controller) common.AppSender {
return commonmock.NewSender(ctrl)
},
expectedErr: errMempoolDisabledWithPartialSync,
},
{
name: "happy path",
mempoolFunc: func(ctrl *gomock.Controller) pmempool.Mempool {
Expand Down Expand Up @@ -174,7 +162,7 @@ func TestNetworkIssueTxFromRPC(t *testing.T) {
snowCtx.ValidatorState,
tt.txVerifier,
tt.mempoolFunc(ctrl),
tt.partialSyncPrimaryNetwork,
false,
tt.appSenderFunc(ctrl),
nil,
nil,
Expand Down

0 comments on commit f9d4e39

Please sign in to comment.