mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 05:05:41 +00:00
Read extrinsic dispatch result for mined transaction (#1582)
* read extrinsic dispatch result for mined transaction * commit for the history * Revert "commit for the history" This reverts commit 99341b04750639db296172cc1432bd70e458ef4b. * Revert "read extrinsic dispatch result for mined transaction" This reverts commit 662b776cbf992be9f1637e52f023b782e8c441d1. * check for successfult transaction in finality relay * check for successful transaction in parachains relay * TrackedTransactionStatus ->TrackedTransactionStatus<HeaderId> * check for successful transaction in messages relay * fix compilation * message_lane_loop_is_able_to_recover_from_unsuccessful_transaction * fixed too-complex-type clippy error * aaand compilation
This commit is contained in:
committed by
Bastian Köcher
parent
1abd5cb60d
commit
43afa02372
@@ -290,15 +290,55 @@ pub(crate) async fn run_until_connection_lost<P: FinalitySyncPipeline>(
|
||||
// wait till exit signal, or new source block
|
||||
select! {
|
||||
transaction_status = last_transaction_tracker => {
|
||||
if transaction_status == TrackedTransactionStatus::Lost {
|
||||
log::error!(
|
||||
target: "bridge",
|
||||
"Finality synchronization from {} to {} has stalled. Going to restart",
|
||||
P::SOURCE_NAME,
|
||||
P::TARGET_NAME,
|
||||
);
|
||||
match transaction_status {
|
||||
TrackedTransactionStatus::Finalized(_) => {
|
||||
// transaction has been finalized, but it may have been finalized in the "failed" state. So
|
||||
// let's check if the block number has been actually updated. If it is not, then we are stalled.
|
||||
//
|
||||
// please also note that we're restarting the loop if we have failed to read required data
|
||||
// from the target client - that's the best we can do here to avoid actual stall.
|
||||
target_client
|
||||
.best_finalized_source_block_id()
|
||||
.await
|
||||
.map_err(|e| format!("failed to read best block from target node: {:?}", e))
|
||||
.and_then(|best_id_at_target| {
|
||||
let last_submitted_header_number = last_submitted_header_number
|
||||
.expect("always Some when last_transaction_tracker is set;\
|
||||
last_transaction_tracker is set;\
|
||||
qed");
|
||||
if last_submitted_header_number > best_id_at_target.0 {
|
||||
Err(format!(
|
||||
"best block at target after tx is {:?} and we've submitted {:?}",
|
||||
best_id_at_target,
|
||||
last_submitted_header_number,
|
||||
))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
})
|
||||
.map_err(|e| {
|
||||
log::error!(
|
||||
target: "bridge",
|
||||
"Failed Finality synchronization from {} to {} has stalled. Transaction failed: {}. \
|
||||
Going to restart",
|
||||
P::SOURCE_NAME,
|
||||
P::TARGET_NAME,
|
||||
e,
|
||||
);
|
||||
|
||||
return Err(FailedClient::Both);
|
||||
FailedClient::Both
|
||||
})?;
|
||||
},
|
||||
TrackedTransactionStatus::Lost => {
|
||||
log::error!(
|
||||
target: "bridge",
|
||||
"Finality synchronization from {} to {} has stalled. Going to restart",
|
||||
P::SOURCE_NAME,
|
||||
P::TARGET_NAME,
|
||||
);
|
||||
|
||||
return Err(FailedClient::Both);
|
||||
},
|
||||
}
|
||||
},
|
||||
_ = async_std::task::sleep(next_tick).fuse() => {},
|
||||
|
||||
@@ -48,17 +48,19 @@ type TestNumber = u64;
|
||||
type TestHash = u64;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct TestTransactionTracker(TrackedTransactionStatus);
|
||||
struct TestTransactionTracker(TrackedTransactionStatus<HeaderId<TestHash, TestNumber>>);
|
||||
|
||||
impl Default for TestTransactionTracker {
|
||||
fn default() -> TestTransactionTracker {
|
||||
TestTransactionTracker(TrackedTransactionStatus::Finalized)
|
||||
TestTransactionTracker(TrackedTransactionStatus::Finalized(Default::default()))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl TransactionTracker for TestTransactionTracker {
|
||||
async fn wait(self) -> TrackedTransactionStatus {
|
||||
type HeaderId = HeaderId<TestHash, TestNumber>;
|
||||
|
||||
async fn wait(self) -> TrackedTransactionStatus<HeaderId<TestHash, TestNumber>> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
@@ -224,7 +226,9 @@ fn prepare_test_clients(
|
||||
|
||||
target_best_block_id: HeaderId(5, 5),
|
||||
target_headers: vec![],
|
||||
target_transaction_tracker: TestTransactionTracker(TrackedTransactionStatus::Finalized),
|
||||
target_transaction_tracker: TestTransactionTracker(TrackedTransactionStatus::Finalized(
|
||||
Default::default(),
|
||||
)),
|
||||
}));
|
||||
(
|
||||
TestSourceClient {
|
||||
@@ -581,3 +585,13 @@ fn stalls_when_transaction_tracker_returns_error() {
|
||||
|
||||
assert_eq!(result, Err(FailedClient::Both));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stalls_when_transaction_tracker_returns_finalized_but_transaction_fails() {
|
||||
let (_, result) = run_sync_loop(|data| {
|
||||
data.target_best_block_id = HeaderId(5, 5);
|
||||
data.target_best_block_id.0 == 16
|
||||
});
|
||||
|
||||
assert_eq!(result, Err(FailedClient::Both));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user