mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-05 17:05:50 +02:00
lnwallet+sweep: add new method CheckMempoolAcceptance
This commit is contained in:
@@ -1898,3 +1898,34 @@ func (b *BtcWallet) RemoveDescendants(tx *wire.MsgTx) error {
|
||||
return b.wallet.TxStore.RemoveUnminedTx(wtxmgrNs, txRecord)
|
||||
})
|
||||
}
|
||||
|
||||
// CheckMempoolAcceptance is a wrapper around `TestMempoolAccept` which checks
|
||||
// the mempool acceptance of a transaction.
|
||||
func (b *BtcWallet) CheckMempoolAcceptance(tx *wire.MsgTx) error {
|
||||
// Use a max feerate of 0 means the default value will be used when
|
||||
// testing mempool acceptance. The default max feerate is 0.10 BTC/kvb,
|
||||
// or 10,000 sat/vb.
|
||||
results, err := b.chain.TestMempoolAccept([]*wire.MsgTx{tx}, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Sanity check that the expected single result is returned.
|
||||
if len(results) != 1 {
|
||||
return fmt.Errorf("expected 1 result from TestMempoolAccept, "+
|
||||
"instead got %v", len(results))
|
||||
}
|
||||
|
||||
result := results[0]
|
||||
log.Debugf("TestMempoolAccept result: %s", spew.Sdump(result))
|
||||
|
||||
// Mempool check failed, we now map the reject reason to a proper RPC
|
||||
// error and return it.
|
||||
if !result.Allowed {
|
||||
err := rpcclient.MapRPCErr(errors.New(result.RejectReason))
|
||||
|
||||
return fmt.Errorf("mempool rejection: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user