smite: retry mine_block_including on mempool eviction - #272
Merged
Merged
Conversation
mine_block_including snapshots the mempool and passes the txids to generateblock. If the target RBF fee-bumps a transaction between the two calls, generateblock fails with "not in mempool". Retry with a fresh mempool snapshot up to 3 times. RBF replacement is atomic, so a single retry should succeed. The extra attempt is a buffer. Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
morehouse
approved these changes
Sep 29, 2026
Comment on lines
+162
to
+185
| for attempt in 1..=MAX_ATTEMPTS { | ||
| let mut txs = self.get_raw_mempool(); | ||
| txs.extend_from_slice(private_mempool); | ||
| let txs_json = serde_json::to_string(&txs).expect("tx list serializes to valid JSON"); | ||
|
|
||
| let gen_out = self | ||
| .run() | ||
| .arg("generateblock") | ||
| .arg(address.to_string()) | ||
| .arg(&txs_json) | ||
| .output() | ||
| .expect("bitcoin-cli generateblock should not fail"); | ||
| if gen_out.status.success() { | ||
| return; | ||
| } | ||
|
|
||
| // Only retry if a snapshotted transaction left the mempool (e.g. | ||
| // replaced by an RBF fee bump) before the block was generated. | ||
| let stderr = String::from_utf8_lossy(&gen_out.stderr); | ||
| assert!( | ||
| stderr.contains("not in mempool") && attempt < MAX_ATTEMPTS, | ||
| "bitcoin-cli generateblock failed: {stderr}" | ||
| ); | ||
| } |
Collaborator
There was a problem hiding this comment.
style nit:
Suggested change
| for attempt in 1..=MAX_ATTEMPTS { | |
| let mut txs = self.get_raw_mempool(); | |
| txs.extend_from_slice(private_mempool); | |
| let txs_json = serde_json::to_string(&txs).expect("tx list serializes to valid JSON"); | |
| let gen_out = self | |
| .run() | |
| .arg("generateblock") | |
| .arg(address.to_string()) | |
| .arg(&txs_json) | |
| .output() | |
| .expect("bitcoin-cli generateblock should not fail"); | |
| if gen_out.status.success() { | |
| return; | |
| } | |
| // Only retry if a snapshotted transaction left the mempool (e.g. | |
| // replaced by an RBF fee bump) before the block was generated. | |
| let stderr = String::from_utf8_lossy(&gen_out.stderr); | |
| assert!( | |
| stderr.contains("not in mempool") && attempt < MAX_ATTEMPTS, | |
| "bitcoin-cli generateblock failed: {stderr}" | |
| ); | |
| } | |
| for attempt in 0..MAX_ATTEMPTS { | |
| let mut txs = self.get_raw_mempool(); | |
| txs.extend_from_slice(private_mempool); | |
| let txs_json = serde_json::to_string(&txs).expect("tx list serializes to valid JSON"); | |
| let gen_out = self | |
| .run() | |
| .arg("generateblock") | |
| .arg(address.to_string()) | |
| .arg(&txs_json) | |
| .output() | |
| .expect("bitcoin-cli generateblock should not fail"); | |
| if gen_out.status.success() { | |
| return; | |
| } | |
| // Only retry if a snapshotted transaction left the mempool (e.g. | |
| // replaced by an RBF fee bump) before the block was generated. | |
| let stderr = String::from_utf8_lossy(&gen_out.stderr); | |
| assert!(stderr.contains("not in mempool"), "bitcoin-cli generateblock failed: {stderr}"); | |
| } | |
| panic!("bitcoin-cli generateblock failed {MAX_ATTEMPTS} times: mempool kept changing"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: #237
mine_block_includingsnapshots the mempool and passes the txids togenerateblock. If the target RBF fee-bumps a transaction between the two calls,generateblockfails withnot in mempool.Retry with a fresh mempool snapshot up to 3 times. RBF replacement is atomic, so a single retry should succeed. The extra attempt is a buffer.