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

State migration rpc #10981

Merged
merged 252 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 245 commits
Commits
Show all changes
252 commits
Select commit Hold shift + click to select a range
7e98291
setting flag
cheme May 18, 2021
5d3a1b2
flag in storage struct
cheme May 18, 2021
4256a40
fix flagging to access and insert.
cheme May 18, 2021
5bb0b68
added todo to fix
cheme May 18, 2021
7081864
also missing serialize meta to storage proof
cheme May 18, 2021
3f1ee83
extract meta.
cheme May 19, 2021
1bbdf35
Isolate old trie layout.
cheme May 19, 2021
e5feabf
failing test that requires storing in meta when old hash scheme is used.
cheme May 19, 2021
aa78ed6
old hash compatibility
cheme May 19, 2021
045b097
Db migrate.
cheme May 19, 2021
79a43dd
runing tests with both states when interesting.
cheme May 20, 2021
aa2e5c3
fix chain spec test with serde default.
cheme May 20, 2021
91bd0aa
export state (missing trie function).
cheme May 20, 2021
183b7b5
Pending using new branch, lacking genericity on layout resolution.
cheme May 21, 2021
8511a40
extract and set global meta
cheme May 21, 2021
270ed28
Update to branch 4
cheme May 24, 2021
b838e7e
fix iterator with root flag (no longer insert node).
cheme May 25, 2021
30742b7
fix trie root hashing of root
cheme May 25, 2021
c620869
complete basic backend.
cheme May 26, 2021
a3b1039
Remove old_hash meta from proof that do not use inner_hashing.
cheme May 26, 2021
693e38b
fix trie test for empty (force layout on empty deltas).
cheme May 26, 2021
6e89b3a
Root update fix.
cheme May 26, 2021
c14e11c
Merge branch 'master' into state-update4
cheme May 26, 2021
f568794
debug on meta
cheme May 26, 2021
fb0ea03
Use trie key iteration that do not include value in proofs.
cheme May 27, 2021
cd98390
switch default test ext to use inner hash.
cheme May 27, 2021
5ab0c01
small integration test, and fix tx cache mgmt in ext.
cheme May 27, 2021
99ef85c
Proof scenario at state-machine level.
cheme May 27, 2021
4d6aee8
trace for db upgrade
cheme May 27, 2021
791acae
try different param
cheme May 27, 2021
b51eaa4
act more like iter_from.
cheme May 28, 2021
715b1a5
Bigger batches.
cheme May 28, 2021
3cdb0ed
Update trie dependency.
cheme May 28, 2021
ae1454f
drafting codec changes and refact
cheme Jun 8, 2021
c807f44
before removing unused branch no value alt hashing.
cheme Jun 8, 2021
a70ce70
alt hashing only for branch with value.
cheme Jun 8, 2021
11f0d5a
fix trie tests
cheme Jun 8, 2021
cf0f0df
Hash of value include the encoded size.
cheme Jun 8, 2021
b721733
removing fields(broken)
cheme Jun 9, 2021
2f8360f
fix trie_stream to also include value length in inner hash.
cheme Jun 9, 2021
76b6d7a
triedbmut only using alt type if inner hashing.
cheme Jun 9, 2021
cfa0ecd
trie_stream to also only use alt hashing type when actually alt hashing.
cheme Jun 9, 2021
60f7012
Refactor meta state, logic should work with change of trie treshold.
cheme Jun 9, 2021
40ec2f7
Remove NoMeta variant.
cheme Jun 9, 2021
204f51f
Remove state_hashed trigger specific functions.
cheme Jun 9, 2021
b62cdf5
pending switching to using threshold, new storage root api does not
cheme Jun 10, 2021
74fb9c8
refactoring to use state from backend (not possible payload changes).
cheme Jun 10, 2021
97a1aa6
Applying from previous state
cheme Jun 10, 2021
f4849a2
Remove default from storage, genesis need a special build.
cheme Jun 10, 2021
4eabbde
rem empty space
cheme Jun 11, 2021
18abb6e
Merge branch 'master' into state-update4-refact
cheme Jun 11, 2021
ae627f6
Catch problem: when using triedb with default: we should not revert
cheme Jun 11, 2021
4706814
fix compilation
cheme Jun 11, 2021
09d5cf6
Right logic to avoid switch on reencode when default layout.
cheme Jun 11, 2021
906cd48
Clean up some todos
cheme Jun 14, 2021
662eabe
remove trie meta from root upstream
cheme Jun 14, 2021
17ac7cb
Merge branch 'master' into state-update4-refact
cheme Jun 15, 2021
ac0e019
update upstream and fix benches.
cheme Jun 15, 2021
7e73a70
split some long lines.
cheme Jun 15, 2021
3498d17
Merge branch 'master' into state-update4-refact
cheme Jun 15, 2021
934021c
UPdate trie crate to work with new design.
cheme Jun 18, 2021
1e40e6d
Finish update to refactored upstream.
cheme Jun 21, 2021
602723e
update to latest triedb changes.
cheme Jun 21, 2021
66ee72d
Clean up.
cheme Jun 21, 2021
23c5db3
fix executor test.
cheme Jun 21, 2021
03d93b2
rust fmt from master.
cheme Jul 22, 2021
b13ebd0
Merge branch 'master' into state-update4
cheme Jul 22, 2021
93aaa4c
rust format.
cheme Jul 22, 2021
66c832e
Merge branch 'master' into state-update4
cheme Aug 11, 2021
89eba2b
Merge branch 'master' into state-update4
cheme Aug 16, 2021
1e02c01
rustfmt
cheme Aug 16, 2021
7898e49
Merge branch 'master' into state-update4
cheme Aug 27, 2021
a48970f
fix
cheme Aug 27, 2021
92b9fcf
start host function driven versioning
cheme Aug 27, 2021
145406a
update state-machine part
cheme Aug 30, 2021
00460da
still need access to state version from runtime
cheme Aug 31, 2021
bad0723
state hash in mem: wrong
cheme Aug 31, 2021
537c04f
direction likely correct, but passing call to code exec for genesis
cheme Aug 31, 2021
b537440
state version serialize in runtime, wrong approach, just initialize it
cheme Sep 8, 2021
b717611
stateversion from runtime version (core api >= 4).
cheme Sep 8, 2021
b6a6e83
Merge branch 'master' into state-update4-host2
cheme Sep 8, 2021
846fef0
update trie, fix tests
cheme Sep 8, 2021
0a6dc15
unused import
cheme Sep 8, 2021
4e10a68
clean some TODOs
cheme Sep 8, 2021
bf31362
Require RuntimeVersionOf for executor
cheme Sep 8, 2021
8aba5dd
use RuntimeVersionOf to resolve genesis state version.
cheme Sep 8, 2021
499ab5b
update runtime version test
cheme Sep 8, 2021
27cf136
fix state-machine tests
cheme Sep 8, 2021
ac4f7dc
TODO
cheme Sep 8, 2021
1c817d6
Use runtime version from storage wasm with fast sync.
cheme Sep 9, 2021
f0d9326
rustfmt
cheme Sep 9, 2021
6d930fa
Merge branch 'master' into state-update4-host2
cheme Sep 9, 2021
877c36e
fmt
cheme Sep 9, 2021
8514d5f
fix test
cheme Sep 9, 2021
3385eae
revert useless changes.
cheme Sep 9, 2021
3be7538
clean some unused changes
cheme Sep 9, 2021
c858c28
fmt
cheme Sep 9, 2021
63265eb
removing useless trait function.
cheme Sep 10, 2021
4142b8d
remove remaining reference to state_hash
cheme Sep 14, 2021
b3c8812
Merge branch 'state-update4-host2' of github.com:cheme/substrate into…
cheme Sep 14, 2021
aaca0f8
Merge branch 'master' into state-update4-host2
cheme Oct 1, 2021
5ed824a
fix some imports
cheme Oct 1, 2021
b0b8a85
Follow chain state version management.
cheme Oct 1, 2021
e7267c0
trie update, fix and constant threshold for trie layouts.
cheme Oct 4, 2021
599714f
update deps
cheme Oct 4, 2021
6045952
Update to latest trie pr changes.
cheme Oct 5, 2021
fb8ff8e
fix benches
cheme Oct 5, 2021
af86f39
Verify proof requires right layout.
cheme Oct 5, 2021
66daec0
update trie_root
cheme Oct 7, 2021
299fea6
Merge branch 'master' into state-update4-host2
cheme Oct 12, 2021
4ff9009
Update trie deps to latest
cheme Oct 12, 2021
fa7ebaf
Merge branch 'master' into state-update4-host2
cheme Oct 18, 2021
a343138
Update to latest trie versioning
cheme Oct 18, 2021
3432668
Removing patch
cheme Oct 19, 2021
932eee7
update lock
cheme Oct 19, 2021
c86af90
Merge branch 'master' into state-update4-host2
cheme Oct 19, 2021
3299b7f
extrinsic for sc-service-test using layout v0.
cheme Oct 19, 2021
e66e40d
Merge branch 'master' into state-update4-host2
cheme Oct 20, 2021
4328973
Adding RuntimeVersionOf to CallExecutor works.
cheme Oct 20, 2021
c342bdf
fmt
cheme Oct 20, 2021
d8a9b50
error when resolving version and no wasm in storage.
cheme Oct 20, 2021
898bc13
use existing utils to instantiate runtime code.
cheme Oct 20, 2021
1b1092c
migration pallet
kianenigma Oct 21, 2021
d35f273
Patch to delay runtime switch.
cheme Oct 21, 2021
90ceb5e
Revert "Patch to delay runtime switch."
cheme Oct 21, 2021
eb272e6
fix test
kianenigma Oct 21, 2021
a327e5c
Merge branch 'master' into state-update4-host2
cheme Oct 21, 2021
e41881c
fix child migration calls.
cheme Oct 21, 2021
ac1a80c
useless closure
cheme Oct 21, 2021
b06a90c
remove remaining state_hash variables.
cheme Oct 21, 2021
724b26f
Fix and add more tests
kianenigma Oct 21, 2021
84e3ab9
Remove outdated comment
cheme Oct 21, 2021
213d648
useless inner hash
cheme Oct 21, 2021
24309cd
fmt
cheme Oct 21, 2021
6133b5a
remote tests
kianenigma Oct 22, 2021
4eb1d42
finally ksm works
kianenigma Oct 26, 2021
c5ae528
Merge branch 'master' of github.com:paritytech/substrate into kiz-inn…
kianenigma Oct 26, 2021
2a98610
batches are broken
kianenigma Oct 26, 2021
0d6590d
Merge branch 'master' of github.com:paritytech/substrate into ecr-sta…
kianenigma Oct 26, 2021
0572949
Merge branch 'ecr-state-update-host' of github.com:paritytech/substra…
kianenigma Oct 26, 2021
c95cd1e
clean the benchmarks
kianenigma Oct 27, 2021
d9d09fd
Apply suggestions from code review
kianenigma Oct 27, 2021
3eaa235
Apply suggestions from code review
kianenigma Oct 27, 2021
ef556f0
Update frame/state-trie-migration/src/lib.rs
kianenigma Oct 28, 2021
9ff5ee9
Update frame/state-trie-migration/src/lib.rs
kianenigma Oct 28, 2021
a0e5c58
brand new version
kianenigma Oct 30, 2021
c953ff0
merged
kianenigma Oct 30, 2021
b6aad51
fix build
kianenigma Oct 30, 2021
a980e40
Update frame/state-trie-migration/src/lib.rs
kianenigma Oct 30, 2021
013b389
Update frame/state-trie-migration/src/lib.rs
kianenigma Oct 30, 2021
182ec74
Merge branch 'master' into state-update4-host2
cheme Nov 1, 2021
3b267bf
Merge branch 'state-update4-host2' into ecr-state-update-host
cheme Nov 1, 2021
d6bd51d
Update primitives/storage/src/lib.rs
kianenigma Nov 4, 2021
82c8cb2
Update frame/state-trie-migration/src/lib.rs
kianenigma Nov 4, 2021
d75b23e
Update frame/state-trie-migration/src/lib.rs
kianenigma Nov 4, 2021
37041fc
merge master and some review comments
kianenigma Nov 4, 2021
d46b029
Upstream.into()
kianenigma Nov 4, 2021
98c8467
Merge branch 'master' into ecr-state-update-host
cheme Nov 5, 2021
d69bce2
Merge branch 'master' into kiz-inner-hashing-runtime-migration
cheme Nov 5, 2021
9b4837f
fmt and opt-in feature to apply state change.
cheme Nov 5, 2021
b3d8f62
feature gate core version, use new test feature for node and test node
cheme Nov 8, 2021
dd20a8d
Use a 'State' api version instead of Core one.
cheme Nov 8, 2021
a0ac11f
Merge branch 'master' into state-update4-host2
cheme Nov 8, 2021
c75d148
fix merge of test function
cheme Nov 8, 2021
aba8632
use blake macro.
cheme Nov 8, 2021
205db5e
Fix state api (require declaring the api in runtime).
cheme Nov 8, 2021
d493547
Merge branch 'master' into state-update4-host2
cheme Nov 8, 2021
6126ed2
Opt out feature, fix macro for io to select a given version
cheme Nov 11, 2021
610bc23
run test nodes on new state.
cheme Nov 11, 2021
c0af4f1
fix
cheme Nov 11, 2021
89b28ac
Merge branch 'master' into state-update4-host2
cheme Nov 11, 2021
8e962f2
Merge branch 'state-update4-host2' into ecr-state-update-host
cheme Nov 12, 2021
2506dd9
Merge branch 'ecr-state-update-host' into kiz-inner-hashing-runtime-m…
cheme Nov 12, 2021
9db1b95
new test structure
kianenigma Nov 12, 2021
bb6b9a7
Merge branch 'kiz-inner-hashing-runtime-migration' of github.com:pari…
kianenigma Nov 12, 2021
13e6844
new testing stuff from emeric
kianenigma Nov 13, 2021
ab79457
Add commit_all, still not working
kianenigma Nov 14, 2021
07e495b
Fix all tests
kianenigma Nov 15, 2021
ba54fd5
add comment
kianenigma Nov 15, 2021
64e4fba
we have PoV tracking baby
kianenigma Nov 16, 2021
b367aac
document stuff, but proof size is still wrong
kianenigma Nov 17, 2021
a5a2a27
FUCK YEAH
kianenigma Nov 17, 2021
8a5cc10
a big batch of review comments
kianenigma Nov 18, 2021
14d9f42
add more tests
kianenigma Nov 19, 2021
4d392a1
tweak test
kianenigma Nov 19, 2021
d886baa
update config
kianenigma Nov 24, 2021
2df11e4
some remote-ext stuff
kianenigma Nov 25, 2021
363cbe1
Master.into()
kianenigma Jan 4, 2022
14cf05d
and upstream.into()
kianenigma Jan 4, 2022
8080e4c
delete some of the old stuff
kianenigma Jan 4, 2022
56d40e5
sync more files with master to minimize the diff
kianenigma Jan 4, 2022
fc689fc
Fix all tests
kianenigma Jan 4, 2022
bb0b00f
make signed migration a bit more relaxed
kianenigma Jan 4, 2022
6b83426
add witness check to signed submissions
kianenigma Jan 4, 2022
1626d19
allow custom migration to also go above limit
kianenigma Jan 4, 2022
0b3ea2d
Fix these pesky tests
kianenigma Jan 5, 2022
c2df41b
==== removal of the unsigned stuff ====
kianenigma Jan 5, 2022
8102e15
Make all tests work again
kianenigma Jan 5, 2022
de17ba0
separate the tests from the logic so it can be reused easier
kianenigma Jan 5, 2022
30c42cb
fix overall build
kianenigma Jan 5, 2022
0304711
Update frame/state-trie-migration/src/lib.rs
kianenigma Jan 14, 2022
0dcf25c
Update frame/state-trie-migration/src/lib.rs
kianenigma Jan 14, 2022
d822852
Master.into()
kianenigma Feb 4, 2022
b910012
Slightly better termination
kianenigma Feb 4, 2022
e883516
Master.into()
kianenigma Feb 9, 2022
6e9106a
some final tweaks
kianenigma Feb 9, 2022
4c119a0
Fix tests
kianenigma Feb 9, 2022
9a4e316
Restrict access to signed migrations
kianenigma Feb 9, 2022
fa388fa
mig rpc
cheme Feb 11, 2022
a912083
fix
cheme Feb 11, 2022
4af0ebc
Merge branch 'master' into kiz-inner-hashing-runtime-migration-check-rpc
cheme Feb 11, 2022
ada5916
better rpc name
cheme Feb 11, 2022
67f020e
Make rpc unsafe
cheme Feb 11, 2022
7c6ce54
address most of the review comments
kianenigma Feb 22, 2022
b33d8b8
fix defensive
kianenigma Feb 22, 2022
dfed611
New simplified code
kianenigma Feb 22, 2022
c0fe24d
Master.into()
kianenigma Feb 22, 2022
91b19d1
Fix weights
kianenigma Feb 22, 2022
80bb935
Master.into()
kianenigma Mar 3, 2022
756140b
fmt
kianenigma Mar 3, 2022
b7555fc
Update frame/state-trie-migration/src/lib.rs
kianenigma Mar 3, 2022
15f831d
make the tests correctly fail
kianenigma Mar 3, 2022
28bae65
Merge branch 'kiz-inner-hashing-runtime-migration' of github.com:pari…
kianenigma Mar 3, 2022
ec1ace7
Fix build
kianenigma Mar 3, 2022
4344530
Fix build
kianenigma Mar 3, 2022
7f60fb3
try and fix the benchmarks
kianenigma Mar 4, 2022
c3ae56b
fix build
kianenigma Mar 4, 2022
a956f97
Fix cargo file
kianenigma Mar 4, 2022
47654c2
Fix runtime deposit
kianenigma Mar 4, 2022
6b162bb
make rustdoc happy
kianenigma Mar 4, 2022
7294b02
Merge branch 'master' of https://github.com/paritytech/substrate into…
Mar 4, 2022
3b9f530
cargo run --quiet --profile=production --features=runtime-benchmarks…
Mar 4, 2022
7e6f57e
Merge branch 'kiz-inner-hashing-runtime-migration' into kiz-inner-has…
cheme Mar 4, 2022
8142f35
update rpc deps, try to process empty keys.
cheme Mar 4, 2022
c9df2f7
Merge branch 'master' into rpc-state-migration
cheme Mar 4, 2022
40d7f8e
move rpc crate
cheme Mar 7, 2022
3c84337
move check backend out of state machine
cheme Mar 7, 2022
0a5f3d9
Add primitive crate.
cheme Mar 7, 2022
92f378b
module code
cheme Mar 7, 2022
5632b53
fix runtime test
cheme Mar 7, 2022
f85752a
StateMigrationStatusProvider
cheme Mar 8, 2022
b1836a3
Pass backend to rpc.
cheme Mar 8, 2022
993d14e
fmt
cheme Mar 8, 2022
be61414
review changes
cheme Mar 9, 2022
53f1574
move rpc crate
cheme Mar 10, 2022
aa703c2
try remove primitive crate
cheme Mar 10, 2022
581b1ca
Update utils/frame/rpc/state-trie-migration-rpc/Cargo.toml
cheme Mar 11, 2022
d85c890
review changes.
cheme Mar 11, 2022
bdf7cc5
Merge branch 'rpc-state-migration' of github.com:cheme/substrate into…
cheme Mar 11, 2022
78a89bb
Merge branch 'master' into rpc-state-migration
cheme Mar 16, 2022
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
34 changes: 33 additions & 1 deletion Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ members = [
"client/service",
"client/service/test",
"client/state-db",
"client/state-trie-migration-rpc",
"client/sync-state-rpc",
"client/telemetry",
"client/tracing",
Expand Down Expand Up @@ -117,6 +118,7 @@ members = [
"frame/staking",
"frame/staking/reward-curve",
"frame/staking/reward-fn",
"frame/state-trie-migration",
"frame/sudo",
"frame/support",
"frame/support/procedural",
Expand Down Expand Up @@ -185,6 +187,7 @@ members = [
"primitives/session",
"primitives/staking",
"primitives/state-machine",
"primitives/state-trie-migration",
"primitives/std",
"primitives/storage",
"primitives/tasks",
Expand Down
3 changes: 2 additions & 1 deletion bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ pub fn new_partial(
let keystore = keystore_container.sync_keystore();
let chain_spec = config.chain_spec.cloned_box();

let rpc_backend = backend.clone();
let rpc_extensions_builder = move |deny_unsafe, subscription_executor| {
let deps = node_rpc::FullDeps {
client: client.clone(),
Expand All @@ -273,7 +274,7 @@ pub fn new_partial(
},
};

node_rpc::create_full(deps).map_err(Into::into)
node_rpc::create_full(deps, rpc_backend.clone()).map_err(Into::into)
};

(rpc_extensions_builder, rpc_setup)
Expand Down
1 change: 1 addition & 0 deletions bin/node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sc-finality-grandpa = { version = "0.10.0-dev", path = "../../../client/finality
sc-finality-grandpa-rpc = { version = "0.10.0-dev", path = "../../../client/finality-grandpa/rpc" }
sc-rpc-api = { version = "0.10.0-dev", path = "../../../client/rpc-api" }
sc-rpc = { version = "4.0.0-dev", path = "../../../client/rpc" }
sc-state-trie-migration-rpc = { version = "4.0.0-dev", path = "../../../client/state-trie-migration-rpc/" }
sc-sync-state-rpc = { version = "0.10.0-dev", path = "../../../client/sync-state-rpc" }
sp-api = { version = "4.0.0-dev", path = "../../../primitives/api" }
sp-block-builder = { version = "4.0.0-dev", path = "../../../primitives/block-builder" }
Expand Down
5 changes: 5 additions & 0 deletions bin/node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub type IoHandler = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
/// Instantiate all Full RPC extensions.
pub fn create_full<C, P, SC, B>(
deps: FullDeps<C, P, SC, B>,
backend: Arc<B>,
) -> Result<jsonrpc_core::IoHandler<sc_rpc_api::Metadata>, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
Expand Down Expand Up @@ -159,6 +160,10 @@ where
finality_provider,
)));

io.extend_with(sc_state_trie_migration_rpc::StateMigrationApi::to_delegate(
sc_state_trie_migration_rpc::MigrationRpc::new(client.clone(), backend, deny_unsafe),
));

io.extend_with(sc_sync_state_rpc::SyncStateRpcApi::to_delegate(
sc_sync_state_rpc::SyncStateRpcHandler::new(
chain_spec,
Expand Down
29 changes: 29 additions & 0 deletions client/state-trie-migration-rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "sc-state-trie-migration-rpc"
Copy link
Member

Choose a reason for hiding this comment

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

This crate should also be moved under the pallet. We already have multiple of these pallet rpc crates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had it under pallet at first but the dependencies from client crate sc-service to pallet was rejected.
Wait, I don't have this dependency anymore, think I can move all under pallet now (even move primitive to rpc as suggested) 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, actually rpc requires dependency to clients crate, which is not allowed (other frame crate can do without because they are using the RuntimeApi interface).

Copy link
Member

Choose a reason for hiding this comment

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

Then please move it to the utils/frame/rpc folder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then please move it to the utils/frame/rpc folder

That's cheating, but yes it results in one less crate, I'm happy with it.

version = "4.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
license = "Apache-2.0"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
description = "Node-specific RPC methods for interaction with state trie migration."
readme = "README.md"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3" }
jsonrpc-core = "18.0.0"
jsonrpc-core-client = "18.0.0"
jsonrpc-derive = "18.0.0"
serde = { version = "1", features = ["derive"] }
sp-state-trie-migration = { version = "4.0.0-dev", path = "../../primitives/state-trie-migration" }

# Substrate Dependencies
sc-client-api = { version = "4.0.0-dev", path = "../api" }
sc-rpc-api = { version = "0.10.0-dev", path = "../rpc-api" }
sp-runtime = { version = "6.0.0", path = "../../primitives/runtime" }

[dev-dependencies]
serde_json = "1"
3 changes: 3 additions & 0 deletions client/state-trie-migration-rpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Node-specific RPC methods for interaction with trie migration.

License: Apache-2.0
91 changes: 91 additions & 0 deletions client/state-trie-migration-rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// This file is part of Substrate.

// Copyright (C) 2019-2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Rpc for state migration.

use jsonrpc_core::{Error, ErrorCode, Result};
use jsonrpc_derive::rpc;
use sc_rpc_api::DenyUnsafe;
use serde::{Deserialize, Serialize};
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
use std::sync::Arc;

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct MigrationStatusResult {
top_remaining_to_migrate: u64,
child_remaining_to_migrate: u64,
}

/// Migration RPC methods.
#[rpc]
pub trait StateMigrationApi<BlockHash> {
/// Check current migration state.
///
/// This call is performed locally without submitting any transactions. Thus executing this
/// won't change any state. Nonetheless it is a VERY costy call that should be
/// only exposed to trusted peers.
#[rpc(name = "state_trieMigrationStatus")]
fn call(&self, at: Option<BlockHash>) -> Result<MigrationStatusResult>;
}

/// An implementation of state migration specific RPC methods.
pub struct MigrationRpc<C, B, BA> {
client: Arc<C>,
backend: Arc<BA>,
deny_unsafe: DenyUnsafe,
_marker: std::marker::PhantomData<(B, BA)>,
}

impl<C, B, BA> MigrationRpc<C, B, BA> {
/// Create new state migration rpc for the given reference to the client.
pub fn new(client: Arc<C>, backend: Arc<BA>, deny_unsafe: DenyUnsafe) -> Self {
MigrationRpc { client, backend, deny_unsafe, _marker: Default::default() }
}
}

impl<C, B, BA> StateMigrationApi<<B as BlockT>::Hash> for MigrationRpc<C, B, BA>
where
B: BlockT,
C: Send + Sync + 'static + sc_client_api::HeaderBackend<B>,
BA: 'static + sc_client_api::backend::Backend<B>,
{
fn call(&self, at: Option<<B as BlockT>::Hash>) -> Result<MigrationStatusResult> {
if let Err(err) = self.deny_unsafe.check_if_safe() {
return Err(err.into())
}

let block_id = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash));
let state = self.backend.state_at(block_id).map_err(error_into_rpc_err)?;
let (top, child) =
sp_state_trie_migration::migration_status(&state).map_err(error_into_rpc_err)?;

Ok(MigrationStatusResult {
top_remaining_to_migrate: top,
child_remaining_to_migrate: child,
})
}
}

fn error_into_rpc_err(err: impl std::fmt::Display) -> Error {
Error {
code: ErrorCode::ServerError(0), // TODO check errors code
Copy link
Member

Choose a reason for hiding this comment

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

TODO

message: "Error while checking migration state".into(),
data: Some(err.to_string().into()),
}
}
5 changes: 3 additions & 2 deletions frame/state-trie-migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sp-std = { default-features = false, path = "../../primitives/std" }
sp-io = { default-features = false, path = "../../primitives/io" }
sp-core = { default-features = false, path = "../../primitives/core" }
sp-runtime = { default-features = false, path = "../../primitives/runtime" }
sp-state-trie-migration = { optional = true, path = "../../primitives/state-trie-migration" }

frame-support = { default-features = false, path = "../support" }
frame-system = { default-features = false, path = "../system" }
Expand Down Expand Up @@ -49,9 +50,9 @@ std = [
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std"
"sp-std/std",
]
runtime-benchmarks = ["frame-benchmarking"]
try-runtime = ["frame-support/try-runtime"]

remote-test = [ "std", "zstd", "serde", "thousands", "remote-externalities" ]
remote-test = [ "std", "zstd", "serde", "thousands", "remote-externalities", "sp-state-trie-migration" ]
Loading