diff --git a/blockmanager.go b/blockmanager.go index 95cc7006..7ddc71ce 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -389,7 +389,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) + err := tmsg.peer.server.txMemPool.ProcessTransaction(tmsg.tx, true) // Remove transaction from request maps. Either the mempool/chain // already knows about it and as such we shouldn't have any more diff --git a/mempool.go b/mempool.go index 86828065..19709b32 100644 --- a/mempool.go +++ b/mempool.go @@ -999,7 +999,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) error { +func (mp *txMemPool) ProcessTransaction(tx *btcutil.Tx, allowOrphan bool) error { // Protect concurrent access. mp.Lock() defer mp.Unlock() @@ -1026,8 +1026,13 @@ func (mp *txMemPool) ProcessTransaction(tx *btcutil.Tx) error { return err } } else { - // When the transaction is an orphan (has inputs missing), - // potentially add it to the orphan pool. + // The transaction is an orphan (has inputs missing). Reject + // it if the flag to allow orphans is not set. + if !allowOrphan { + return TxRuleError("transaction spends unknown inputs") + } + + // Potentially add the orphan transaction to the orphan pool. err := mp.maybeAddOrphan(tx) if err != nil { return err diff --git a/rpcserver.go b/rpcserver.go index c3981a46..bad1c0c4 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1382,7 +1382,7 @@ func handleSendRawTransaction(s *rpcServer, cmd btcjson.Cmd) (interface{}, error } tx := btcutil.NewTx(msgtx) - err = s.server.txMemPool.ProcessTransaction(tx) + err = s.server.txMemPool.ProcessTransaction(tx, 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,