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

config to disable outgoing periodic gossip and pull gossip appRequests #763

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions plugin/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ type Config struct {
PullGossipFrequency Duration `json:"pull-gossip-frequency"`
RegossipFrequency Duration `json:"regossip-frequency"`
TxRegossipFrequency Duration `json:"tx-regossip-frequency"` // Deprecated: use RegossipFrequency instead
DisableGossip bool `json:"disable-gossip"` // If true, disables gossiping of transactions

// Log
LogLevel string `json:"log-level"`
Expand Down
3 changes: 3 additions & 0 deletions plugin/evm/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func (t txGossipHandler) AppGossip(ctx context.Context, nodeID ids.NodeID, gossi
}

func (t txGossipHandler) AppRequest(ctx context.Context, nodeID ids.NodeID, deadline time.Time, requestBytes []byte) ([]byte, *common.AppError) {
if t.appRequestHandler == nil {
return nil, nil
}
return t.appRequestHandler.AppRequest(ctx, nodeID, deadline, requestBytes)
}

Expand Down
19 changes: 14 additions & 5 deletions plugin/evm/gossiper_eth_gossiping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"crypto/ecdsa"
"encoding/json"
"fmt"
"math/big"
"strings"
"sync"
Expand All @@ -22,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ava-labs/coreth/core"
"github.com/ava-labs/coreth/core/types"
Expand Down Expand Up @@ -73,6 +75,11 @@ func getValidEthTxs(key *ecdsa.PrivateKey, count int, gasPrice *big.Int) []*type
// show that a geth tx discovered from gossip is requested to the same node that
// gossiped it
func TestMempoolEthTxsAppGossipHandling(t *testing.T) {
testMempoolEthTxsAppGossipHandling(t, false)
testMempoolEthTxsAppGossipHandling(t, true)
}

func testMempoolEthTxsAppGossipHandling(t *testing.T, disabled bool) {
assert := assert.New(t)

key, err := crypto.GenerateKey()
Expand All @@ -83,7 +90,8 @@ func TestMempoolEthTxsAppGossipHandling(t *testing.T) {
genesisJSON, err := fundAddressByGenesis([]common.Address{addr})
assert.NoError(err)

_, vm, _, _, sender := GenesisVM(t, true, genesisJSON, "", "")
config := fmt.Sprintf(`{"disable-gossip":%v}`, disabled)
_, vm, _, _, sender := GenesisVM(t, true, genesisJSON, config, "")
defer func() {
err := vm.Shutdown(context.Background())
assert.NoError(err)
Expand Down Expand Up @@ -116,10 +124,11 @@ func TestMempoolEthTxsAppGossipHandling(t *testing.T) {
assert.False(txRequested, "tx should not be requested")

// wait for transaction to be re-gossiped
attemptAwait(t, &wg, 5*time.Second)
got := attemptAwait(&wg, 5*time.Second)
require.Equal(t, !disabled, got)
}

func attemptAwait(t *testing.T, wg *sync.WaitGroup, delay time.Duration) {
func attemptAwait(wg *sync.WaitGroup, delay time.Duration) bool {
ticker := make(chan struct{})

// Wait for [wg] and then close [ticket] to indicate that
Expand All @@ -131,8 +140,8 @@ func attemptAwait(t *testing.T, wg *sync.WaitGroup, delay time.Duration) {

select {
case <-time.After(delay):
t.Fatal("Timed out waiting for wait group to complete")
return false // Didn't get the tx
case <-ticker:
// The wait group completed without issue
return true // Got the tx
}
}
20 changes: 16 additions & 4 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ func (vm *VM) initBlockBuilding() error {
}

ethTxPushGossiper := vm.ethTxPushGossiper.Get()
if ethTxPushGossiper == nil {
if ethTxPushGossiper == nil && !vm.config.DisableGossip {
ethTxPushGossiper, err = gossip.NewPushGossiper[*GossipEthTx](
ethTxGossipMarshaller,
ethTxPool,
Expand All @@ -1098,7 +1098,7 @@ func (vm *VM) initBlockBuilding() error {
vm.ethTxPushGossiper.Set(ethTxPushGossiper)
}

if vm.atomicTxPushGossiper == nil {
if vm.atomicTxPushGossiper == nil && !vm.config.DisableGossip {
vm.atomicTxPushGossiper, err = gossip.NewPushGossiper[*atomic.GossipAtomicTx](
atomicTxGossipMarshaller,
vm.mempool,
Expand All @@ -1121,7 +1121,7 @@ func (vm *VM) initBlockBuilding() error {
vm.builder.awaitSubmittedTxs()

if vm.ethTxGossipHandler == nil {
vm.ethTxGossipHandler = newTxGossipHandler[*GossipEthTx](
handler := newTxGossipHandler[*GossipEthTx](
vm.ctx.Log,
ethTxGossipMarshaller,
ethTxPool,
Expand All @@ -1131,14 +1131,18 @@ func (vm *VM) initBlockBuilding() error {
txGossipThrottlingLimit,
vm.p2pValidators,
)
if vm.config.DisableGossip {
handler.appRequestHandler = nil // disable responding to pull gossip requests
}
vm.ethTxGossipHandler = handler
}

if err := vm.Network.AddHandler(p2p.TxGossipHandlerID, vm.ethTxGossipHandler); err != nil {
return fmt.Errorf("failed to add eth tx gossip handler: %w", err)
}

if vm.atomicTxGossipHandler == nil {
vm.atomicTxGossipHandler = newTxGossipHandler[*atomic.GossipAtomicTx](
handler := newTxGossipHandler[*atomic.GossipAtomicTx](
vm.ctx.Log,
atomicTxGossipMarshaller,
vm.mempool,
Expand All @@ -1148,12 +1152,20 @@ func (vm *VM) initBlockBuilding() error {
txGossipThrottlingLimit,
vm.p2pValidators,
)
if vm.config.DisableGossip {
handler.appRequestHandler = nil // disable responding to pull gossip requests
}
vm.atomicTxGossipHandler = handler
}

if err := vm.Network.AddHandler(p2p.AtomicTxGossipHandlerID, vm.atomicTxGossipHandler); err != nil {
return fmt.Errorf("failed to add atomic tx gossip handler: %w", err)
}

if vm.config.DisableGossip {
return nil // Disable periodic push and pull gossip
}

if vm.ethTxPullGossiper == nil {
ethTxPullGossiper := gossip.NewPullGossiper[*GossipEthTx](
vm.ctx.Log,
Expand Down
Loading