{
 "number": 36408,
 "repo": "bitcoin/bitcoin",
 "url": "https://github.com/bitcoin/bitcoin/pull/36408",
 "title": "test: allow 3 bytes of fee overestimate in assert_fee_amount",
 "author": "fametrano",
 "author_association": "FIRST_TIME_CONTRIBUTOR",
 "created_at": "2026-10-02T06:53:12Z",
 "updated_at": "2026-11-01T19:04:28Z",
 "description_hash": "5124d3c73fa017e2",
 "age_days": 30,
 "draft": false,
 "labels": [
  "Tests"
 ],
 "milestone": null,
 "base": "master",
 "head_sha": "050409b2c5522eff0dc37c00a6d1225a8a437e17",
 "head_ref": "test-fee-tolerance-short-sig",
 "head_repo": "fametrano/bitcoin",
 "head_history": [],
 "additions": 3,
 "deletions": 2,
 "changed_files": 1,
 "commit_count": 1,
 "size_bucket": "S",
 "mergeable_state": "clean",
 "bot": {
  "drahtbot": {
   "present": true,
   "reviews": {
    "ack": [
     {
      "login": "Ayoazeez26",
      "url": "https://github.com/bitcoin/bitcoin/pull/36408#issuecomment-5981997800"
     }
    ]
   },
   "conflicts": []
  }
 },
 "acks_parsed": {},
 "acks_tally": {
  "ack": 0,
  "stale_ack": 0,
  "concept_ack": 0,
  "approach_ack": 0,
  "nack": 0,
  "concept_nack": 0,
  "approach_nack": 0
 },
 "reviews": {
  "approved": 0,
  "changes_requested": 0,
  "distinct_reviewers": [
   "Ayoazeez26"
  ]
 },
 "signals": {
  "needs_rebase": false,
  "ci_failed": false,
  "mergeable_state": "clean",
  "last_author_activity": "2026-11-01T19:04:28Z",
  "last_reviewer_activity": "2026-10-04T16:17:10Z",
  "last_reviewer": "Ayoazeez26",
  "author_silent_days": 0,
  "waiting_on_author_days": 0,
  "days_since_update": 0
 },
 "refs": {
  "mentioned": [
   24151,
   25164,
   36394
  ],
  "depends_on": [],
  "fixes": [
   36394
  ],
  "linked_issues": [
   {
    "number": 36394,
    "type": "issue",
    "state": "open",
    "merged": false,
    "merged_at": null,
    "title": "Intermittent CI failure in wallet_send.py, in , line 329, in run_test                                        assert_fee_amount(fee, count_bytes(res[\\\"hex\\\"]), Decimal(\\\"0.00002\\\")),                                    AssertionError: Fee of 0.00000438 BTC too high! (Should be 0.00000432 BTC)"
   }
  ],
  "references": [
   {
    "number": 36394,
    "type": "issue",
    "state": "open",
    "merged": false,
    "merged_at": null,
    "title": "Intermittent CI failure in wallet_send.py, in , line 329, in run_test                                        assert_fee_amount(fee, count_bytes(res[\\\"hex\\\"]), Decimal(\\\"0.00002\\\")),                                    AssertionError: Fee of 0.00000438 BTC too high! (Should be 0.00000432 BTC)"
   },
   {
    "number": 24151,
    "type": "issue",
    "state": "closed",
    "merged": false,
    "merged_at": null,
    "title": "\\\"Fee too high\\\" CI error in wallet_send.py"
   },
   {
    "number": 25164,
    "type": "issue",
    "state": "closed",
    "merged": false,
    "merged_at": null,
    "title": "Intermittent CI failure \\\"fee too high\\\" in wallet_send.py"
   }
  ],
  "conflicts": []
 },
 "stack": {
  "shares_commits_with": [],
  "based_on": [],
  "base_for": []
 },
 "review_paths": [],
 "body": "The wallet sizes a transaction assuming a 71-byte low-R ECDSA signature. A signature whose r or s has leading zero bytes is shorter, so the fee can cover a few bytes more than the signed transaction needs. In #36394 the wallet estimated 219 bytes and paid 438 sat at 2 sat/vB, but the signed transaction was 216 bytes: the signature was 3 bytes short. That happens about once in 4 million signatures. `assert_fee_amount` allows only 2 bytes of overestimate, so the test failed.\n\nI raise the allowance to 3 bytes, which makes the failure about 200 times rarer. The check that the fee is not too low is unchanged. @maflcko suggested 3 bytes in #24151 and #25164.\n\nFixes #36394.\n\n*Made with my usual tools: a computer, the Internet and an LLM. The mistakes, as usual, are all mine.*",
 "commits": [
  {
   "sha": "050409b2c5522eff0dc37c00a6d1225a8a437e17",
   "date": "2026-10-02T06:52:58Z",
   "message": "test: allow 3 bytes of fee overestimate in assert_fee_amount\n\nThe wallet sizes a transaction assuming 71-byte low-R ECDSA signatures.\nA signature whose r or s has leading zero bytes is shorter, so the fee\ncan cover a few bytes more than the signed transaction needs. A\nsignature 3 bytes short (about 1 in 4 million) made wallet_send.py fail\nwith an estimate of 219 bytes for a 216-byte transaction.\n\nAllowing 3 bytes instead of 2 makes this about 200 times rarer. The\ncheck that the fee is not too low is unchanged.\n\nFixes #36394."
  }
 ],
 "timeline": [
  {
   "t": "2026-10-04T16:17:10Z",
   "kind": "comment",
   "who": "Ayoazeez26",
   "assoc": "NONE",
   "text": "tACK 050409b2c5522eff0dc37c00a6d1225a8a437e17\n\nTested on macOS with Python 3.14. `wallet_send.py` passes on this commit.\n\nI read through #36394 and the CI log there. Since running the test won't reproduce it (a 3-byte short signature is roughly 1 in 4 million), so I forced it instead by bumping the signature size in `PKHDescriptor::MaxSatSize()` from 71 to 74. That makes the wallet overestimate by 3 bytes on every run.\n\nOn master with that change, `wallet_send.py` fails at the `fee_rate=7` check:\n\n    AssertionError: Fee of 0.00001554 BTC too high! (Should be 0.00001533 BTC)\n\nWith 73 (+2) instead, the old check passes, as expected.\n\nWith this PR and the same +3 change, all the `assert_fee_amount` checks pass. One more thing I noticed, with the +3 change, the run gets past all the fee checks but then fails in `test_maxfeerate()` with this error:\n\n     test_framework.util.JSONRPCException: Fee rate exceeds maximum configured by user (maxfeerate) (-6)  [http_status=200]\n\nThis is most likely from my +3 change but I thought it's worth noting.",
   "id": "c:5981997800",
   "url": "https://github.com/bitcoin/bitcoin/pull/36408#issuecomment-5981997800",
   "hash": "c4e000755eb68033",
   "edited": null
  },
  {
   "t": "2026-11-01T19:04:28Z",
   "kind": "comment",
   "who": "fametrano",
   "assoc": "NONE",
   "text": "The `test_maxfeerate()` failure comes from your +3 change in `MaxSatSize()`, not from this PR. Thanks for testing.\n\nI ran `wallet_send.py` on 050409b2c5: unchanged it passes; with `PKHDescriptor::MaxSatSize()` bumped from 71 to 74 it fails as yours did. The `fee_rate=7` check passes (1554 sat for 222 estimated vbytes, against 1533), and `test_maxfeerate()` fails at its last call, `fee_rate=1.000` under `-maxfeerate=0.00001009`. The wallet sets the fee from the estimated size, but checks `-maxfeerate` against the signed one, here 218 or 219 vbytes: 222 sat is at least 1.013 sat/vB, over the 1.009 cap. This PR only changes `assert_fee_amount`, which `test_maxfeerate()` does not call.",
   "id": "c:6562492763",
   "url": "https://github.com/bitcoin/bitcoin/pull/36408#issuecomment-6562492763",
   "hash": "765e886df4364341",
   "edited": null
  }
 ],
 "labels_log": [
  {
   "t": "2026-10-02T06:53:16Z",
   "action": "labeled",
   "label": "Tests",
   "who": "DrahtBot"
  }
 ],
 "state_log": [],
 "text_chars": 3115,
 "text_tokens_estimate": 778,
 "changed_paths": [
  "test/functional/test_framework/util.py"
 ],
 "files": [
  {
   "path": "test/functional/test_framework/util.py",
   "add": 3,
   "del": 2
  }
 ],
 "test_lines": 5,
 "git": {
  "head": "050409b2c5522eff0dc37c00a6d1225a8a437e17",
  "head_matches_backup": true,
  "base": "7988380da987c0b860885853ace8149b84ac2ee8",
  "patch_id": "9c514af7aece5adf",
  "commits": [
   {
    "sha": "050409b2c5",
    "subject": "test: allow 3 bytes of fee overestimate in assert_fee_amount",
    "files": 1,
    "add": 3,
    "del": 2
   }
  ],
  "patch_truncated": false
 },
 "patch_id": "9c514af7aece5adf",
 "input_hash": "e93cdb538eb209d0",
 "extracted_at": "2026-11-02T01:09:49+00:00"
}