mirror of
https://github.com/LBRYFoundation/lbcd.git
synced 2025-08-23 17:47:24 +00:00
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:
parent
a87e6fbdea
commit
7a885b3cf6
3 changed files with 10 additions and 5 deletions
|
@ -389,7 +389,7 @@ func (b *blockManager) handleTxMsg(tmsg *txMsg) {
|
||||||
|
|
||||||
// Process the transaction to include validation, insertion in the
|
// Process the transaction to include validation, insertion in the
|
||||||
// memory pool, orphan handling, etc.
|
// 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
|
// Remove transaction from request maps. Either the mempool/chain
|
||||||
// already knows about it and as such we shouldn't have any more
|
// already knows about it and as such we shouldn't have any more
|
||||||
|
|
11
mempool.go
11
mempool.go
|
@ -999,7 +999,7 @@ func (mp *txMemPool) processOrphans(hash *btcwire.ShaHash) error {
|
||||||
// rules, orphan transaction handling, and insertion into the memory pool.
|
// rules, orphan transaction handling, and insertion into the memory pool.
|
||||||
//
|
//
|
||||||
// This function is safe for concurrent access.
|
// 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.
|
// Protect concurrent access.
|
||||||
mp.Lock()
|
mp.Lock()
|
||||||
defer mp.Unlock()
|
defer mp.Unlock()
|
||||||
|
@ -1026,8 +1026,13 @@ func (mp *txMemPool) ProcessTransaction(tx *btcutil.Tx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// When the transaction is an orphan (has inputs missing),
|
// The transaction is an orphan (has inputs missing). Reject
|
||||||
// potentially add it to the orphan pool.
|
// 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)
|
err := mp.maybeAddOrphan(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -1382,7 +1382,7 @@ func handleSendRawTransaction(s *rpcServer, cmd btcjson.Cmd) (interface{}, error
|
||||||
}
|
}
|
||||||
|
|
||||||
tx := btcutil.NewTx(msgtx)
|
tx := btcutil.NewTx(msgtx)
|
||||||
err = s.server.txMemPool.ProcessTransaction(tx)
|
err = s.server.txMemPool.ProcessTransaction(tx, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// When the error is a rule error, it means the transaction was
|
// When the error is a rule error, it means the transaction was
|
||||||
// simply rejected as opposed to something actually going wrong,
|
// simply rejected as opposed to something actually going wrong,
|
||||||
|
|
Loading…
Add table
Reference in a new issue