wire, main: Add SFNodeNetworkLimited flag

This change is part of the effort to add pruning support to btcd.

Wire now supports the ability to signal NODE_NETWORK_LIMITED which
signals to peers that the node is able to serve the last 288 blocks.

Since archival nodes have all blocks, they can also signal for
NODE_NETWORK_LIMITED.  SFNodeNetworkLimited flag is added to the default
services.
This commit is contained in:
Calvin Kim 2023-01-26 14:29:16 +09:00
parent 57ec43fedc
commit 0212c334ce
3 changed files with 18 additions and 11 deletions

View file

@ -44,8 +44,8 @@ import (
const (
// defaultServices describes the default services that are supported by
// the server.
defaultServices = wire.SFNodeNetwork | wire.SFNodeBloom |
wire.SFNodeWitness | wire.SFNodeCF
defaultServices = wire.SFNodeNetwork | wire.SFNodeNetworkLimited |
wire.SFNodeBloom | wire.SFNodeWitness | wire.SFNodeCF
// defaultRequiredServices describes the default services that are
// required to be supported by outbound peers.

View file

@ -93,18 +93,23 @@ const (
// SFNode2X is a flag used to indicate a peer is running the Segwit2X
// software.
SFNode2X
// SFNodeNetWorkLimited is a flag used to indicate a peer supports serving
// the last 288 blocks.
SFNodeNetworkLimited = 1 << 10
)
// Map of service flags back to their constant names for pretty printing.
var sfStrings = map[ServiceFlag]string{
SFNodeNetwork: "SFNodeNetwork",
SFNodeGetUTXO: "SFNodeGetUTXO",
SFNodeBloom: "SFNodeBloom",
SFNodeWitness: "SFNodeWitness",
SFNodeXthin: "SFNodeXthin",
SFNodeBit5: "SFNodeBit5",
SFNodeCF: "SFNodeCF",
SFNode2X: "SFNode2X",
SFNodeNetwork: "SFNodeNetwork",
SFNodeGetUTXO: "SFNodeGetUTXO",
SFNodeBloom: "SFNodeBloom",
SFNodeWitness: "SFNodeWitness",
SFNodeXthin: "SFNodeXthin",
SFNodeBit5: "SFNodeBit5",
SFNodeCF: "SFNodeCF",
SFNode2X: "SFNode2X",
SFNodeNetworkLimited: "SFNodeNetworkLimited",
}
// orderedSFStrings is an ordered list of service flags from highest to
@ -118,6 +123,7 @@ var orderedSFStrings = []ServiceFlag{
SFNodeBit5,
SFNodeCF,
SFNode2X,
SFNodeNetworkLimited,
}
// String returns the ServiceFlag in human-readable form.

View file

@ -21,7 +21,8 @@ func TestServiceFlagStringer(t *testing.T) {
{SFNodeBit5, "SFNodeBit5"},
{SFNodeCF, "SFNodeCF"},
{SFNode2X, "SFNode2X"},
{0xffffffff, "SFNodeNetwork|SFNodeGetUTXO|SFNodeBloom|SFNodeWitness|SFNodeXthin|SFNodeBit5|SFNodeCF|SFNode2X|0xffffff00"},
{SFNodeNetworkLimited, "SFNodeNetworkLimited"},
{0xffffffff, "SFNodeNetwork|SFNodeGetUTXO|SFNodeBloom|SFNodeWitness|SFNodeXthin|SFNodeBit5|SFNodeCF|SFNode2X|SFNodeNetworkLimited|0xfffffb00"},
}
t.Logf("Running %d tests", len(tests))