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.
This commit is contained in:
Olaoluwa Osuntokun 2016-08-22 18:02:53 -07:00
parent dc5486a579
commit 815ded348e
No known key found for this signature in database
GPG key ID: 9CC5B105D03521A2
4 changed files with 33 additions and 1 deletions

View file

@ -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."` 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"` 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."` 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) onionlookup func(string) ([]net.IP, error)
lookup func(string) ([]net.IP, error) lookup func(string) ([]net.IP, error)
oniondial func(string, string) (net.Conn, error) oniondial func(string, string) (net.Conn, error)
@ -479,6 +481,26 @@ func loadConfig() (*config, []string, error) {
return nil, nil, err 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" // Append the network type to the data directory so it is "namespaced"
// per network. In addition to the block database, there are other // per network. In addition to the block database, there are other
// pieces of data that are saved to disk such as address manager state. // pieces of data that are saved to disk such as address manager state.

4
doc.go
View file

@ -108,6 +108,10 @@ Application Options:
--sigcachemaxsize= The maximum number of entries in the signature --sigcachemaxsize= The maximum number of entries in the signature
verification cache. verification cache.
--blocksonly Do not accept transactions from remote peers. --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: Help Options:
-h, --help Show this help message -h, --help Show this help message

View file

@ -238,6 +238,12 @@
; Do not accept transactions from remote peers. ; Do not accept transactions from remote peers.
; blocksonly=1 ; 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 ; Optional Transaction Indexes

View file

@ -2519,7 +2519,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param
txC := mempool.Config{ txC := mempool.Config{
Policy: mempool.Policy{ Policy: mempool.Policy{
DisableRelayPriority: cfg.NoRelayPriority, DisableRelayPriority: cfg.NoRelayPriority,
RelayNonStd: chainParams.RelayNonStdTxs, RelayNonStd: cfg.RelayNonStd,
FreeTxRelayLimit: cfg.FreeTxRelayLimit, FreeTxRelayLimit: cfg.FreeTxRelayLimit,
MaxOrphanTxs: cfg.MaxOrphanTxs, MaxOrphanTxs: cfg.MaxOrphanTxs,
MaxOrphanTxSize: defaultMaxOrphanTxSize, MaxOrphanTxSize: defaultMaxOrphanTxSize,