-
Notifications
You must be signed in to change notification settings - Fork 281
[v0.50.0] Implement support for historic blocks in Subxt #2131
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
Draft
jsdw
wants to merge
33
commits into
master
Choose a base branch
from
jsdw-subxt-new
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…/implementing tx flows
…om unstable-light-client
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This release version is a deliberately large bump up from 0.44.0 to signify the extent of the changes in this release.
The headline changes are as follows:
subxt-historiccrate has been removed, its functionality having been merged into Subxt.subxt-corecrate has been removed for now to make way for the above. Subxt itself continues to support WASM use cases.no-stdfunctionality, theframe-decodecrate now contains much of the underlying logic used throughout Subxt to encode and decode things, and we would like to expand the functionality here.subxt-corecrate on how they use it, and will use this feedback to drive future work in this area.Errorenum; instead different Subxt APIs return different errors, to limit the number of possible errors in any one place. These all convert intosubxt::Errorso this can continue to be used as a catch-all.This changes have results in many breaking changes across APIs, which I will try my best to summarize below.
A good place to look for a more holistic understanding of what's changes are the examples, both:
For the smaller examples, start with the basic transaction submission example and then have a look at the blocks example and the storage example to give the best broad overview of the changes. Pick and choose others next depending on what suits.
A breakdown of the significant changes follows, to aid migration efforts:
Configuration
Before
Configuration (
PolkadotConfigandSubstrateConfig) was type-only and didn't exist at the value level, and so you'd provide it to the client like so:After
Configuration now exists at the value level too. This is because it has been extended with support for historic types and working with historic metadatas and spec versions:
The rules for when to use
PolkadotConfigandSubstrateConfigremain the same:PolkadotConfigfor the Polkadot Relay Chain.SubstrateConfigby default with other chains.See the docs for
PolkadotConfigandSubstrateConfigfor more. If you want to work with historic blocks for instance, you'll need to provide historic type information forSubstrateConfig.Working at specific blocks
Before
Previously, you'd be able to select (within a limited range) which block to work at with APIs like so:
After
Now, the block is selected first, like so:
Notes:
at_latesthas been renamed toat_current_blockand, like before, it fetches the current finalized block at the time of calling.at_current_blocknow accepts a block hahs or block number, and returns a client that works in the context of that block.Metadataand so it was unnecessary. Now, constants are retrieved at a specific block like everything else (different blocks may have differentMetadatas).runtime_api()was renamed toruntime_apis()to be consistent with other APIs names..tx()is now callable at a specific block, and uses this block for any account nonce and mortality configuration.Working with blocks
Before
A
.blocks()method accessed block-specific APIs for fetching and subscribing to blocks.After
Now that APIs are largely block-specific up front, we don't need separate APIs for block fetching, and move streaming blocks up a level.
Notes:
.at()at a given block to hand back a full client which can do anything at that block.api.blocks().subscribe_finalized()=>api.stream_blocks().api.blocks().subscribe_best()=>api.stream_best_blocks().api.blocks().subscribe_all()=>api.stream_all_blocks().Transactions
Before
Transactions were implicitly created at the latest block, and the APIs were disconnected from any particular block:
After
Transactions are anchored to a given block but we continue to provide a
.tx()method on the client as a shorthand for "create transactions at the current block".Notes:
transactionsinstead oftxeverywhere to align better with other API names, but continue to providetxas a shorthand.partialis changed tosignablein transaction APIs. "partial" was always a confusing name, and "signable" makes it much clearer what is being created; something that can be signed.tx().create_partial_offline(..)=>tx().create_signable_offline(..)tx().create_v4_partial_offline(..)=>tx().create_v4_signable_offline(..)tx().create_v5_partial_offline(..)=>tx().create_v5_signable_offline(..)tx().create_partial(..)=>tx().create_signable(..)tx().create_v4_partial(..)=>tx().create_v4_signable(..)tx().create_v5_partial(..)=>tx().create_v5_signable(..)tx().from_bytes(bytes)is added as an easy way to hand a pre-constructed transaction to Subxt to be submitted, removing the need for an uglySubmittableTransaction::from_bytesmethod.Storage Entries
Before
The codegen dealt with the heavy lifting of iterating storage maps at various depths (albeit with a bug), and on fetching an entry you had little control over how you handled the resulting bytes.
After
A redesign of the Storage APIs makes everything more unified, and allows working at specific storage entries in a much more flexible way than before, while moving logic out of the codegen, simplifying it, and into Subxt proper.
This is perhaps the largest change to any specific set of APIs in terms of differences. Take a look at the API docs and the storage example and PR for more on this.
Dynamic values
Before
Dynamic values were always constructed using and returning
scale_value::Values, for instance:After
The dynamic methods have been made more generic, allowing more arbitrary types to be used in their construction, and alloowing the return type to be set. This does however mean that types need to be provided sometimes:
Notes:
scale_value::Valuewas used everywhere, the actual values provided are always checked at runtime against the API and invalid shapes/values will lead to an error.scale_value::Value. This makes it easier to work against historic blocks where you may not have or want to use the#[subxt]codegen, but still want to work with static types as much as possible.Metadata
Subxt previously exposed
subxt::Metadata, which was a wrapped version ofsubxt_metadata::Metadata. The wrapping was removed, and now we have onlysubxt_metadata::Metadata, which is exposed assubxt::Metadata. This metadata can be cloned but is not cheap to clone, and so we also exposesubxt::ArcMetadata, which is used in many places and is theArc-wrapped version of it, for cheap cloning.subxt_metadata::Metadatanow exposes helper functions to construct it from variousframe_metadataversions, to support our historic decoding efforts:Metadata::from_v16(..)Metadata::from_v15(..)Metadata::from_v14(..)Metadata::from_v13(..)Metadata::from_v12(..)Metadata::from_v11(..)Metadata::from_v10(..)Metadata::from_v9(..)Metadata::from_v8(..)Where the older versions require type information to be provided in addition to the correpsonding
frame_metadataversion.