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

Add a "tracing visitor" to make it easier to find decode issues #52

Merged
merged 5 commits into from
Jul 24, 2024

Conversation

jsdw
Copy link
Collaborator

@jsdw jsdw commented Jul 18, 2024

The main motivation for this is in making it easier to understand what went wrong when we try to decode historic blocks ie via https://github.com/jsdw/polkadot-historic-decoding-example.

This visitor is similar to the normal Value visitor, except that it tracks various information while decoding a value, and as such is able to print out a useful error in the event that it fails to decode, ie something like:

Caused by:
    0: Failed to decode type 'Vec<<T as Trait>::Call>' into a Value in extrinsic Utility.batch
    1: Error decoding value at .[1].[0].proof.[69]: Not enough data to fill buffer
       Decoded so far:
       
       <Vec<<T as Trait>::Call>> (
         <<T as Trait>::Call> Staking (
           <builtin::module::Staking> bond {
             controller: <<T::Lookup as StaticLookup>::Source> 0x1650C532ED1A8641E8922AA24ADE0FF411D03EDD9ED1C6B7FE42F1A801CEE37C,
             value: <BalanceOf<T>> 50000000000000000,
             payee: <RewardDestination> Controller ()
           }
         ),
         <<T as Trait>::Call> Session (
           <builtin::module::Session> set_keys {
             keys: <T::Keys> (
               <AccountId> 0x8BDC9AEC45375D38DD3D88862AF5A3E1EA7512E40AC8CD7CC68DD0E2AB73AFC2,
               <AccountId> 0x9672FF4C25ADFA43D60418A2CEE8839A83CA868D318AFB7E6FBAA0E91BEBF622,
               <AccountId> 0x32EE635C78E4060B9EA8FB3C0914988494B2E2AD63CAAC907AFC964D95689053,
               <AccountId> 0x32B3DBC6A9DDD582ABBFFE31C86F144C4AB67F148B44A58C1821BDD46E4BFC4F
             ),
             proof: <Vec<u8>> 0x56B14C4F72738F9D3FDE8EF8CAFCEA7A83B6EA1A7CCDCFC3F50C73130007040284D717070894C6A4B68FB82C9BECF7F01B603D1112AAB237B07F2955CFDC5F6258F245BB7F
           }
         )
       )

The Value to_string implementation was reworked in the process in order to allow Values to be printed in a non-compact form, so now print!("{value:#}") will print a multiline form and print!("{value}") will continue to print a compact format. The ability to print context and custom format things was also added but is currently not exposed in the APIs; we can figure out what they should look like as a separate PR.

@jsdw jsdw changed the title Add a "tracing visitor" Add a "tracing visitor" to make it easier to find decode issues Jul 18, 2024
src/scale_impls/tracing_decoder/visitor.rs Outdated Show resolved Hide resolved
src/scale_impls/tracing_decoder/visitor.rs Outdated Show resolved Hide resolved
src/scale_impls/tracing_decoder/error.rs Show resolved Hide resolved
Copy link
Contributor

@lexnv lexnv left a comment

Choose a reason for hiding this comment

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

LGTM!

@jsdw jsdw merged commit 0d96cc7 into main Jul 24, 2024
8 checks passed
@jsdw jsdw deleted the jsdw-tracing-visitor branch July 24, 2024 10:21
@jsdw jsdw mentioned this pull request Jul 24, 2024
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.

3 participants