Reject orphan transactions from sendrawtransaction.

This commit modifies the sendrawtransaction RPC to reject transactions
which are orphans.  This mirrors the behavior of the reference
implementation.
This commit is contained in:
Dave Collins 2014-03-17 17:32:30 -05:00
parent a87e6fbdea
commit 7a885b3cf6
3 changed files with 10 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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,