Do not treat pending-block receipts as confirmed (fixes #165) - #749
Open
JSap0914 wants to merge 1 commit into
Open
Do not treat pending-block receipts as confirmed (fixes #165)#749JSap0914 wants to merge 1 commit into
JSap0914 wants to merge 1 commit into
Conversation
send_transaction_with_confirmation short-circuited the confirmation wait whenever confirmations == 0 and returned the first receipt from eth_getTransactionReceipt directly. For a transaction that is still part of a pending block the node returns a receipt whose block_hash and block_number are null, so that pending receipt was reported as a confirmed result. Always run wait_for_confirmations so the transaction must be mined into a block (block_number present) before its receipt is returned, including the confirmations == 0 case. Add a mocked-transport regression test covering the pending-then-mined sequence. Fixes tomusdrw#165
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.
Problem
send_transaction_with_confirmation(andsend_raw_transaction_with_confirmation) could report a pending transaction as confirmed.When
confirmations == 0the function skippedwait_for_confirmationsentirely and returned the first receipt frometh_getTransactionReceipt. As noted in #165, a node returns a receipt withblockHash/blockNumberset tonullfor a transaction that is only part of a pending block. That pending receipt was returned as the confirmed result instead of waiting for the transaction to actually be mined.Fix
Always run
wait_for_confirmations, including forconfirmations == 0.wait_for_confirmationsalready only treats a receipt as confirmed onceblock_numberis present (viatransaction_receipt_block_number_check), so the call now waits for the transaction to be mined into a block before returning its receipt.Test
Added a mocked-transport regression test (
test_send_transaction_with_confirmation_ignores_pending_receipt) that drives a pending-then-mined sequence withconfirmations == 0: the firsteth_getTransactionReceiptreturns a receipt with nullblockHash/blockNumber(must not confirm), polling continues, and the subsequently mined receipt is returned. The test fails against the previous code (it returned the pending receipt without ever creating a block filter) and passes with this change.cargo fmt -- --checkis clean; no new clippy warnings introduced.Fixes #165