Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d50d5e4
initial ideas
shawntabrizi Mar 28, 2024
7f4422e
Update proving_trie.rs
shawntabrizi Mar 28, 2024
bdc0c84
create trait
shawntabrizi Mar 28, 2024
da385ab
use trait
shawntabrizi Mar 28, 2024
6ab4bfb
clean up trait and basic trie further
shawntabrizi Mar 28, 2024
1cfb29f
use trait in session historical
shawntabrizi Mar 28, 2024
3080c7b
fix api, add basic end to end test
shawntabrizi Mar 28, 2024
39b0fca
fix test
shawntabrizi Mar 28, 2024
599f576
Revert "use trait in session historical"
shawntabrizi Mar 28, 2024
a1c8886
Merge branch 'master' into shawntabrizi-proving-trie
shawntabrizi Mar 29, 2024
6bde2a3
Merge branch 'master' into shawntabrizi-proving-trie
Ank4n Apr 4, 2024
ead7951
Update substrate/primitives/runtime/src/proving_trie.rs
shawntabrizi Apr 4, 2024
0cac048
Merge branch 'master' into shawntabrizi-proving-trie
shawntabrizi Aug 15, 2024
acfe734
fix some feedback
shawntabrizi Aug 15, 2024
45f4287
update name
shawntabrizi Aug 15, 2024
efbe1c9
docs and multi value proof
shawntabrizi Aug 15, 2024
cfa62ce
improve test
shawntabrizi Aug 15, 2024
885fd94
add multi-value query test
shawntabrizi Aug 15, 2024
18a5c2e
Merge branch 'master' into shawntabrizi-proving-trie
shawntabrizi Aug 15, 2024
5e3e518
Create pr_3881.prdoc
shawntabrizi Aug 15, 2024
f35cacc
Merge branch 'shawntabrizi-proving-trie' of https://github.com/shawnt…
shawntabrizi Aug 15, 2024
e6c3759
use v1
shawntabrizi Aug 17, 2024
89679c3
Merge branch 'master' into shawntabrizi-proving-trie
shawntabrizi Aug 17, 2024
6e853ba
Merge branch 'master' into shawntabrizi-proving-trie
shawntabrizi Sep 2, 2024
00a7aa9
Merge remote-tracking branch 'upstream/master' into shawntabrizi-prov…
shawntabrizi Sep 3, 2024
ffbd656
use compact trie apis
shawntabrizi Sep 3, 2024
0217d0f
Update proving_trie.rs
shawntabrizi Sep 3, 2024
f20038a
more docs
shawntabrizi Sep 3, 2024
f934d8d
bad data test
shawntabrizi Sep 3, 2024
c92bd6a
Merge branch 'master' into shawntabrizi-proving-trie
shawntabrizi Sep 3, 2024
266a89b
additional warnings about layout
shawntabrizi Sep 3, 2024
3034aab
Update prdoc/pr_3881.prdoc
shawntabrizi Sep 3, 2024
1ceab64
remove lifetime
shawntabrizi Sep 3, 2024
c426a65
remove unused
shawntabrizi Sep 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions prdoc/pr_3881.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Introduce a Generic Proving Trie

doc:
- audience: Runtime Dev
description: |
This PR introduces a Proving Trie object which can be used inside the runtime. This can allow
for things like airdrops where a single hash is stored on chain representing the whole airdrop
and individuals present a proof of their inclusion in the airdrop.

crates:
- name: sp-runtime
bump: major
2 changes: 2 additions & 0 deletions substrate/primitives/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sp-arithmetic = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-std = { workspace = true }
sp-trie = { workspace = true }
sp-weights = { workspace = true }
docify = { workspace = true }
tracing = { workspace = true, features = ["log"], default-features = false }
Expand Down Expand Up @@ -69,6 +70,7 @@ std = [
"sp-state-machine/std",
"sp-std/std",
"sp-tracing/std",
"sp-trie/std",
"sp-weights/std",
"tracing/std",
]
Expand Down
16 changes: 16 additions & 0 deletions substrate/primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub mod generic;
pub mod legacy;
mod multiaddress;
pub mod offchain;
pub mod proving_trie;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not too sure if it should be part of sp-runtime crate.
Thing is the choice of using this trie should not be a default for any runtime (I think it is not the best tree for most use case, and I would encourage more binary trie, anyway it is very use case specific).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do we have a binary trie available in Substrate?

Does this trie work along side child tries?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the proof is to be run on child trie, there is no choice but to use this trie indeed.
(if using child trie root to prove, please be careful the chain will not be switching from trie V0 to trie V1 (should not matter for crowdloan as iirc the values are <= 32 byte), as a migration may change child trie root.
About this trie version, the simpliest would probably be to just pass the version in parameter.
When I read the PR I did not have this use case in mind but it is true that if what we are proving is from substrate state, then it could make sense to have this in runtime.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can I name this ProvingTrieBase16, and that would be better?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not too sure anymore what was my point 🤦
Probably at first reading I was thinking it should be an external crate, then realizing it is being tightly linked with substrate state could actually be fine.
ProvingTrieBase16 may not be a good idea as long as substrate does have a single trie backend.
Maybe it could simple be a module in sp-trie, but guess I am ok with things being this way.

pub mod runtime_logger;
mod runtime_string;
#[cfg(feature = "std")]
Expand All @@ -103,6 +104,8 @@ pub use crate::runtime_string::*;
// Re-export Multiaddress
pub use multiaddress::MultiAddress;

use proving_trie::TrieError;

/// Re-export these since they're only "kind of" generic.
pub use generic::{Digest, DigestItem};

Expand Down Expand Up @@ -592,6 +595,8 @@ pub enum DispatchError {
Unavailable,
/// Root origin is not allowed.
RootNotAllowed,
/// An error with tries.
Trie(TrieError),
}

/// Result of a `Dispatchable` which contains the `DispatchResult` and additional information about
Expand Down Expand Up @@ -697,6 +702,12 @@ impl From<ArithmeticError> for DispatchError {
}
}

impl From<TrieError> for DispatchError {
fn from(e: TrieError) -> DispatchError {
Self::Trie(e)
}
}

impl From<&'static str> for DispatchError {
fn from(err: &'static str) -> DispatchError {
Self::Other(err)
Expand All @@ -721,6 +732,7 @@ impl From<DispatchError> for &'static str {
Corruption => "State corrupt",
Unavailable => "Resource unavailable",
RootNotAllowed => "Root not allowed",
Trie(e) => e.into(),
}
}
}
Expand Down Expand Up @@ -768,6 +780,10 @@ impl traits::Printable for DispatchError {
Corruption => "State corrupt".print(),
Unavailable => "Resource unavailable".print(),
RootNotAllowed => "Root not allowed".print(),
Trie(e) => {
"Trie error: ".print();
<&'static str>::from(*e).print();
},
}
}
}
Expand Down
Loading