From 8a322e4792fd260b87318a144f805d0c500d91ac Mon Sep 17 00:00:00 2001 From: David Hill Date: Tue, 22 Apr 2014 15:52:36 -0400 Subject: [PATCH] Bypass rate limiter for sendrawtransaction. ok @davecgh --- blockmanager.go | 4 ++-- mempool.go | 14 +++++++------- rpcserver.go | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/blockmanager.go b/blockmanager.go index aabfad66..cc2ffa3e 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -444,7 +444,7 @@ func (b *blockManager) handleTxMsg(tmsg *txMsg) { // Process the transaction to include validation, insertion in the // memory pool, orphan handling, etc. - err := tmsg.peer.server.txMemPool.ProcessTransaction(tmsg.tx, true) + err := tmsg.peer.server.txMemPool.ProcessTransaction(tmsg.tx, true, true) // Remove transaction from request maps. Either the mempool/chain // already knows about it and as such we shouldn't have any more @@ -1086,7 +1086,7 @@ func (b *blockManager) handleNotifyMsg(notification *btcchain.Notification) { // Reinsert all of the transactions (except the coinbase) into // the transaction pool. for _, tx := range block.Transactions()[1:] { - err := b.server.txMemPool.MaybeAcceptTransaction(tx, nil, false) + err := b.server.txMemPool.MaybeAcceptTransaction(tx, nil, false, true) if err != nil { // Remove the transaction and all transactions // that depend on it if it wasn't accepted into diff --git a/mempool.go b/mempool.go index ee8c9502..809f028f 100644 --- a/mempool.go +++ b/mempool.go @@ -724,7 +724,7 @@ func (mp *txMemPool) FetchTransaction(txHash *btcwire.ShaHash) (*btcutil.Tx, err // more details. // // This function MUST be called with the mempool lock held (for writes). -func (mp *txMemPool) maybeAcceptTransaction(tx *btcutil.Tx, isOrphan *bool, isNew bool) error { +func (mp *txMemPool) maybeAcceptTransaction(tx *btcutil.Tx, isOrphan *bool, isNew, rateLimit bool) error { if isOrphan != nil { *isOrphan = false } @@ -867,7 +867,7 @@ func (mp *txMemPool) maybeAcceptTransaction(tx *btcutil.Tx, isOrphan *bool, isNe // Free-to-relay transactions are rate limited here to prevent // penny-flooding with tiny transactions as a form of attack. - if minRequiredFee == 0 { + if rateLimit && minRequiredFee == 0 { nowUnix := time.Now().Unix() // we decay passed data with an exponentially decaying ~10 // minutes window - matches bitcoind handling. @@ -919,12 +919,12 @@ func (mp *txMemPool) maybeAcceptTransaction(tx *btcutil.Tx, isOrphan *bool, isNe // or not the transaction is an orphan. // // This function is safe for concurrent access. -func (mp *txMemPool) MaybeAcceptTransaction(tx *btcutil.Tx, isOrphan *bool, isNew bool) error { +func (mp *txMemPool) MaybeAcceptTransaction(tx *btcutil.Tx, isOrphan *bool, isNew, rateLimit bool) error { // Protect concurrent access. mp.Lock() defer mp.Unlock() - return mp.maybeAcceptTransaction(tx, isOrphan, isNew) + return mp.maybeAcceptTransaction(tx, isOrphan, isNew, rateLimit) } // processOrphans determines if there are any orphans which depend on the passed @@ -964,7 +964,7 @@ func (mp *txMemPool) processOrphans(hash *btcwire.ShaHash) error { // Potentially accept the transaction into the // transaction pool. var isOrphan bool - err := mp.maybeAcceptTransaction(tx, &isOrphan, true) + err := mp.maybeAcceptTransaction(tx, &isOrphan, true, true) if err != nil { return err } @@ -993,7 +993,7 @@ func (mp *txMemPool) processOrphans(hash *btcwire.ShaHash) error { // rules, orphan transaction handling, and insertion into the memory pool. // // This function is safe for concurrent access. -func (mp *txMemPool) ProcessTransaction(tx *btcutil.Tx, allowOrphan bool) error { +func (mp *txMemPool) ProcessTransaction(tx *btcutil.Tx, allowOrphan, rateLimit bool) error { // Protect concurrent access. mp.Lock() defer mp.Unlock() @@ -1002,7 +1002,7 @@ func (mp *txMemPool) ProcessTransaction(tx *btcutil.Tx, allowOrphan bool) error // Potentially accept the transaction to the memory pool. var isOrphan bool - err := mp.maybeAcceptTransaction(tx, &isOrphan, true) + err := mp.maybeAcceptTransaction(tx, &isOrphan, true, rateLimit) if err != nil { return err } diff --git a/rpcserver.go b/rpcserver.go index 2e53decf..6c2ced06 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1381,7 +1381,7 @@ func handleSendRawTransaction(s *rpcServer, cmd btcjson.Cmd) (interface{}, error } tx := btcutil.NewTx(msgtx) - err = s.server.txMemPool.ProcessTransaction(tx, false) + err = s.server.txMemPool.ProcessTransaction(tx, false, false) if err != nil { // When the error is a rule error, it means the transaction was // simply rejected as opposed to something actually going wrong,