From 815ded348ec5aa2d0dbe7cfbc1468616e3508252 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 22 Aug 2016 18:02:53 -0700 Subject: [PATCH] config: introduce new flags to accept/reject non-std transactions This commit adds two new cli flags: one for accepting non-std transactions, and the other for rejecting non-std transactions. The two flag are rejected when using concurrently. Config parsing is set up such that, the desired policy expressed via the config always overrides the policy set by default for a particular chain. The doc.go files and the sample-btcd.conf file have been updated to document the new flags exposing further policy control. --- config.go | 22 ++++++++++++++++++++++ doc.go | 4 ++++ sample-btcd.conf | 6 ++++++ server.go | 2 +- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index 5e7cb27a..fe8bab2c 100644 --- a/config.go +++ b/config.go @@ -141,6 +141,8 @@ type config struct { DropTxIndex bool `long:"droptxindex" description:"Deletes the hash-based transaction index from the database on start up and then exits."` AddrIndex bool `long:"addrindex" description:"Maintain a full address-based transaction index which makes the searchrawtransactions RPC available"` 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."` onionlookup func(string) ([]net.IP, error) lookup func(string) ([]net.IP, error) oniondial func(string, string) (net.Conn, error) @@ -479,6 +481,26 @@ func loadConfig() (*config, []string, error) { return nil, nil, err } + // Set the default policy for relaying non-standard transactions + // according to the default of the active network. The set + // configuration value takes precedence over the default value for the + // selected network. + relayNonStd := activeNetParams.RelayNonStdTxs + switch { + case cfg.RelayNonStd && cfg.RejectNonStd: + str := "%s: rejectnonstd and relaynonstd cannot be used " + + "together -- choose only one" + err := fmt.Errorf(str, funcName) + fmt.Fprintln(os.Stderr, err) + fmt.Fprintln(os.Stderr, usageMessage) + return nil, nil, err + case cfg.RejectNonStd: + relayNonStd = false + case cfg.RelayNonStd: + relayNonStd = true + } + cfg.RelayNonStd = relayNonStd + // Append the network type to the data directory so it is "namespaced" // per network. In addition to the block database, there are other // pieces of data that are saved to disk such as address manager state. diff --git a/doc.go b/doc.go index d01ffe7a..2ef4cba8 100644 --- a/doc.go +++ b/doc.go @@ -108,6 +108,10 @@ Application Options: --sigcachemaxsize= The maximum number of entries in the signature verification cache. --blocksonly Do not accept transactions from remote peers. + --relaynonstd Relay non-standard transactions regardless of the + default settings for the active network. + --rejectnonstd Reject non-standard transactions regardless of the + default settings for the active network. Help Options: -h, --help Show this help message diff --git a/sample-btcd.conf b/sample-btcd.conf index da4e4b8c..d12be44d 100644 --- a/sample-btcd.conf +++ b/sample-btcd.conf @@ -238,6 +238,12 @@ ; Do not accept transactions from remote peers. ; blocksonly=1 +; Relay non-standard transactions regardless of default network settings. +; relaynonstd=1 + +; Reject non-standard transactions regardless of default network settings. +; rejectnonstd=1 + ; ------------------------------------------------------------------------------ ; Optional Transaction Indexes diff --git a/server.go b/server.go index f78d2a33..545d0b24 100644 --- a/server.go +++ b/server.go @@ -2519,7 +2519,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param txC := mempool.Config{ Policy: mempool.Policy{ DisableRelayPriority: cfg.NoRelayPriority, - RelayNonStd: chainParams.RelayNonStdTxs, + RelayNonStd: cfg.RelayNonStd, FreeTxRelayLimit: cfg.FreeTxRelayLimit, MaxOrphanTxs: cfg.MaxOrphanTxs, MaxOrphanTxSize: defaultMaxOrphanTxSize,