{"record":{"id":"39b274815778e5ac","repo":"nautechsystems/nautilus_trader","slug":"finalized-swap-log-position-does-not-match-transac","errorCode":null,"errorMessage":"Finalized Swap log position does not match transaction {}","messagePattern":"Finalized Swap log position does not match transaction (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":4748,"sourceCode":"                && log.topics.first().is_some_and(|topic| topic == &signature)\n                && Address::from_str(&log.address).ok() == Some(plan.pool_address)\n        })\n        .collect::<Vec<_>>();\n    anyhow::ensure!(\n        swap_logs.len() == 1,\n        \"Finalized transaction {} emitted {} Swap logs from expected pool {}; expected exactly one\",\n        included.tx_hash,\n        swap_logs.len(),\n        plan.pool_address\n    );\n    let log = swap_logs[0];\n    let log_transaction_hash = B256::from_str(&rpc_log::extract_transaction_hash(log)?)\n        .with_context(|| \"Invalid finalized Swap log transaction hash\")?;\n    let log_block_hash = log\n        .block_hash\n        .as_deref()\n        .ok_or_else(|| anyhow::anyhow!(\"Finalized Swap log has no block hash\"))?;\n    anyhow::ensure!(\n        log_transaction_hash == included.tx_hash\n            && rpc_log::extract_block_number(log)? == included.block_number\n            && u64::from(rpc_log::extract_transaction_index(log)?)\n                == included.receipt.transaction_index\n            && B256::from_str(log_block_hash)\n                .with_context(|| \"Invalid finalized Swap log block hash\")?\n                == included.receipt.block_hash,\n        \"Finalized Swap log position does not match transaction {}\",\n        included.tx_hash\n    );\n\n    let dex = crate::exchanges::get_dex_extended(plan.pool.chain.name, &plan.pool.dex.name)\n        .ok_or_else(|| {\n            anyhow::anyhow!(\n                \"No RPC Swap decoder for {}:{}\",\n                plan.pool.chain.name,\n                plan.pool.dex.name\n            )","sourceCodeStart":4730,"sourceCodeEnd":4766,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/execution/client.rs#L4730-L4766","documentation":"This ensure! validates that the finalized Swap log's transaction hash, block number, transaction index, and block hash all match the verified inclusion receipt. When the position (tx hash / block number / tx index / block hash combination) disagrees, the log does not belong to the transaction the library tracked — a reorg, mismatched response, or parsing error.","triggerScenarios":"The RPC returned a Swap log whose transactionHash, blockNumber, transactionIndex or blockHash differs from included.tx_hash / included.block_number / included.receipt.transaction_index / included.receipt.block_hash — e.g. logs fetched for the wrong block range after a reorg.","commonSituations":"Chain reorganization moved the tx to another block; provider returned logs from a cached/stale block; mixing hex and decimal block numbers so the comparison fails; duplicate tx hashes across chains when querying the wrong network.","solutions":["Re-query logs/receipt after confirming chain finality; a reorg invalidates the previous inclusion data","Verify you query the same chain/network the plan's pool belongs to","Check that extract_block_number/extract_transaction_index parse hex-vs-decimal consistently with the provider","Restart verification from the receipt fetch so all fields come from one consistent response"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if log_tx_hash != included.tx_hash || log_block_number != included.block_number || log_tx_index as u64 != included.receipt.transaction_index { return Err(anyhow!(\"log position mismatch\")); }","typeGuard":null,"tryCatchPattern":"match verify_log_position(&log, &included) {\n    Err(e) if is_reorg_indicator(&e) => wait_for_finality_and_retry(tx_hash).await,\n    Err(e) => return Err(e),\n    Ok(()) => {},\n}","preventionTips":["Only verify logs after chain finality depth is reached","Fetch log and receipt from the same provider in one flow","Normalize hex/decimal parsing of block numbers and indices","Track reorg events and invalidate cached inclusion data"],"tags":["blockchain","consistency","reorg","receipt"],"backgroundTag":"internal-invariant-violation","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}