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 ( const (
// defaultServices describes the default services that are supported by // defaultServices describes the default services that are supported by
// the server. // the server.
defaultServices = wire.SFNodeNetwork | wire.SFNodeBloom | defaultServices = wire.SFNodeNetwork | wire.SFNodeNetworkLimited |
wire.SFNodeWitness | wire.SFNodeCF wire.SFNodeBloom | wire.SFNodeWitness | wire.SFNodeCF
// defaultRequiredServices describes the default services that are // defaultRequiredServices describes the default services that are
// required to be supported by outbound peers. // required to be supported by outbound peers.

View file

@ -93,6 +93,10 @@ const (
// SFNode2X is a flag used to indicate a peer is running the Segwit2X // SFNode2X is a flag used to indicate a peer is running the Segwit2X
// software. // software.
SFNode2X 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. // Map of service flags back to their constant names for pretty printing.
@ -105,6 +109,7 @@ var sfStrings = map[ServiceFlag]string{
SFNodeBit5: "SFNodeBit5", SFNodeBit5: "SFNodeBit5",
SFNodeCF: "SFNodeCF", SFNodeCF: "SFNodeCF",
SFNode2X: "SFNode2X", SFNode2X: "SFNode2X",
SFNodeNetworkLimited: "SFNodeNetworkLimited",
} }
// orderedSFStrings is an ordered list of service flags from highest to // orderedSFStrings is an ordered list of service flags from highest to
@ -118,6 +123,7 @@ var orderedSFStrings = []ServiceFlag{
SFNodeBit5, SFNodeBit5,
SFNodeCF, SFNodeCF,
SFNode2X, SFNode2X,
SFNodeNetworkLimited,
} }
// String returns the ServiceFlag in human-readable form. // String returns the ServiceFlag in human-readable form.

View file

@ -21,7 +21,8 @@ func TestServiceFlagStringer(t *testing.T) {
{SFNodeBit5, "SFNodeBit5"}, {SFNodeBit5, "SFNodeBit5"},
{SFNodeCF, "SFNodeCF"}, {SFNodeCF, "SFNodeCF"},
{SFNode2X, "SFNode2X"}, {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)) t.Logf("Running %d tests", len(tests))