From 1d1470f11f29967ec68711243296c00235d14706 Mon Sep 17 00:00:00 2001 From: James Wilson Date: Tue, 12 Nov 2024 18:15:46 +0000 Subject: [PATCH 1/3] Fix unstable-light-client + ChainHeadBackend tx events --- subxt/src/backend/chain_head/mod.rs | 4 ++-- subxt/src/backend/chain_head/rpc_methods.rs | 7 +------ subxt/src/backend/legacy/mod.rs | 6 ++---- subxt/src/backend/mod.rs | 5 +---- subxt/src/tx/tx_progress.rs | 13 +++++-------- 5 files changed, 11 insertions(+), 24 deletions(-) diff --git a/subxt/src/backend/chain_head/mod.rs b/subxt/src/backend/chain_head/mod.rs index 5b6145227a..a77e21c6b5 100644 --- a/subxt/src/backend/chain_head/mod.rs +++ b/subxt/src/backend/chain_head/mod.rs @@ -682,8 +682,8 @@ impl Backend for ChainHeadBackend { rpc_methods::TransactionStatus::BestChainBlockIncluded { block: None } => { TransactionStatus::NoLongerInBestBlock } - rpc_methods::TransactionStatus::Broadcasted { num_peers } => { - TransactionStatus::Broadcasted { num_peers } + rpc_methods::TransactionStatus::Broadcasted => { + TransactionStatus::Broadcasted } rpc_methods::TransactionStatus::Dropped { error, .. } => { TransactionStatus::Dropped { message: error } diff --git a/subxt/src/backend/chain_head/rpc_methods.rs b/subxt/src/backend/chain_head/rpc_methods.rs index dff0a86503..eb6ea38fc0 100644 --- a/subxt/src/backend/chain_head/rpc_methods.rs +++ b/subxt/src/backend/chain_head/rpc_methods.rs @@ -709,10 +709,7 @@ pub enum TransactionStatus { /// Transaction is part of the future queue. Validated, /// The transaction has been broadcast to other nodes. - Broadcasted { - /// Number of peers it's been broadcast to. - num_peers: u32, - }, + Broadcasted, /// Transaction has been included in block with given details. /// Null is returned if the transaction is no longer in any block /// of the best chain. @@ -737,8 +734,6 @@ pub enum TransactionStatus { }, /// The transaction was dropped. Dropped { - /// Was the transaction broadcasted to other nodes before being dropped? - broadcasted: bool, /// Human readable message; why was it dropped. error: String, }, diff --git a/subxt/src/backend/legacy/mod.rs b/subxt/src/backend/legacy/mod.rs index c4145aafc4..77cdd0b339 100644 --- a/subxt/src/backend/legacy/mod.rs +++ b/subxt/src/backend/legacy/mod.rs @@ -354,10 +354,8 @@ impl Backend for LegacyBackend { RpcTransactionStatus::Retracted(_) => None, // These roughly map across: RpcTransactionStatus::Ready => Some(TransactionStatus::Validated), - RpcTransactionStatus::Broadcast(peers) => { - Some(TransactionStatus::Broadcasted { - num_peers: peers.len() as u32, - }) + RpcTransactionStatus::Broadcast(_peers) => { + Some(TransactionStatus::Broadcasted) } RpcTransactionStatus::InBlock(hash) => { Some(TransactionStatus::InBestBlock { diff --git a/subxt/src/backend/mod.rs b/subxt/src/backend/mod.rs index e37cfde8d3..a8b1d1c426 100644 --- a/subxt/src/backend/mod.rs +++ b/subxt/src/backend/mod.rs @@ -290,10 +290,7 @@ pub enum TransactionStatus { /// Transaction is part of the future queue. Validated, /// The transaction has been broadcast to other nodes. - Broadcasted { - /// Number of peers it's been broadcast to. - num_peers: u32, - }, + Broadcasted, /// Transaction is no longer in a best block. NoLongerInBestBlock, /// Transaction has been included in block with given hash. diff --git a/subxt/src/tx/tx_progress.rs b/subxt/src/tx/tx_progress.rs index f4d2ed9ab9..ae9f74edb5 100644 --- a/subxt/src/tx/tx_progress.rs +++ b/subxt/src/tx/tx_progress.rs @@ -135,7 +135,7 @@ impl Stream for TxProgress { sub.poll_next_unpin(cx).map_ok(|status| { match status { BackendTxStatus::Validated => TxStatus::Validated, - BackendTxStatus::Broadcasted { num_peers } => TxStatus::Broadcasted { num_peers }, + BackendTxStatus::Broadcasted => TxStatus::Broadcasted, BackendTxStatus::NoLongerInBestBlock => TxStatus::NoLongerInBestBlock, BackendTxStatus::InBestBlock { hash } => { TxStatus::InBestBlock(TxInBlock::new(hash, self.ext_hash, self.client.clone())) @@ -172,10 +172,7 @@ pub enum TxStatus { /// Transaction is part of the future queue. Validated, /// The transaction has been broadcast to other nodes. - Broadcasted { - /// Number of peers it's been broadcast to. - num_peers: u32, - }, + Broadcasted, /// Transaction is no longer in a best block. NoLongerInBestBlock, /// Transaction has been included in block with given hash. @@ -363,7 +360,7 @@ mod test { #[tokio::test] async fn wait_for_finalized_returns_err_when_error() { let tx_progress = mock_tx_progress(vec![ - MockSubstrateTxStatus::Broadcasted { num_peers: 2 }, + MockSubstrateTxStatus::Broadcasted, MockSubstrateTxStatus::Error { message: "err".into(), }, @@ -378,7 +375,7 @@ mod test { #[tokio::test] async fn wait_for_finalized_returns_err_when_invalid() { let tx_progress = mock_tx_progress(vec![ - MockSubstrateTxStatus::Broadcasted { num_peers: 2 }, + MockSubstrateTxStatus::Broadcasted, MockSubstrateTxStatus::Invalid { message: "err".into(), }, @@ -393,7 +390,7 @@ mod test { #[tokio::test] async fn wait_for_finalized_returns_err_when_dropped() { let tx_progress = mock_tx_progress(vec![ - MockSubstrateTxStatus::Broadcasted { num_peers: 2 }, + MockSubstrateTxStatus::Broadcasted, MockSubstrateTxStatus::Dropped { message: "err".into(), }, From 07f9ff09fd540cdbfe7c2e7aaa262ed476ba003e Mon Sep 17 00:00:00 2001 From: James Wilson Date: Tue, 12 Nov 2024 18:28:46 +0000 Subject: [PATCH 2/3] Add note that Broadcasted event should no longer be returned at all --- subxt/src/backend/chain_head/rpc_methods.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/subxt/src/backend/chain_head/rpc_methods.rs b/subxt/src/backend/chain_head/rpc_methods.rs index eb6ea38fc0..e8f39d3405 100644 --- a/subxt/src/backend/chain_head/rpc_methods.rs +++ b/subxt/src/backend/chain_head/rpc_methods.rs @@ -709,6 +709,10 @@ pub enum TransactionStatus { /// Transaction is part of the future queue. Validated, /// The transaction has been broadcast to other nodes. + /// + /// Note: This event is no longer expected to be returned as of + /// the chainHead_v1 spec, but we do so for compatibility with + /// older versions of Smoldot, which do return it. Broadcasted, /// Transaction has been included in block with given details. /// Null is returned if the transaction is no longer in any block From d806dcd0be77088a6b7f6675e64a30173be020aa Mon Sep 17 00:00:00 2001 From: James Wilson Date: Tue, 12 Nov 2024 18:32:12 +0000 Subject: [PATCH 3/3] fmt --- subxt/src/backend/chain_head/mod.rs | 4 +--- subxt/src/backend/chain_head/rpc_methods.rs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/subxt/src/backend/chain_head/mod.rs b/subxt/src/backend/chain_head/mod.rs index a77e21c6b5..9a75543ee9 100644 --- a/subxt/src/backend/chain_head/mod.rs +++ b/subxt/src/backend/chain_head/mod.rs @@ -682,9 +682,7 @@ impl Backend for ChainHeadBackend { rpc_methods::TransactionStatus::BestChainBlockIncluded { block: None } => { TransactionStatus::NoLongerInBestBlock } - rpc_methods::TransactionStatus::Broadcasted => { - TransactionStatus::Broadcasted - } + rpc_methods::TransactionStatus::Broadcasted => TransactionStatus::Broadcasted, rpc_methods::TransactionStatus::Dropped { error, .. } => { TransactionStatus::Dropped { message: error } } diff --git a/subxt/src/backend/chain_head/rpc_methods.rs b/subxt/src/backend/chain_head/rpc_methods.rs index e8f39d3405..1eb715d980 100644 --- a/subxt/src/backend/chain_head/rpc_methods.rs +++ b/subxt/src/backend/chain_head/rpc_methods.rs @@ -709,7 +709,7 @@ pub enum TransactionStatus { /// Transaction is part of the future queue. Validated, /// The transaction has been broadcast to other nodes. - /// + /// /// Note: This event is no longer expected to be returned as of /// the chainHead_v1 spec, but we do so for compatibility with /// older versions of Smoldot, which do return it.