Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new API for sign_and_submit_then_watch #354

Merged
merged 33 commits into from Dec 9, 2021
Merged

Implement new API for sign_and_submit_then_watch #354

merged 33 commits into from Dec 9, 2021

Conversation

jsdw
Copy link
Collaborator

@jsdw jsdw commented Dec 3, 2021

This PR is an attempt to implement the API for subscribing to transaction state and obtaining events as described in #312.

Closes #312

@jsdw
Copy link
Collaborator Author

jsdw commented Dec 7, 2021

So, I'm fairly happy with this API now overall.

Some things that come out of this PR that could be addressed separately:

  • More docs, tests and examples of the new API. (especially examples, to show how you can dig into each stage of a transaction in more detail if needed).
  • Making TransactionProgress impl Stream (probably an upstream change in jsonrpsee is easiest).
  • Tidy up the event subscription stuff. Now that the new API doesn't need to subscribe to events, we can probably simplify and have a second look at the use cases for the separate event subscription API. (I'd like to think that we could strip it right down, and rely on a Stream impl to provide combinators for filtering and working with events).

@jsdw jsdw marked this pull request as ready for review December 7, 2021 17:14
@jsdw jsdw requested a review from ascjones December 7, 2021 17:14
src/client.rs Outdated
})
// If we successfully obtain the block hash we think contains our
// extrinsic, the extrinsic should be in there somewhere..
.ok_or(Error::Transaction(TransactionError::BlockHashNotFound))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this error message could be a little confusing:
Block hash containing non-finalized transaction can no longer be found

maybe 'extrinsic not found' or 'extrinsic position not found' instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up going for "The block containing the transaction can no longer be found (perhaps it was on a non-finalized fork?)"; what do you reckon?

Copy link
Contributor

@insipx insipx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty clean to me, nj

examples/submit_and_watch.rs Outdated Show resolved Hide resolved
src/client.rs Outdated Show resolved Hide resolved
src/client.rs Outdated Show resolved Hide resolved
src/client.rs Outdated Show resolved Hide resolved
src/client.rs Outdated Show resolved Hide resolved
src/client.rs Outdated Show resolved Hide resolved
src/error.rs Outdated Show resolved Hide resolved
src/error.rs Outdated Show resolved Hide resolved
src/error.rs Outdated Show resolved Hide resolved
src/error.rs Outdated Show resolved Hide resolved
@jsdw
Copy link
Collaborator Author

jsdw commented Dec 8, 2021

@gregdhill @sander2 you guys may both be interested in this PR, and it would def break some stuff :)

See the examples/submit_and_watch.rs example for the high level usage. I need to expand this to show the lower level usage as well.

Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! A few nitpicks.

src/client.rs Outdated Show resolved Hide resolved
src/client.rs Outdated Show resolved Hide resolved
src/client.rs Outdated Show resolved Hide resolved
src/client.rs Outdated
pub enum TransactionProgressStatus<'client, T: Config> {
/// Transaction is part of the future queue.
pub enum TransactionStatus<'client, T: Config> {
/// The transaction is part of the "future" queue.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The transaction is part of the "future" queue.
/// The transaction is part of the "future" queue in the transaction pool.

maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure enough on the terminology to really know! are "future" and "ready" transactions both part of the pool?

The substrate glossary for transaction pool: "A collection of transactions that are not yet included in blocks but have been determined to be valid."

Maybe Future transactions haven't been validated yet? But in the big comment, they do mention "future and ready pool"...

Anyway, shrug, I'd lean towards playing it safe and leaving it as is for now :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @ascjones knows? Either way, fine by me to leave it as is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This distinction is new to me TBH

src/client.rs Outdated Show resolved Hide resolved
Copy link
Member

@ascjones ascjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/client.rs Outdated
pub enum TransactionProgressStatus<'client, T: Config> {
/// Transaction is part of the future queue.
pub enum TransactionStatus<'client, T: Config> {
/// The transaction is part of the "future" queue.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This distinction is new to me TBH

src/client.rs Outdated
/// - `Retracted`
/// 5. Block finalized:
/// - `Finalized`
/// - `FinalityTimeout`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice categorisation. Would it bring any value to bring this grouping to the type level, instead of the simple 1 => 1 mapping with TransactionStatus? i.e. split the groups into their own enums combined as variants in the top level enum.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reckon there are few enough "groups", and things can move between them easily enough, that the flat enum is probably easier to work with (since one mode of use involves matching on variants), and has the nice benefit of aligning very closely with thr substrate version, and so easy to keep in sync going forwards :)

src/client.rs Outdated
@@ -280,3 +284,416 @@ where
Ok(signed)
}
}

/// This struct represents a subscription to the progress of some transaction, and is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reckon all this stuff deserves it's own file, shouldn't be in client.rs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually did do this initially. I like the separation; I just wasn't keen on the circular dependency it would introduce (client makes a transactionprogress, transactionprogress et al have a reference to client) :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I think I'll give it a try anyway though, because it would be nice breaking that file down!)

@jsdw jsdw merged commit 5db9b73 into master Dec 9, 2021
@jsdw jsdw deleted the jsdw-events branch December 9, 2021 12:23
0623forbidden pushed a commit to DEIPworld/substrate-subxt that referenced this pull request Feb 15, 2022
* WIP Implementing new event subscription API

* back to lifetimes, fix example

* no more need for accept_weak_inclusion

* thread lifetime through to prevent 'temporary dropped' issue

* make working with events a little nicer

* Get tests compiling

* fmt and clippy

* _name back to name

* dont take ownership, just have stronger note

* Attempt to fix test

* remove commented-out code

* Add a couple more helper methods and a test

* Remove custom ExtrinsicFailed handling; treat them like other events

* Handle runtime errors in TransactionProgress related bits

* cargo fmt + clippy

* Fix some of the failing tests

* remove unused import

* fix transfer_error test

* Fix compile errors against new substrate latest

* Comment tweaks, and force test-runtime rebuild

* Drop the TransactionProgress subscription when we hit 'end' statuses

* cargo fmt

* find_event to find_first_event and helper to return all matching events

* TransactionProgressStatus to TransactionStatus

* Copy and improve docs on TransactionStatus from substrate

* debug impl for Client to avoid manual debug impls elsewhere

* Add and tweak comments, specifically a note about block inclusion on errors

* clippy + fmt

* Fix docs

* Ignore 'error' statuses and adhere to the substrate docs

* tweak and improve some comments per @dvdplm's suggestions

* Break transaction* structs into separate file

* fmt and fix doc link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Finer grained event subscription API
5 participants