diff --git a/config/config.go b/config/config.go index 07dc01af3..63e5cee7a 100644 --- a/config/config.go +++ b/config/config.go @@ -165,7 +165,7 @@ type configFlags struct { DropAddrIndex bool `long:"dropaddrindex" description:"Deletes the address-based transaction index from the database on start up and then exits."` RelayNonStd bool `long:"relaynonstd" description:"Relay non-standard transactions regardless of the default settings for the active network."` RejectNonStd bool `long:"rejectnonstd" description:"Reject non-standard transactions regardless of the default settings for the active network."` - SubNetwork uint64 `long:"subnetwork" description:"If subnetwork > 0, than node will request and process only payloads from specified subnetwork. And if subnetwork is 0, than payloads of all subnetworks are processed."` + SubNetwork uint64 `long:"subnetwork" description:"If subnetwork > 0, than node will request and process only payloads from specified subnetwork. And if subnetwork is 0, than payloads of all subnetworks are processed. Subnetworks 3 through 255 are reserved for future use and are currently not allowed."` } // Config defines the configuration options for btcd. @@ -751,8 +751,16 @@ func loadConfig() (*Config, []string, error) { cfg.MiningAddrs = append(cfg.MiningAddrs, addr) } + if cfg.SubNetwork >= wire.SubNetworkReservedFirst && cfg.SubNetwork <= wire.SubNetworkReservedLast { + str := "%s: subnetworkID %d is reserved for future use, and nodes can not run in it " + err := fmt.Errorf(str, funcName, cfg.SubNetwork) + fmt.Fprintln(os.Stderr, err) + fmt.Fprintln(os.Stderr, usageMessage) + return nil, nil, err + } + // Check that 'generate' and 'subnetwork' flags do not conflict - if cfg.Generate && cfg.SubNetwork != 0 { + if cfg.Generate && cfg.SubNetwork != wire.SubNetworkSupportsAll { str := "%s: both generate flag and subnetwork filtering are set " err := fmt.Errorf(str, funcName) fmt.Fprintln(os.Stderr, err) diff --git a/config/config_test.go b/config/config_test.go index 918924ef2..da9240561 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -7,6 +7,8 @@ import ( "regexp" "runtime" "testing" + + "github.com/daglabs/btcd/wire" ) var ( @@ -70,3 +72,18 @@ func TestCreateDefaultConfigFile(t *testing.T) { t.Error("Could not find rpcpass in generated default config file.") } } + +// TestConstants makes sure that all constants hard-coded into the help text were not modified. +func TestConstants(t *testing.T) { + if wire.SubNetworkSupportsAll != 0 { + t.Errorf("wire.SubNetworkSupportsAll value was changed from 0, therefore you probably need to update the help text for SubNetwork") + } + + if wire.SubNetworkReservedFirst != 3 { + t.Errorf("wire.SubNetworkReservedFirst value was changed from 0, therefore you probably need to update the help text for SubNetwork") + } + + if wire.SubNetworkReservedLast != 255 { + t.Errorf("wire.SubNetworkReservedLast value was changed from 0, therefore you probably need to update the help text for SubNetwork") + } +} diff --git a/wire/msgtx.go b/wire/msgtx.go index 682fcd717..957c3b994 100644 --- a/wire/msgtx.go +++ b/wire/msgtx.go @@ -96,14 +96,21 @@ const ( // 6,400,000 bytes. freeListMaxItems = 12500 - // SubNetworkSupportsAll is the sub network id that is used to signal to peers that you support all sub-networks + // SubNetworkSupportsAll is the sub-network id that is used to signal to peers that you support all sub-networks SubNetworkSupportsAll = 0 - // SubNetworkDAGCoin is the default sub network which is used for transactions without related payload data + // SubNetworkDAGCoin is the default sub-network which is used for transactions without related payload data SubNetworkDAGCoin = 1 - // SubNetworkRegistry is the sub network which is used for adding new sub networks to the registry + // SubNetworkRegistry is the sub-network which is used for adding new sub networks to the registry SubNetworkRegistry = 2 + + // SubNetworkReservedFirst and SubnetworkReservedLast mark the range of sub-networks that are reserved for future use + // and are currently un-assigned for anything + // SubNetworkReservedFirst is the first reserved sub-network + SubNetworkReservedFirst = 3 + // SubNetworkReservedLast is the last reserved sub-network + SubNetworkReservedLast = 255 ) // scriptFreeList defines a free list of byte slices (up to the maximum number