config: New option --blocksonly (#553)
The --blocksonly configuration option disables accepting transactions from remote peers. It will still accept, relay, and rebroadcast valid transactions sent via RPC or websockets.
This commit is contained in:
parent
7b31349023
commit
d1e493f4ee
5 changed files with 44 additions and 4 deletions
|
@ -132,6 +132,7 @@ type config struct {
|
||||||
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."`
|
||||||
NoPeerBloomFilters bool `long:"nopeerbloomfilters" description:"Disable bloom filtering support."`
|
NoPeerBloomFilters bool `long:"nopeerbloomfilters" description:"Disable bloom filtering support."`
|
||||||
SigCacheMaxSize uint `long:"sigcachemaxsize" description:"The maximum number of entries in the signature verification cache."`
|
SigCacheMaxSize uint `long:"sigcachemaxsize" description:"The maximum number of entries in the signature verification cache."`
|
||||||
|
BlocksOnly bool `long:"blocksonly" description:"Do not accept transactions from remote peers."`
|
||||||
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)
|
||||||
|
|
1
doc.go
1
doc.go
|
@ -112,6 +112,7 @@ Application Options:
|
||||||
--nopeerbloomfilters Disable bloom filtering support.
|
--nopeerbloomfilters Disable bloom filtering support.
|
||||||
--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.
|
||||||
|
|
||||||
Help Options:
|
Help Options:
|
||||||
-h, --help Show this help message
|
-h, --help Show this help message
|
||||||
|
|
|
@ -1660,8 +1660,8 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Debugf("Received unhandled message of type %v:",
|
log.Debugf("Received unhandled message of type %v "+
|
||||||
rmsg.Command())
|
"from %v", rmsg.Command(), p)
|
||||||
}
|
}
|
||||||
p.stallControl <- stallControlMsg{sccHandlerDone, rmsg}
|
p.stallControl <- stallControlMsg{sccHandlerDone, rmsg}
|
||||||
|
|
||||||
|
|
|
@ -233,6 +233,9 @@
|
||||||
; Limit orphan transaction pool to 1000 transactions.
|
; Limit orphan transaction pool to 1000 transactions.
|
||||||
; maxorphantx=1000
|
; maxorphantx=1000
|
||||||
|
|
||||||
|
; Do not accept transactions from remote peers.
|
||||||
|
; blocksonly=1
|
||||||
|
|
||||||
; ------------------------------------------------------------------------------
|
; ------------------------------------------------------------------------------
|
||||||
; Optional Transaction Indexes
|
; Optional Transaction Indexes
|
||||||
; ------------------------------------------------------------------------------
|
; ------------------------------------------------------------------------------
|
||||||
|
|
39
server.go
39
server.go
|
@ -440,6 +440,12 @@ func (sp *serverPeer) OnMemPool(p *peer.Peer, msg *wire.MsgMemPool) {
|
||||||
// handler this does not serialize all transactions through a single thread
|
// handler this does not serialize all transactions through a single thread
|
||||||
// transactions don't rely on the previous one in a linear fashion like blocks.
|
// transactions don't rely on the previous one in a linear fashion like blocks.
|
||||||
func (sp *serverPeer) OnTx(p *peer.Peer, msg *wire.MsgTx) {
|
func (sp *serverPeer) OnTx(p *peer.Peer, msg *wire.MsgTx) {
|
||||||
|
if cfg.BlocksOnly {
|
||||||
|
peerLog.Tracef("Ignoring tx %v from %v - blocksonly enabled",
|
||||||
|
msg.TxSha(), p)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Add the transaction to the known inventory for the peer.
|
// Add the transaction to the known inventory for the peer.
|
||||||
// Convert the raw MsgTx to a btcutil.Tx which provides some convenience
|
// Convert the raw MsgTx to a btcutil.Tx which provides some convenience
|
||||||
// methods and things such as hash caching.
|
// methods and things such as hash caching.
|
||||||
|
@ -487,7 +493,36 @@ func (sp *serverPeer) OnBlock(p *peer.Peer, msg *wire.MsgBlock, buf []byte) {
|
||||||
// accordingly. We pass the message down to blockmanager which will call
|
// accordingly. We pass the message down to blockmanager which will call
|
||||||
// QueueMessage with any appropriate responses.
|
// QueueMessage with any appropriate responses.
|
||||||
func (sp *serverPeer) OnInv(p *peer.Peer, msg *wire.MsgInv) {
|
func (sp *serverPeer) OnInv(p *peer.Peer, msg *wire.MsgInv) {
|
||||||
sp.server.blockManager.QueueInv(msg, sp)
|
if !cfg.BlocksOnly {
|
||||||
|
if len(msg.InvList) > 0 {
|
||||||
|
sp.server.blockManager.QueueInv(msg, sp)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
newInv := wire.NewMsgInvSizeHint(uint(len(msg.InvList)))
|
||||||
|
for _, invVect := range msg.InvList {
|
||||||
|
if invVect.Type == wire.InvTypeTx {
|
||||||
|
peerLog.Tracef("Ignoring tx %v in inv from %v -- "+
|
||||||
|
"blocksonly enabled", invVect.Hash, p)
|
||||||
|
if p.ProtocolVersion() >= wire.BIP0037Version {
|
||||||
|
peerLog.Infof("Peer %v is announcing "+
|
||||||
|
"transactions -- disconnecting", p)
|
||||||
|
p.Disconnect()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err := newInv.AddInvVect(invVect)
|
||||||
|
if err != nil {
|
||||||
|
peerLog.Errorf("Failed to add inventory vector: %v", err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(newInv.InvList) > 0 {
|
||||||
|
sp.server.blockManager.QueueInv(newInv, sp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnHeaders is invoked when a peer receives a headers bitcoin
|
// OnHeaders is invoked when a peer receives a headers bitcoin
|
||||||
|
@ -1450,7 +1485,7 @@ func newPeerConfig(sp *serverPeer) *peer.Config {
|
||||||
UserAgentVersion: userAgentVersion,
|
UserAgentVersion: userAgentVersion,
|
||||||
ChainParams: sp.server.chainParams,
|
ChainParams: sp.server.chainParams,
|
||||||
Services: sp.server.services,
|
Services: sp.server.services,
|
||||||
DisableRelayTx: false,
|
DisableRelayTx: cfg.BlocksOnly,
|
||||||
ProtocolVersion: 70011,
|
ProtocolVersion: 70011,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue