Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Allow usage of different proof formats #4938

Closed
wants to merge 253 commits into from
Closed
Show file tree
Hide file tree
Changes from 197 commits
Commits
Show all changes
253 commits
Select commit Hold shift + click to select a range
2845d0e
changes to state-db
cheme Jan 28, 2020
a0532d1
change transaction to be by child trie.
cheme Jan 28, 2020
eb5961f
slice index fix, many failing tests.
cheme Jan 28, 2020
67687f8
fix state-db tests
cheme Jan 28, 2020
48df830
vec with multiple entry of a same rc prefixeddb did not make sense,
cheme Jan 29, 2020
9e9a684
Merge branch 'master' into split_child_payload
cheme Jan 29, 2020
cb4c4a9
change set to btreemap, seems useless (at least do no solve changetrie
cheme Jan 29, 2020
a398b82
moving get_1 to get, state-machine needs rework
cheme Jan 30, 2020
7b26a93
Resolve a bit of child trie
cheme Jan 30, 2020
4d1378f
Merge branch 'split_child_payload' into split_child_payload_map2
cheme Jan 30, 2020
f39ce3f
small refact
cheme Jan 30, 2020
bc4fe52
Merge branch 'master' into split_child_payload
cheme Jan 30, 2020
f27a2ec
Merge branch 'split_child_payload' into split_child_payload_map2
cheme Jan 30, 2020
9f0c600
indent
cheme Jan 31, 2020
ecb43d0
Use const of null hash check on BackendStorageRef.
cheme Jan 31, 2020
d76a316
Merge branch 'split_child_payload_map2' into split_child_payload
cheme Jan 31, 2020
ae29df5
Associated null node hash set to a non optional const.
cheme Jan 31, 2020
6a06c0a
Make ChildInfo borrow of OwnedChildInfo.
cheme Jan 31, 2020
25aaa3a
Removing unsafe cast, using ref_cast asumption for borrow case.
cheme Feb 3, 2020
0d45d85
Borrow approach on OwnedChildInfo and ChildInfo did not make sense
cheme Feb 3, 2020
274a923
Factoring map of children code, before switching key.
cheme Feb 3, 2020
2e47a1d
Switching children key from optional to simple ChildInfo.
cheme Feb 3, 2020
328ed66
Merge branch 'master' into split_child_payload
cheme Feb 4, 2020
b07d7ca
fix merge test
cheme Feb 4, 2020
e5d7b04
clean todos
cheme Feb 4, 2020
3a71669
fix
cheme Feb 4, 2020
c846471
End up removing all keypacedDB from code.
cheme Feb 4, 2020
0b557b6
Clean unused struct and useless child info.
cheme Feb 4, 2020
8483da4
remove todo
cheme Feb 4, 2020
64ffcea
actual touch to keyspace prefixing (fail on wrong code asserted).
cheme Feb 4, 2020
2bc3cb6
self review changes.
cheme Feb 5, 2020
3136355
bump impl version.
cheme Feb 5, 2020
f655da1
Merge branch 'master' into split_child_payload
cheme Feb 5, 2020
bae6523
calculate size for single operation on usize.
cheme Feb 6, 2020
88ed503
Put keyspace logic in its own struct.
cheme Feb 6, 2020
4eb4676
Restrict top trie in ext to the storage key build from an empty key.
cheme Feb 6, 2020
5151471
Implementation basis for this PR, note that child storage key default
cheme Feb 6, 2020
8715446
Resolve prefix from child_info
cheme Feb 6, 2020
b72cd9c
Removed all child prefix, next is putting it back on full storage and on
cheme Feb 6, 2020
b636687
Prefixing child storage key where needed.
cheme Feb 7, 2020
e88631c
Merge branch 'master' into child_trie_w3_change
cheme Feb 7, 2020
e5b525f
Merge branch 'master' into split_child_payload
cheme Feb 7, 2020
e3cf283
In progress multiple proof format
cheme Feb 7, 2020
728aedf
Remove deprecated check for genesis and fix some test storage builds.
cheme Feb 7, 2020
8329448
Merge branch 'master' into child_trie_w3_change
cheme Feb 7, 2020
864e9ca
Fix contract to stop using the child storage prefix.
cheme Feb 7, 2020
c87d19b
Revert changes to state-db and plug keyspace above it for default child
cheme Feb 11, 2020
1f62342
Merge branch 'master' into split_child_payload
cheme Feb 11, 2020
8b901a2
Update client-db benches.
cheme Feb 11, 2020
f6efdad
Bump runtime impl version.
cheme Feb 11, 2020
c683198
Merge branch 'master' into split_child_payload
cheme Feb 13, 2020
3241607
Merge branch 'split_child_payload' into split_child_proof
cheme Feb 13, 2020
93de960
fix new code
cheme Feb 13, 2020
972574f
Merge branch 'split_child_payload' into split_child_proof
cheme Feb 13, 2020
a284921
progress (note that the unpack doing check we could have trie primitive
cheme Feb 13, 2020
4708560
Things stick together, lot of todos remaining.
cheme Feb 14, 2020
09b9afd
propagate api change
cheme Feb 14, 2020
2224e2f
Merge branch 'master' into child_trie_w3_change
cheme Feb 17, 2020
c04ba95
Fixing merge.
cheme Feb 17, 2020
ffaf9f5
Switch back to using prefix on host function, remove child_id and
cheme Feb 17, 2020
87bd97c
fix polka ref issue.
cheme Feb 17, 2020
17cf613
Switching back to unprefixed in child info (all temporary struct
cheme Feb 18, 2020
b3ccc93
bump version
cheme Feb 18, 2020
afe85ae
fix tabs and doc.
cheme Feb 18, 2020
befe325
Merge branch 'master' into child_trie_w3_change
cheme Feb 18, 2020
ed480fa
Apply more consistant naming 'storage_key' instead of
cheme Feb 19, 2020
e103c2a
Update primitives/storage/src/lib.rs
cheme Feb 21, 2020
958b626
use prefixed storage key in change trie
cheme Feb 21, 2020
26f8000
Merge branch 'child_trie_w3_change' of github.com:cheme/polkadot into…
cheme Feb 21, 2020
f471d56
renaming 'default_child_trie_root' to 'empty_child_trie_root'
cheme Feb 21, 2020
02ff227
apply some renaming, rpc change are really ugly, will revert them
cheme Feb 21, 2020
8fcc112
Switch back to using child_type for rpc (and light client).
cheme Feb 21, 2020
b7b347a
Merge branch 'master' into child_trie_w3_change
cheme Feb 21, 2020
3869774
Merge branch 'master' into child_trie_w3_change
cheme Feb 26, 2020
4ebc204
Merge branch 'master' into child_trie_w3_change
cheme Feb 26, 2020
74aa3f8
bump runtime version
cheme Feb 26, 2020
dc023d1
merge #4857
cheme Feb 26, 2020
4c40ea7
Resolve merging change of api from #4857
cheme Feb 26, 2020
b6b70f3
revert rpc related default renaming.
cheme Feb 27, 2020
d563278
fix slice indexing for child root
cheme Feb 27, 2020
a85bb38
Switch back to prefixed storage key for rpc.
cheme Feb 27, 2020
5f98fbe
rpc error discrepancy
cheme Feb 27, 2020
320e375
Merge branch 'master' into child_trie_w3_change
cheme Feb 27, 2020
f05a576
Merge branch 'child_trie_w3_change' into split_child_payload
cheme Feb 27, 2020
d85dec2
Fix test
cheme Feb 27, 2020
9f704c9
use correct parameter in overlay and fix change trie.
cheme Feb 28, 2020
c82edbd
Merge branch 'master' into child_trie_w3_change
cheme Mar 2, 2020
7c5d546
bump version
cheme Mar 2, 2020
19ab06b
Merge branch 'master' into child_trie_w3_change
cheme Mar 10, 2020
152f04f
Merge branch 'master' into child_trie_w3_change
cheme Mar 12, 2020
e959e0d
Merge branch 'child_trie_w3_change' into split_child_payload
cheme Mar 12, 2020
eff1d8c
keeping inner hasher, it is needed at state-machine level.
cheme Mar 12, 2020
0036fd3
Merge branch 'master' into child_trie_w3_change
cheme Mar 17, 2020
29254aa
missing merge
cheme Mar 17, 2020
72cfb6c
Merge branch 'child_trie_w3_change' into split_child_payload
cheme Mar 17, 2020
baacffa
fix bench
cheme Mar 17, 2020
160d2ea
Restore previous cli api (will need deprecation in a v2 of rpc), split
cheme Mar 18, 2020
c76b433
Merge branch 'child_trie_w3_change' into split_child_payload
cheme Mar 18, 2020
63cf6bd
remove old rpc
cheme Mar 19, 2020
5ed450b
Merge branch 'master' into child_trie_w3_change
cheme Mar 19, 2020
f21606f
review change.
cheme Mar 20, 2020
1b2a30c
Using `PrefixedStorageKey` type for child storage key that are prefixed.
cheme Mar 20, 2020
750cdd8
Fix rpc test.
cheme Mar 23, 2020
32e27c9
Merge branch 'master' into child_trie_w3_change
cheme Mar 23, 2020
cc65f44
bump spec version
cheme Mar 23, 2020
c20cef9
Merge branch 'master' into child_trie_w3_change
cheme Mar 26, 2020
797ad34
Merge branch 'master' into child_trie_w3_change
cheme Mar 26, 2020
f1b23df
Apply review suggestion
cheme Mar 26, 2020
9651dd1
Merge branch 'master' into child_trie_w3_change
cheme Mar 30, 2020
c631a46
Fix unrelated warning for CI
cheme Mar 30, 2020
217c19b
Merge branch 'master' into child_trie_w3_change
cheme Apr 2, 2020
cf7d90e
Merge branch 'child_trie_w3_change' into split_child_payload
cheme Apr 2, 2020
7c8f393
companion fix
cheme Apr 2, 2020
b2240f1
Update .maintain/gitlab/check_polkadot_companion_build.sh
cheme Apr 2, 2020
f3b9f23
Fix compilation errors.
cheme Apr 2, 2020
63943ee
last attempt
cheme Apr 2, 2020
784cb22
Forcing companion pr.
cheme Apr 2, 2020
4bbb24d
revert ci changes.
cheme Apr 2, 2020
18fa632
Merge branch 'split_child_payload' into split_child_proof
cheme Apr 3, 2020
ee679c1
lock update
cheme Apr 3, 2020
5d8ae4e
fix compilation errors
cheme Apr 3, 2020
50c3dd7
Merge branch 'master' into child_trie_w3_change
cheme Apr 3, 2020
a7c16eb
Merge branch 'child_trie_w3_change' of github.com:cheme/substrate int…
cheme Apr 3, 2020
ca40040
Merge branch 'master' into child_trie_w3_change
cheme Apr 9, 2020
226f7cd
name of children in chain spec change.
cheme Apr 14, 2020
5ab115e
Merge branch 'master' into child_trie_w3_change
cheme Apr 14, 2020
1ad4c5a
Merge branch 'master' into child_trie_w3_change
cheme Apr 15, 2020
94b78f3
Merge branch 'child_trie_w3_change' into split_child_payload
cheme Apr 15, 2020
5938d86
remove terminal space
cheme Apr 15, 2020
aa5c6dd
Merge branch 'split_child_payload' into split_child_proof
cheme Apr 15, 2020
30e8192
Merge branch 'master' into child_trie_w3_change
cheme Apr 15, 2020
bc2a198
sp-io documentation changes.
cheme Apr 15, 2020
83ff4a0
Merge branch 'master' into child_trie_w3_change
cheme Apr 15, 2020
ecb1c39
Merge branch 'master' into child_trie_w3_change
cheme Apr 15, 2020
619b454
Retain compatibility with network protocol.
cheme Apr 15, 2020
fa52a8c
Revert "Retain compatibility with network protocol."
cheme Apr 15, 2020
6969c74
Add ChildenProofMap and ChildrenProofInfo to be able to rebase on
cheme Apr 15, 2020
167f20c
Merge branch 'master' into child_trie_w3_change
cheme Apr 15, 2020
48dfe7d
Failure to run this on non split child payload: see non implemented
cheme Apr 15, 2020
38fa2c0
it was actually fine
cheme Apr 15, 2020
b7f7ee5
doc
cheme Apr 16, 2020
091ca80
pushing back full backend (will probably be removed with the Full
cheme Apr 16, 2020
87a4903
Merge branch 'split_child_proof_no_split_child_payload' into split_ch…
cheme Apr 16, 2020
e10387a
Register full in runtime, otherwhise packing would not be possible,
cheme Apr 16, 2020
557e6ef
passing around a target storage kind
cheme Apr 16, 2020
f687fc2
fix compact proof failure.
cheme Apr 16, 2020
a83f8e6
moving storage proof to trie as in master
cheme Apr 16, 2020
928fac0
Merge branch 'master' into child_trie_w3_change
gavofyork Apr 17, 2020
69ed118
fix renamed field related error
cheme Apr 17, 2020
eebdfe6
rework of storage proof in trie.
cheme Apr 17, 2020
39ba926
adapt rest of code
cheme Apr 17, 2020
60c136d
renaming refactor
cheme Apr 20, 2020
b79bd84
Merge branch 'master' into child_trie_w3_change
cheme Apr 20, 2020
e4c6289
refact and fix flatten not use.
cheme Apr 20, 2020
de305ed
move all pack to storage proof
cheme Apr 20, 2020
7a9098b
fix compile error, remove unused flatten method
cheme Apr 20, 2020
728daf4
add calls to the proof, untested.
cheme Apr 20, 2020
8724b57
Removing proof output and queryplan without value (does not exist in
cheme Apr 20, 2020
4641cbd
more acceptable error management
cheme Apr 21, 2020
c2d1cf1
switch root registration to encoded data.
cheme Apr 21, 2020
1a19852
only collect root when needed.
cheme Apr 21, 2020
02128d2
fix
cheme Apr 21, 2020
a9c1e65
remove old todos
cheme Apr 21, 2020
4f1e0ac
Set kind at the consumer level (static in rpc)
cheme Apr 21, 2020
869c24f
restore correct legacy encoding of light client
cheme Apr 21, 2020
d364381
Merge implementation
cheme Apr 21, 2020
55a12c8
Switch to new proof format and use compact on rpc and light (except head
cheme Apr 21, 2020
e542417
missing switches
cheme Apr 21, 2020
d3da220
fix merging and into a refactoring
cheme Apr 22, 2020
d6c82f5
remove rwlock for collecting roots
cheme Apr 22, 2020
f0a8455
triedbmut requiring hashdb block refacto (it should require a variant
cheme Apr 22, 2020
facd6f6
Revert "triedbmut requiring hashdb block refacto (it should require a…
cheme Apr 22, 2020
2fdb0f8
actually need rwlock for client backend
cheme Apr 22, 2020
2e4ed7d
fix doc test
cheme Apr 23, 2020
064d117
Merge branch 'child_trie_w3_change' into split_child_proof
cheme Apr 23, 2020
46d436a
Merge branch 'master' into split_child_proof
cheme Apr 23, 2020
f465388
Complete merge
cheme Apr 23, 2020
5f9b31b
Merge branch 'master' into split_child_proof
cheme May 4, 2020
f8a42a6
fix merge
cheme May 4, 2020
dc3915e
Merge branch 'master' into split_child_proof
cheme May 5, 2020
4fe29c0
Merge branch 'master' into split_child_proof
cheme May 18, 2020
cb93d53
remove unused parameter, rename api proof recorder
cheme May 18, 2020
be1fc61
restore to default proof
cheme May 18, 2020
16554e5
removing Legacy storage proof struct, codec adapters are enough
cheme May 18, 2020
cb7a0b5
Legacy compatibility. Note that in this state the PR does change
cheme May 19, 2020
9a9c982
revert to former light client proof encoding
cheme May 19, 2020
109267b
Revert protocol format to.
cheme May 19, 2020
6bd1469
also use non breakable finality proof
cheme May 19, 2020
f298e6b
Switch to compact proof everywhere
cheme May 19, 2020
4d5bfa7
Revert "Switch to compact proof everywhere"
cheme May 19, 2020
a2eca57
Doc improvment, remove dead code, more sensible recurse calls.
cheme May 19, 2020
e3d2067
Revert "Revert "Switch to compact proof everywhere"" : uses compact
cheme May 19, 2020
2e2d90f
Revert "Revert "Revert "Switch to compact proof everywhere"" : non
cheme May 19, 2020
af26fa8
Merge branch 'master' into split_child_proof
cheme May 20, 2020
89154cf
Pre refacto change from review.
cheme Jun 3, 2020
d659b2c
Merge branch 'master' into split_child_proof
cheme Jun 3, 2020
830dbf9
Refactoring in progress, base traits.
cheme Jun 3, 2020
83ce879
Trie in shape
cheme Jun 4, 2020
9aca478
Adding query plan variant to multiple for usage without exposing state
cheme Jun 4, 2020
2ec97d5
into partial merge
cheme Jun 5, 2020
f425fd5
in progress
cheme Jun 5, 2020
719d2d7
in progress
cheme Jun 5, 2020
30c1aec
refact trie code a bit (hasher instead of h::out mainly and no sync).
cheme Jun 8, 2020
bfd5a6d
New proof extract function to implement.
cheme Jun 8, 2020
d7f51d6
very messy but got something with right type system for state machine
cheme Jun 9, 2020
d5279dd
Test on full backend
cheme Jun 9, 2020
cc915c1
basic knownstorageandvalue test.
cheme Jun 9, 2020
e087c58
Fix tests remove warnings.
cheme Jun 10, 2020
69ebd39
sp_api using associated rec backend
cheme Jun 10, 2020
f4e6cb1
a few more, did not abstract state at client level (direct simpleproof
cheme Jun 10, 2020
4711052
the proof recorde struct is useless when we extract mergeable proof or
cheme Jun 10, 2020
3273887
Switch proof provider to return proofreg, we needed to merge
cheme Jun 10, 2020
d390740
test still needs a few updates, builds
cheme Jun 10, 2020
a8017b8
test fixed
cheme Jun 11, 2020
9a56fd6
completed query plan test.
cheme Jun 11, 2020
d496011
using another proof to register.
cheme Jun 11, 2020
f4f21bd
quick renaming
cheme Jun 11, 2020
f8185e9
clean warnings
cheme Jun 11, 2020
f7b2fba
more warnings
cheme Jun 11, 2020
ccfffcc
Merge branch 'master' into split_child_proof
cheme Jun 11, 2020
a6e4214
Renamings.
cheme Jun 12, 2020
2e372d3
switch collect of input to be in trait instead of hacky consolidate.
cheme Jun 12, 2020
e414fc5
Same state as rec, will remove reg backend state
cheme Jun 12, 2020
f5c525b
Removal of associated state type.
cheme Jun 12, 2020
9ef94da
Removing arc and code that could clone a record
cheme Jun 12, 2020
ad72850
comment
cheme Jun 12, 2020
cb8583d
Fix full backend test
cheme Jun 12, 2020
9a009ab
assert previous encoding is the same as SimpleProof.
cheme Jun 12, 2020
078576c
Remove temporary variants of multiple proof
cheme Jun 12, 2020
9c3c299
remove some proofs todos
cheme Jun 12, 2020
3000ea6
renaming reg 'registering' to rec 'recording'
cheme Jun 12, 2020
dba2bb1
minor doc change
cheme Jun 12, 2020
e1eafe7
Merge branch 'master' into split_child_proof
cheme Jun 12, 2020
2bc0dad
rename trieskiphashes to compact
cheme Jun 15, 2020
522775c
Break lines.
cheme Jun 15, 2020
a78b648
Merge branch 'master' into split_child_proof
cheme Jun 15, 2020
75d03f7
test ui line mismatch
cheme Jun 15, 2020
de341c1
restore doc test
cheme Jun 15, 2020
f9474f6
Expose proof from in memory backend type.
cheme Jun 16, 2020
10ec408
line breaks.
cheme Jun 16, 2020
7c789c9
few style fix
cheme Jun 16, 2020
ead9c0f
Merge branch 'master' into split_child_proof
cheme Jun 16, 2020
5974650
Fix trait issue from merge.
cheme Jun 17, 2020
53988c4
New lines break (from merge)
cheme Jun 17, 2020
996efa4
doc update
cheme Jun 17, 2020
45c5fcf
Remove todo
cheme Jun 17, 2020
e4e74bd
Merge branch 'master' into split_child_proof, expect issue with client
cheme Jul 9, 2020
5a25f15
Merge branch 'master' into split_child_proof
cheme Jul 23, 2020
c63cadb
Merge branch 'master' into split_child_proof
cheme Aug 3, 2020
2114ee9
Merge branch 'master' into split_child_proof
cheme Aug 17, 2020
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
3 changes: 3 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ mod tests {
use sc_consensus_epochs::descendent_query;
use sp_consensus::{
Environment, Proposer, BlockImportParams, BlockOrigin, ForkChoiceStrategy, BlockImport,
RecordProof,
RecordProof, StorageProofKind,
};
use node_primitives::{Block, DigestItem, Signature};
use node_runtime::{BalancesCall, Call, UncheckedExtrinsic, Address};
Expand Down Expand Up @@ -591,7 +591,7 @@ mod tests {
inherent_data,
digest,
std::time::Duration::from_secs(1),
RecordProof::Yes,
RecordProof::Yes(StorageProofKind::Flatten),
).await
}).expect("Error making test block").block;

Expand Down
11 changes: 7 additions & 4 deletions client/api/src/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use sp_runtime::{
};
use sp_state_machine::{
OverlayedChanges, ExecutionManager, ExecutionStrategy, StorageProof,
StorageProofKind,
};
use sc_executor::{RuntimeVersion, NativeVersion};
use sp_externalities::Extensions;
Expand Down Expand Up @@ -92,7 +93,7 @@ pub trait CallExecutor<B: BlockT> {
initialize_block: InitializeBlock<'a, B>,
execution_manager: ExecutionManager<EM>,
native_call: Option<NC>,
proof_recorder: &Option<ProofRecorder<B>>,
proof_recorder: Option<&RefCell<ProofRecorder<B>>>,
extensions: Option<Extensions>,
) -> sp_blockchain::Result<NativeOrEncoded<R>> where ExecutionManager<EM>: Clone;

Expand All @@ -109,14 +110,15 @@ pub trait CallExecutor<B: BlockT> {
mut state: S,
overlay: &mut OverlayedChanges,
method: &str,
call_data: &[u8]
call_data: &[u8],
kind: StorageProofKind,
) -> Result<(Vec<u8>, StorageProof), sp_blockchain::Error> {
let trie_state = state.as_trie_backend()
.ok_or_else(||
Box::new(sp_state_machine::ExecutionError::UnableToGenerateProof)
as Box<dyn sp_state_machine::Error>
)?;
self.prove_at_trie_state(trie_state, overlay, method, call_data)
self.prove_at_trie_state(trie_state, overlay, method, call_data, kind)
}

/// Execute a call to a contract on top of given trie state, gathering execution proof.
Expand All @@ -127,7 +129,8 @@ pub trait CallExecutor<B: BlockT> {
trie_state: &sp_state_machine::TrieBackend<S, HashFor<B>>,
overlay: &mut OverlayedChanges,
method: &str,
call_data: &[u8]
call_data: &[u8],
kind: StorageProofKind,
) -> Result<(Vec<u8>, StorageProof), sp_blockchain::Error>;

/// Get runtime version if supported.
Expand Down
6 changes: 4 additions & 2 deletions client/api/src/cht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ use sp_core::{H256, convert_hash};
use sp_runtime::traits::{Header as HeaderT, AtLeast32Bit, Zero, One};
use sp_state_machine::{
MemoryDB, TrieBackend, Backend as StateBackend, StorageProof, InMemoryBackend,
prove_read_on_trie_backend, read_proof_check, read_proof_check_on_proving_backend
prove_read_on_trie_backend, read_proof_check, read_proof_check_on_flat_proving_backend,
StorageProofKind,
};

use sp_blockchain::{Error as ClientError, Result as ClientResult};
Expand Down Expand Up @@ -121,6 +122,7 @@ pub fn build_proof<Header, Hasher, BlocksI, HashesI>(
prove_read_on_trie_backend(
trie_storage,
blocks.into_iter().map(|number| encode_cht_key(number)),
StorageProofKind::Flatten,
).map_err(ClientError::Execution)
}

Expand Down Expand Up @@ -170,7 +172,7 @@ pub fn check_proof_on_proving_backend<Header, Hasher>(
local_number,
remote_hash,
|_, local_cht_key|
read_proof_check_on_proving_backend::<Hasher>(
read_proof_check_on_flat_proving_backend::<Hasher>(
proving_backend,
local_cht_key,
).map_err(|e| ClientError::from(e)),
Expand Down
3 changes: 2 additions & 1 deletion client/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ pub use light::*;
pub use notifications::*;
pub use proof_provider::*;

pub use sp_state_machine::{StorageProof, ExecutionStrategy, CloneableSpawn};
pub use sp_state_machine::{StorageProof, LegacyDecodeAdapter, LegacyEncodeAdapter,
FlattenEncodeAdapter, StorageProofKind, ExecutionStrategy, CloneableSpawn};

/// Usage Information Provider interface
///
Expand Down
6 changes: 5 additions & 1 deletion client/api/src/proof_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT},
};
use crate::{StorageProof, ChangesProof};
use crate::{StorageProof, ChangesProof, StorageProofKind};
use sp_storage::{ChildInfo, StorageKey, PrefixedStorageKey};

/// Interface for providing block proving utilities.
Expand All @@ -31,6 +31,7 @@ pub trait ProofProvider<Block: BlockT> {
&self,
id: &BlockId<Block>,
keys: &mut dyn Iterator<Item=&[u8]>,
kind: StorageProofKind,
) -> sp_blockchain::Result<StorageProof>;

/// Reads child storage value at a given block + storage_key + key, returning
Expand All @@ -40,6 +41,7 @@ pub trait ProofProvider<Block: BlockT> {
id: &BlockId<Block>,
child_info: &ChildInfo,
keys: &mut dyn Iterator<Item=&[u8]>,
kind: StorageProofKind,
) -> sp_blockchain::Result<StorageProof>;

/// Execute a call to a contract on top of state in a block of given hash
Expand All @@ -51,7 +53,9 @@ pub trait ProofProvider<Block: BlockT> {
id: &BlockId<Block>,
method: &str,
call_data: &[u8],
kind: StorageProofKind,
) -> sp_blockchain::Result<(Vec<u8>, StorageProof)>;

/// Reads given header and generates CHT-based header proof.
fn header_proof(&self, id: &BlockId<Block>) -> sp_blockchain::Result<(Block::Header, StorageProof)>;

Expand Down
4 changes: 2 additions & 2 deletions client/basic-authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//!
//! ```
//! # use sc_basic_authorship::ProposerFactory;
//! # use sp_consensus::{Environment, Proposer, RecordProof};
//! # use sp_consensus::{Environment, Proposer, RecordProof, StorageProofKind};
//! # use sp_runtime::generic::BlockId;
//! # use std::{sync::Arc, time::Duration};
//! # use substrate_test_runtime_client::{self, runtime::{Extrinsic, Transfer}, AccountKeyring};
Expand All @@ -45,7 +45,7 @@
//! Default::default(),
//! Default::default(),
//! Duration::from_secs(2),
//! RecordProof::Yes,
//! RecordProof::Yes(StorageProofKind::Flatten),
//! );
//!
//! // We wait until the proposition is performed.
Expand Down
6 changes: 3 additions & 3 deletions client/block-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ where

let mut api = api.runtime_api();

if record_proof.yes() {
api.record_proof();
if let Some(kind) = record_proof.kind() {
api.record_proof(kind);
}

let block_id = BlockId::Hash(parent_hash);
Expand Down Expand Up @@ -231,7 +231,7 @@ mod tests {
&client,
client.info().best_hash,
client.info().best_number,
RecordProof::Yes,
RecordProof::Yes(sp_api::StorageProofKind::Flatten),
Default::default(),
&*backend,
).unwrap().build().unwrap();
Expand Down
24 changes: 12 additions & 12 deletions client/finality-grandpa/src/finality_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use log::{trace, warn};

use sp_blockchain::{Backend as BlockchainBackend, Error as ClientError, Result as ClientResult};
use sc_client_api::{
backend::Backend, StorageProof,
backend::Backend, StorageProof, StorageProofKind,
light::{FetchChecker, RemoteReadRequest},
StorageProvider, ProofProvider,
};
Expand Down Expand Up @@ -97,7 +97,7 @@ impl<BE, Block: BlockT> AuthoritySetForFinalityProver<Block> for Arc<dyn Storage
}

fn prove_authorities(&self, block: &BlockId<Block>) -> ClientResult<StorageProof> {
self.read_proof(block, &mut std::iter::once(GRANDPA_AUTHORITIES_KEY))
self.read_proof(block, &mut std::iter::once(GRANDPA_AUTHORITIES_KEY), StorageProofKind::Flatten)
}
}

Expand Down Expand Up @@ -228,7 +228,7 @@ pub(crate) struct FinalityProofFragment<Header: HeaderT> {
/// The set of headers in the range (U; F] that we believe are unknown to the caller. Ordered.
pub unknown_headers: Vec<Header>,
/// Optional proof of execution of GRANDPA::authorities() at the `block`.
pub authorities_proof: Option<StorageProof>,
pub authorities_proof: Option<Vec<Vec<u8>>>,
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 the code here would greatly benefit from using strong-typing instead of opaque Vec<u8> or even Vec<Vec<u8>>. The previous code had StorageProof, why not introduce FlatProof struct that is wrapped in the StorageProof enum, but used in a type-safety fashion here?

}

/// Proof of finality is the ordered set of finality fragments, where:
Expand Down Expand Up @@ -344,7 +344,7 @@ pub(crate) fn prove_finality<Block: BlockT, B: BlockchainBackend<Block>, J>(
block: current,
justification,
unknown_headers: ::std::mem::take(&mut unknown_headers),
authorities_proof: new_authorities_proof,
authorities_proof: new_authorities_proof.map(StorageProof::expect_flatten_content),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a panicker, we should rather have expect here with a convincing proof why the kind is always going to be Flat.

};

// append justification to finality proof if required
Expand Down Expand Up @@ -511,7 +511,7 @@ fn check_finality_proof_fragment<Block: BlockT, B, J>(
current_authorities = authorities_provider.check_authorities_proof(
proof_fragment.block,
header,
new_authorities_proof,
StorageProof::Flatten(new_authorities_proof),
)?;

current_set_id += 1;
Expand Down Expand Up @@ -836,8 +836,8 @@ pub(crate) mod tests {
_ => unreachable!("no other authorities should be fetched: {:?}", block_id),
},
|block_id| match block_id {
BlockId::Number(5) => Ok(StorageProof::new(vec![vec![50]])),
BlockId::Number(7) => Ok(StorageProof::new(vec![vec![70]])),
BlockId::Number(5) => Ok(StorageProof::Flatten(vec![vec![50]])),
BlockId::Number(7) => Ok(StorageProof::Flatten(vec![vec![70]])),
_ => unreachable!("no other authorities should be proved: {:?}", block_id),
},
),
Expand All @@ -853,14 +853,14 @@ pub(crate) mod tests {
block: header(5).hash(),
justification: just5,
unknown_headers: Vec::new(),
authorities_proof: Some(StorageProof::new(vec![vec![50]])),
authorities_proof: Some(vec![vec![50]]),
},
// last fragment provides justification for #7 && unknown#7
FinalityProofFragment {
block: header(7).hash(),
justification: just7.clone(),
unknown_headers: vec![header(7)],
authorities_proof: Some(StorageProof::new(vec![vec![70]])),
authorities_proof: Some(vec![vec![70]]),
},
]);

Expand All @@ -874,7 +874,7 @@ pub(crate) mod tests {
0,
auth3,
&ClosureAuthoritySetForFinalityChecker(
|hash, _header, proof: StorageProof| match proof.clone().iter_nodes().next().map(|x| x[0]) {
|hash, _header, proof: StorageProof| match proof.clone().iter_nodes_flatten().next().map(|x| x[0]) {
Some(50) => Ok(auth5.clone()),
Some(70) => Ok(auth7.clone()),
_ => unreachable!("no other proofs should be checked: {}", hash),
Expand Down Expand Up @@ -935,7 +935,7 @@ pub(crate) mod tests {
block: header(4).hash(),
justification: TestJustification((0, authorities.clone()), vec![7]).encode(),
unknown_headers: vec![header(4)],
authorities_proof: Some(StorageProof::new(vec![vec![42]])),
authorities_proof: Some(vec![vec![42]]),
}, FinalityProofFragment {
block: header(5).hash(),
justification: TestJustification((0, authorities), vec![8]).encode(),
Expand Down Expand Up @@ -985,7 +985,7 @@ pub(crate) mod tests {
block: header(2).hash(),
justification: TestJustification((1, initial_authorities.clone()), vec![7]).encode(),
unknown_headers: Vec::new(),
authorities_proof: Some(StorageProof::new(vec![vec![42]])),
authorities_proof: Some(vec![vec![42]]),
}, FinalityProofFragment {
block: header(4).hash(),
justification: TestJustification((2, next_authorities.clone()), vec![8]).encode(),
Expand Down
4 changes: 2 additions & 2 deletions client/finality-grandpa/src/light_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ pub mod tests {
use sp_consensus::{import_queue::CacheKeyId, ForkChoiceStrategy, BlockImport};
use sp_finality_grandpa::AuthorityId;
use sp_core::{H256, crypto::Public};
use sc_client_api::{in_mem::Blockchain as InMemoryAuxStore, StorageProof};
use sc_client_api::{in_mem::Blockchain as InMemoryAuxStore};
use substrate_test_runtime_client::runtime::{Block, Header};
use crate::tests::TestApi;
use crate::finality_proof::{
Expand Down Expand Up @@ -867,7 +867,7 @@ pub mod tests {
Vec::new(),
).encode(),
unknown_headers: Vec::new(),
authorities_proof: Some(StorageProof::new(vec![])),
authorities_proof: Some(vec![]),
},
].encode(),
&mut verifier,
Expand Down
4 changes: 2 additions & 2 deletions client/finality-grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use tokio::runtime::{Runtime, Handle};
use sp_keyring::Ed25519Keyring;
use sc_client_api::backend::TransactionFor;
use sp_blockchain::Result;
use sp_api::{ApiRef, StorageProof, ProvideRuntimeApi};
use sp_api::{ApiRef, StorageProof, StorageProofKind, ProvideRuntimeApi};
use substrate_test_runtime_client::runtime::BlockNumber;
use sp_consensus::{
BlockOrigin, ForkChoiceStrategy, ImportedAux, BlockImportParams, ImportResult, BlockImport,
Expand Down Expand Up @@ -248,7 +248,7 @@ impl AuthoritySetForFinalityProver<Block> for TestApi {
let backend = <InMemoryBackend<HashFor<Block>>>::from(vec![
(None, vec![(b"authorities".to_vec(), Some(authorities.encode()))])
]);
let proof = prove_read(backend, vec![b"authorities"])
let proof = prove_read(backend, vec![b"authorities"], StorageProofKind::Flatten)
.expect("failure proving read from in-memory storage backend");
Ok(proof)
}
Expand Down
Loading