Skip to content
Open
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 docs/cli/default_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ devfakeauthor = false
txarrivalwait = "500ms"
txannouncementonly = false
disable-tx-propagation = false
nosnap = false
[p2p.discovery]
v4disc = true
v5disc = true
Expand Down
2 changes: 2 additions & 0 deletions docs/cli/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ The ```bor server``` command runs the Bor client.

- ```nodiscover```: Disables the peer discovery mechanism (manual peer addition) (default: false)

- ```p2p.nosnap```: Disable serving snap sync requests to peers (snap/1 protocol is not advertised) (default: false)

- ```port```: Network listening port (default: 30303)

- ```relay.bp-rpc-endpoints```: Comma separated rpc endpoints of all block producers
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ func (s *Ethereum) SetAuthorized(authorized bool) {
// network protocols to start.
func (s *Ethereum) Protocols() []p2p.Protocol {
protos := eth.MakeProtocols((*ethHandler)(s.handler), s.networkID, s.discmix)
if s.config.SnapshotCache > 0 {
if s.config.SnapshotCache > 0 && !s.config.NoSnapServing {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this disable snap/1 completely from being registered? In which case the node won't be able to sync from snap.

I think it's fine - but we can mention this fact in comment / description.

Basically, if we want to sync from snap, we can set nosnap to false which will allow snap/1 to be registered.

protos = append(protos, snap.MakeProtocols((*snapHandler)(s.handler))...)
}
if s.config.WitnessProtocol {
Expand Down
91 changes: 91 additions & 0 deletions eth/backend_protocols_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2025 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package eth

import (
"testing"

"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/protocols/snap"
)

// TestProtocolsSnapServing verifies that the snap/1 protocol is included or
// excluded from the advertised protocol list based on SnapshotCache and
// NoSnapServing config fields.
func TestProtocolsSnapServing(t *testing.T) {
th := newTestHandlerWithBlocks(0)
defer th.close()

tests := []struct {
name string
snapshotCache int
noSnapServing bool
wantSnap bool
}{
{
name: "snap served when snapshots enabled",
snapshotCache: 100,
noSnapServing: false,
wantSnap: true,
},
{
name: "snap not served when SnapshotCache is zero",
snapshotCache: 0,
noSnapServing: false,
wantSnap: false,
},
{
name: "snap not served when NoSnapServing is set",
snapshotCache: 100,
noSnapServing: true,
wantSnap: false,
},
{
name: "snap not served when both SnapshotCache zero and NoSnapServing set",
snapshotCache: 0,
noSnapServing: true,
wantSnap: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
eth := &Ethereum{
handler: th.handler,
networkID: 1,
config: &ethconfig.Config{
SnapshotCache: tt.snapshotCache,
NoSnapServing: tt.noSnapServing,
},
}

protos := eth.Protocols()

var hasSnap bool
for _, proto := range protos {
if proto.Name == snap.ProtocolName {
hasSnap = true
break
}
}

if hasSnap != tt.wantSnap {
t.Errorf("snap protocol advertised = %v, want %v", hasSnap, tt.wantSnap)
}
})
}
}
5 changes: 5 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ type Config struct {
// WitnessProtocol enabless the wit protocol
WitnessProtocol bool

// NoSnapServing disables the snap/1 sub-protocol, preventing this node from
// serving snap sync state to peers. Useful for block producers that should
// not spend resources on snap sync serving.
NoSnapServing bool

// SyncWithWitnesses enables syncing blocks with witnesses
SyncWithWitnesses bool

Expand Down
5 changes: 5 additions & 0 deletions internal/cli/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ type P2PConfig struct {

// DisableTxPropagation disables transaction broadcast and announcement completely to its peers
DisableTxPropagation bool `hcl:"disable-tx-propagation,optional" toml:"disable-tx-propagation,optional"`

// NoSnapServing disables serving snap sync requests to peers (snap/1 protocol is not advertised)
NoSnapServing bool `hcl:"nosnap,optional" toml:"nosnap,optional"`
}

type P2PDiscovery struct {
Expand Down Expand Up @@ -837,6 +840,7 @@ func DefaultConfig() *Config {
TxArrivalWait: 500 * time.Millisecond,
TxAnnouncementOnly: false,
DisableTxPropagation: false,
NoSnapServing: false,
Discovery: &P2PDiscovery{
DiscoveryV4: true,
DiscoveryV5: true,
Expand Down Expand Up @@ -1657,6 +1661,7 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (*
n.ParallelEVM.SpeculativeProcesses = c.ParallelEVM.SpeculativeProcesses
n.ParallelEVM.Enforce = c.ParallelEVM.Enforce

n.NoSnapServing = c.P2P.NoSnapServing
n.WitnessProtocol = c.Witness.Enable
if c.SyncMode == "stateless" {
if !c.Witness.Enable {
Expand Down
7 changes: 7 additions & 0 deletions internal/cli/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,13 @@ func (c *Command) Flags(config *Config) *flagset.Flagset {
Default: c.cliConfig.P2P.DisableTxPropagation,
Group: "P2P",
})
f.BoolFlag(&flagset.BoolFlag{
Name: "p2p.nosnap",
Usage: "Disable serving snap sync requests to peers (snap/1 protocol is not advertised)",
Value: &c.cliConfig.P2P.NoSnapServing,
Default: c.cliConfig.P2P.NoSnapServing,
Group: "P2P",
})
f.SliceStringFlag(&flagset.SliceStringFlag{
Name: "discovery.dns",
Usage: "Comma separated list of enrtree:// URLs which will be queried for nodes to connect to",
Expand Down
Loading