Skip to content

Commit

Permalink
Fix unstable-light-client + ChainHeadBackend tx events (#1865)
Browse files Browse the repository at this point in the history
* Fix unstable-light-client + ChainHeadBackend tx events

* Add note that Broadcasted event should no longer be returned at all

* fmt
  • Loading branch information
jsdw authored Nov 13, 2024
1 parent f861adf commit 057c847
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 deletions.
4 changes: 1 addition & 3 deletions subxt/src/backend/chain_head/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,7 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for ChainHeadBackend<T> {
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 }
}
Expand Down
11 changes: 5 additions & 6 deletions subxt/src/backend/chain_head/rpc_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,11 @@ pub enum TransactionStatus<Hash> {
/// 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,
},
///
/// 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
/// of the best chain.
Expand All @@ -737,8 +738,6 @@ pub enum TransactionStatus<Hash> {
},
/// 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,
},
Expand Down
6 changes: 2 additions & 4 deletions subxt/src/backend/legacy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,8 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for LegacyBackend<T> {
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 {
Expand Down
5 changes: 1 addition & 4 deletions subxt/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,7 @@ pub enum TransactionStatus<Hash> {
/// 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.
Expand Down
13 changes: 5 additions & 8 deletions subxt/src/tx/tx_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl<T: Config, C: Clone> Stream for TxProgress<T, C> {
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()))
Expand Down Expand Up @@ -172,10 +172,7 @@ pub enum TxStatus<T: Config, C> {
/// 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.
Expand Down Expand Up @@ -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(),
},
Expand All @@ -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(),
},
Expand All @@ -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(),
},
Expand Down

0 comments on commit 057c847

Please sign in to comment.