Skip to content

fix rbf calculation - fixes #2010 #2011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2020

Conversation

psq
Copy link
Contributor

@psq psq commented Oct 28, 2020

Fixes #2010. Current calculation overpays by a factor of 2048 (should use attempt-1 as multiplier, and fee is per kb, not per byte

@psq psq requested a review from jcnelson October 28, 2020 05:55
@psq psq self-assigned this Oct 28, 2020
@@ -664,7 +664,7 @@ impl BitcoinRegtestController {

// RBF
let tx_fee = self.config.burnchain.burnchain_op_tx_fee
+ (attempt * self.last_tx_len * self.min_relay_fee);
+ ((attempt - 1) * self.last_tx_len * self.min_relay_fee / 1024);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For good measure, can you change attempt - 1 to attempt.saturating_sub(1) so it doesn't ever underflow?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can you group the numerator explicitly? I.e. ((attempt.saturating_sub(1) * self.last_tx_len * self.min_relay_fee) / 1024);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea. addressed in 00d7880

@jcnelson
Copy link
Member

Thanks for catching this @psq! Are you able to mine blocks on the testnet with these settings?

Once my comment is addressed this will LGTM.

@psq
Copy link
Contributor Author

psq commented Oct 30, 2020

Are you able to mine blocks on the testnet with these settings

yes, the miner is mining, but I'm no sure it is the second transaction is the one accepted when there is a second attempt based on how the UTXO seem to get updated, so I'll dig deeper tomorrow.

@psq
Copy link
Contributor Author

psq commented Oct 30, 2020

seems to work fine, I changed the code to send 2 sats more per new attempt, and the replaced transaction is the one that gets committed, not the original one. So all good.

bitcoin-cli -regtest -conf=/Users/psq/src/perso/stacks-blockchain/bitcoin.conf -rpcport=19443 gettransaction f39adee67e803ee2faeec0d6733c8f6b905f34881e2d8ebdca7aeac8dc90d598 true
{
  "amount": -0.00022002,
  "fee": -0.00005852,
  "confirmations": 446,
  "blockhash": "291bf835aafebd56eb8e6529f821c82b1815fc61e16a407243520df9cb9c8e36",
  "blockheight": 3015,
  "blockindex": 7,
  "blocktime": 1604047618,
  "txid": "f39adee67e803ee2faeec0d6733c8f6b905f34881e2d8ebdca7aeac8dc90d598",
  "walletconflicts": [
  ],
  "time": 1604047618,
  "timereceived": 1604100263,
  "bip125-replaceable": "no",
  "details": [
    {
      "involvesWatchonly": true,
      "category": "send",
      "amount": 0.00000000,
      "vout": 0,
      "fee": -0.00005852,
      "abandoned": false
    },
    {
      "involvesWatchonly": true,
      "address": "mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8",
      "category": "send",
      "amount": -0.00011001,
      "vout": 1,
      "fee": -0.00005852,
      "abandoned": false
    },
    {
      "involvesWatchonly": true,
      "address": "mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8",
      "category": "send",
      "amount": -0.00011001,
      "vout": 2,
      "fee": -0.00005852,
      "abandoned": false
    },
    {
      "involvesWatchonly": true,
      "address": "mxtGS9DHV2TafucTmcDJhNipRZ7svFoi7C",
      "category": "send",
      "amount": -0.40695581,
      "label": "",
      "vout": 3,
      "fee": -0.00005852,
      "abandoned": false
    },
    {
      "involvesWatchonly": true,
      "address": "mxtGS9DHV2TafucTmcDJhNipRZ7svFoi7C",
      "category": "receive",
      "amount": 0.40695581,
      "label": "",
      "vout": 3
    }
  ],
  "hex": "01000000016740ed391ace48d0025eb8f67cbb9c0cb44d08067b074c3cd245733830a784f1030000006a47304402201894cce7b5c9d30d961891751f3beb1d2f65aa8c7ccf80de5b2a8d57032c6e6f0220610e266761a28c2fd5391661f074000882f8ec28ccb2f5e17356f8b71d17f1b0012103c74baf92e45c41c5d16022165753f015b032b0bce30dc848d2a3495128800ccafdffffff040000000000000000536a4c5069645b26fae0a3d035f2f2a891f1fcdd667ac9755cd5709c305bf9e3e173d0db065bac81488024f279e4e99f36fff6c7cc62a4853222e1ce66cec8b925986aa051cd6b00000bc5001300000bc6000d00f92a0000000000001976a914000000000000000000000000000000000000000088acf92a0000000000001976a914000000000000000000000000000000000000000088ac1df76c02000000001976a914be8203fccbca453e0b0dd4edc919451c7895764088ac00000000"
}

you can see 11_001 per address instead of 11_000, and the first transaction is not found.

Copy link
Member

@jcnelson jcnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @psq!

Copy link
Contributor

@kantai kantai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jcnelson jcnelson merged commit ec2472d into stacks-network:master Nov 2, 2020
@blockstack-devops
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@stacks-network stacks-network locked as resolved and limited conversation to collaborators Nov 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TESTNET BUG] RBF fee calculation spends too much
4 participants