You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rbf.cpp 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) 2016 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #include "policy/rbf.h"
  5. bool SignalsOptInRBF(const CTransaction &tx)
  6. {
  7. for (const CTxIn &txin : tx.vin) {
  8. if (txin.nSequence < std::numeric_limits<unsigned int>::max()-1) {
  9. return true;
  10. }
  11. }
  12. return false;
  13. }
  14. RBFTransactionState IsRBFOptIn(const CTransaction &tx, CTxMemPool &pool)
  15. {
  16. AssertLockHeld(pool.cs);
  17. CTxMemPool::setEntries setAncestors;
  18. // First check the transaction itself.
  19. if (SignalsOptInRBF(tx)) {
  20. return RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125;
  21. }
  22. // If this transaction is not in our mempool, then we can't be sure
  23. // we will know about all its inputs.
  24. if (!pool.exists(tx.GetHash())) {
  25. return RBF_TRANSACTIONSTATE_UNKNOWN;
  26. }
  27. // If all the inputs have nSequence >= maxint-1, it still might be
  28. // signaled for RBF if any unconfirmed parents have signaled.
  29. uint64_t noLimit = std::numeric_limits<uint64_t>::max();
  30. std::string dummy;
  31. CTxMemPoolEntry entry = *pool.mapTx.find(tx.GetHash());
  32. pool.CalculateMemPoolAncestors(entry, setAncestors, noLimit, noLimit, noLimit, noLimit, dummy, false);
  33. for (CTxMemPool::txiter it : setAncestors) {
  34. if (SignalsOptInRBF(it->GetTx())) {
  35. return RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125;
  36. }
  37. }
  38. return RBF_TRANSACTIONSTATE_FINAL;
  39. }