Try-runtime Revamp and Facelift (#12537)

* fix online/offline confusion

* unified cache file

* multi-threaded babyyy

* checkpoint for niklas

* compiles

* all tests pass with --test-threads 1

* child-tree scrape is also multi-threaded now.

* better thread splitting

* some suggestions (#12532)

* some suggestions

* tokio multithread

* move unused dependencies

* snapshot command

* fix rem

* a bit of cleanup

* support optional checks

* fix

* OCW command migrated to wasm-only, as an example

* state-version management fully in remote-ext

* almost everything move to wasm executor, some CLI flags reduced

* follow-chain works as well

* Master.into()

* everything builds now

* concurrent insertion and download for remote builds

* minor fix

* fix a bug

* checkpoint

* some updates

* fmt

* review comments

* fmt

* fix

* fmt

* update

* fmt

* rename

* fix the damn UI tests

* fmt

* remoe the thread abstraction for the time being

* cleanup

* fix CI

* fmt

* fix

* fix a few more things

* tweak log levels

* better error handling

* address grumbles: use futures::mpsc

* review comments

* fmt

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update utils/frame/try-runtime/cli/src/lib.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* better api version stuff

* some doc update

* a whole lot of docs

* fmt

* fix all docs

* fmt

* rpc rebase: Try-runtime Revamp and Facelift (#12921)

* Introduce sensible weight constants (#12868)

* Introduce sensible weight constants

* cargo fmt

* Remove unused import

* Add missing import

* ".git/.scripts/bench-bot.sh" pallet dev pallet_lottery

Co-authored-by: command-bot <>

* Checkout to the branch HEAD explicitly in `build-linux-substrate` (#12876)

* cli: Improve pruning documentation (#12819)

* cli: Improve pruning documentation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Keep `finalized` notation and remove `canonical` one

* cli: Fix cargo doc

* cli: `PruningModeClap` IR enum

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Convert PruningModeClap into pruning modes

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Use `PruningModeClap`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Rename to `DatabasePruningMode`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Implement `FromStr` instead of `clap::ValueEnum`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update client/cli/src/params/pruning_params.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Fix clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Add option documentation back

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Apply suggestions from code review

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>

* Revert "Move LockableCurrency trait to fungibles::Lockable and deprecate LockableCurrency (#12798)" (#12882)

This reverts commit 9a014d1ecd.

* Don't indefinitely block on shutting down Tokio (#12885)

* Don't indefinitely on shutting down Tokio

Now we wait in maximum 60 seconds before we shutdown the node. Tasks are may be leaked and leading
to some data corruption.

* Drink less :thinking_face:

* General Message Queue Pallet (#12485)

* The message queue

* Make fully generic

* Refactor

* Docs

* Refactor

* Use iter not slice

* Per-origin queues

* Multi-queue processing

* Introduce MaxReady

* Remove MaxReady in favour of ready ring

* Cleanups

* ReadyRing and tests

* Stale page reaping

* from_components -> from_parts

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Move WeightCounter to sp_weights

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add MockedWeightInfo

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Deploy to kitchensink

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use WeightCounter

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Small fixes and logging

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add service_page

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Typo

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Move service_page below service_queue

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add service_message

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use correct weight function

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Overweight execution

* Refactor

* Missing file

* Fix WeightCounter usage in scheduler

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix peek_index

Take into account that decoding from a mutable slice modifies it.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add tests and bench service_page_item

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add debug_info

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add no-progress check to service_queues

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add more benches

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Bound from_message and try_append_message

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add PageReaped event

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Rename BookStateOf and BookStateFor

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update tests and remove logging

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove redundant per-message origins; add footprint() and sweep_queue()

* Move testing stuff to mock.rs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add integration test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix no-progress check

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix debug_info

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fixup merge and tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix footprint tracking

* Introduce

* Formatting

* OverweightEnqueued event, auto-servicing config item

* Update tests and benchmarks

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Provide change handler

* Add missing BookStateFor::insert and call QueueChangeHandler

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update benchmarks and weights

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More tests...

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use weight metering functions

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* weightInfo::process_message_payload is gone

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add defensive_saturating_accrue

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Rename WeightCounter to WeightMeter

Ctr+Shift+H should do the trick.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test on_initialize

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add module docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove origin from MaxMessageLen

The message origin is not encoded into the heap and does
therefore not influence the max message length anymore.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add BoundedVec::as_slice

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test Page::{from_message, try_append_message}

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fixup docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Docs

* Do nothing in sweep_queue if the queue does not exist

... otherwise it inserts default values into the storage.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test ring (un)knitting

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Upgrade stress-test

Change the test to not assume that all queued messages will be
processed in the next block but split it over multiple.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More tests...

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Beauty fixes

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Rename BoundedVec::as_slice to as_bounded_slice

Conflicts with deref().as_slice() otherwise.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix imports

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove ReadyRing struct

Was used for testing only. Instead use 'fn assert_ring' which also
check the service head and backlinks.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Beauty fixes

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix stale page watermark

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix test feature and clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* QueueChanged handler is called correctly

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update benches

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Abstract testing functions

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Simplify tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make stuff compile

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Extend overweight execution benchmark

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove TODOs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test service queue with faulty MessageProcessor

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update pallet ui tests to 1.65

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Review doc fixes

Co-authored-by: Robert Klotzner <eskimor@users.noreply.github.com>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add weight_limit to extrinsic weight of execute_overweight

* Correctly return unused weight

* Return actual weight consumed in do_execute_overweight

* Review fixes

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Set version 7.0.0-dev

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make it compile

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Switch message_size to u64

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Switch message_count to u64

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix benchmarks

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make CI green

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Docs

* Update tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* ".git/.scripts/bench-bot.sh" pallet dev pallet_message_queue

* Dont mention README.md in the Cargo.toml

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove reference to readme

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: parity-processbot <>
Co-authored-by: Robert Klotzner <eskimor@users.noreply.github.com>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* zombienet timings adjusted (#12890)

* zombinet tests: add some timeout to allow net spin-up

Sometimes tests are failing at first try, as the pods were not up yet.
Adding timeout should allow the network to spin up properly.

* initial timeout increased to 30s

* Move import queue out of `sc-network` (#12764)

* Move import queue out of `sc-network`

Add supplementary asynchronous API for the import queue which means
it can be run as an independent task and communicated with through
the `ImportQueueService`.

This commit removes removes block and justification imports from
`sc-network` and provides `ChainSync` with a handle to import queue so
it can import blocks and justifications. Polling of the import queue is
moved complete out of `sc-network` and `sc_consensus::Link` is
implemented for `ChainSyncInterfaceHandled` so the import queue
can still influence the syncing process.

* Fix tests

* Apply review comments

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update client/network/sync/src/lib.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

Co-authored-by: Bastian Köcher <git@kchr.de>

* Trace response payload in default `jsonrpsee` middleware (#12886)

* Trace result in default `jsonrpsee` middleware

* `rpc_metrics::extra`

Co-authored-by: Bastian Köcher <git@kchr.de>

Co-authored-by: Bastian Köcher <git@kchr.de>

* Ensure that we inform all tasks to stop before starting the 60 seconds shutdown (#12897)

* Ensure that we inform all tasks to stop before starting the 60 seconds shutdown

The change of waiting in maximum 60 seconds for the node to shutdown actually introduced a bug. We
were actually waiting always 60 seconds as we didn't informed our tasks to shutdown. The solution to
this problem is to drop the task manager as this will then inform all tasks to end. It also adds
tests to ensure that the behaviors work as expected. (This should already have been done in the
first pr! :()

* ".git/.scripts/fmt.sh" 1

Co-authored-by: command-bot <>

* Safe desired targets call (#12826)

* checked call for desired targets

* fix compile

* fmt

* fix tests

* cleaner with and_then

* Fix typo (#12900)

* ValidateUnsigned: Improve docs. (#12870)

* ValidateUnsigned: Improve docs.

* Review comments

* rpc server with HTTP/WS on the same socket (#12663)

* jsonrpsee v0.16

add backwards compatibility

run old http server on http only

* cargo fmt

* update jsonrpsee 0.16.1

* less verbose cors log

* fix nit in log: WS -> HTTP

* revert needless changes in Cargo.lock

* remove unused features in tower

* fix nits; add client-core feature

* jsonrpsee v0.16.2

* `pallet-message-queue`: Fix license (#12895)

* Fix license

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add mock doc

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use explicit call indices (#12891)

* frame-system: explicit call index

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use explicit call indices

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* pallet-template: explicit call index

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* DNM: Temporarily require call_index

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "DNM: Temporarily require call_index"

This reverts commit c4934e312e12af72ca05a8029d7da753a9c99346.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Pin canonincalized block (#12902)

* Remove implicit approval chilling upon slash. (#12420)

* don't read slashing spans when taking election snapshot

* update cargo.toml

* bring back remote test

* fix merge stuff

* fix npos-voters function sig

* remove as much redundant diff as you can

* Update frame/staking/src/pallet/mod.rs

Co-authored-by: Andronik <write@reusable.software>

* fix

* Update frame/staking/src/pallet/impls.rs

* update lock

* fix all tests

* review comments

* fmt

* fix offence bench

* clippy

* ".git/.scripts/bench-bot.sh" pallet dev pallet_staking

Co-authored-by: Andronik <write@reusable.software>
Co-authored-by: Ankan <ankan.anurag@gmail.com>
Co-authored-by: command-bot <>

* bounties calls docs fix (#12909)

Co-authored-by: parity-processbot <>

* pallet-contracts migration pre-upgrade fix for v8 (#12905)

* Only run pre-v8 migration check for versions older than 8

* Logix fix

* use custom environment for publishing crates (#12912)

* [contracts] Add debug buffer limit + enforcement (#12845)

* Add debug buffer limit + enforcement

Add debug buffer limit + enforcement

* use BoundedVec for the debug buffer

* revert schedule (debug buf len limit not needed anymore)

* return DispatchError

* addressed review comments

* frame/remote-externalities: Fix clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/rpc: Add previous export

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Fixup some wrong dependencies (#12899)

* Fixup some wrong dependencies

Dev dependencies should not appear in the feature list. If features are required, they should be
directly enabled for the `dev-dependency`.

* More fixups

* Fix fix

* Remove deprecated feature

* Make all work properly and nice!!

* FMT

* Fix formatting

* add numerator and denominator to Rational128 Debug impl and increase precision of float representation (#12914)

* Fix state-db pinning (#12927)

* Pin all canonicalized blocks

* Added a test

* Docs

* [ci] add job switcher (#12922)

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Vlad <vladimir@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com>
Co-authored-by: Gavin Wood <gavin@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Robert Klotzner <eskimor@users.noreply.github.com>
Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com>
Co-authored-by: tgmichel <telmo@purestake.com>
Co-authored-by: Ankan <10196091+Ank4n@users.noreply.github.com>
Co-authored-by: Luke Schoen <ltfschoen@users.noreply.github.com>
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Andronik <write@reusable.software>
Co-authored-by: Ankan <ankan.anurag@gmail.com>
Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>
Co-authored-by: Dino Pačandi <3002868+Dinonard@users.noreply.github.com>
Co-authored-by: João Paulo Silva de Souza <77391175+joao-paulo-parity@users.noreply.github.com>
Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
Co-authored-by: Alexander Samusev <41779041+alvicsam@users.noreply.github.com>

* Revert "rpc rebase: Try-runtime Revamp and Facelift (#12921)"

This reverts commit 4ce770a9cb8daf1401529bda7d974b8c703f6b3e.

* Lexnv/kiz revamp try runtime stuff (#12932)

* Introduce sensible weight constants (#12868)

* Introduce sensible weight constants

* cargo fmt

* Remove unused import

* Add missing import

* ".git/.scripts/bench-bot.sh" pallet dev pallet_lottery

Co-authored-by: command-bot <>

* Checkout to the branch HEAD explicitly in `build-linux-substrate` (#12876)

* cli: Improve pruning documentation (#12819)

* cli: Improve pruning documentation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Keep `finalized` notation and remove `canonical` one

* cli: Fix cargo doc

* cli: `PruningModeClap` IR enum

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Convert PruningModeClap into pruning modes

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Use `PruningModeClap`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Rename to `DatabasePruningMode`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Implement `FromStr` instead of `clap::ValueEnum`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update client/cli/src/params/pruning_params.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Fix clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Add option documentation back

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Apply suggestions from code review

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>

* Revert "Move LockableCurrency trait to fungibles::Lockable and deprecate LockableCurrency (#12798)" (#12882)

This reverts commit 9a014d1ecd.

* Don't indefinitely block on shutting down Tokio (#12885)

* Don't indefinitely on shutting down Tokio

Now we wait in maximum 60 seconds before we shutdown the node. Tasks are may be leaked and leading
to some data corruption.

* Drink less :thinking_face:

* General Message Queue Pallet (#12485)

* The message queue

* Make fully generic

* Refactor

* Docs

* Refactor

* Use iter not slice

* Per-origin queues

* Multi-queue processing

* Introduce MaxReady

* Remove MaxReady in favour of ready ring

* Cleanups

* ReadyRing and tests

* Stale page reaping

* from_components -> from_parts

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Move WeightCounter to sp_weights

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add MockedWeightInfo

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Deploy to kitchensink

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use WeightCounter

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Small fixes and logging

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add service_page

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Typo

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Move service_page below service_queue

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add service_message

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use correct weight function

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Overweight execution

* Refactor

* Missing file

* Fix WeightCounter usage in scheduler

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix peek_index

Take into account that decoding from a mutable slice modifies it.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add tests and bench service_page_item

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add debug_info

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add no-progress check to service_queues

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add more benches

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Bound from_message and try_append_message

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add PageReaped event

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Rename BookStateOf and BookStateFor

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update tests and remove logging

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove redundant per-message origins; add footprint() and sweep_queue()

* Move testing stuff to mock.rs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add integration test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix no-progress check

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix debug_info

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fixup merge and tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix footprint tracking

* Introduce

* Formatting

* OverweightEnqueued event, auto-servicing config item

* Update tests and benchmarks

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Provide change handler

* Add missing BookStateFor::insert and call QueueChangeHandler

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update benchmarks and weights

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More tests...

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use weight metering functions

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* weightInfo::process_message_payload is gone

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add defensive_saturating_accrue

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Rename WeightCounter to WeightMeter

Ctr+Shift+H should do the trick.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test on_initialize

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add module docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove origin from MaxMessageLen

The message origin is not encoded into the heap and does
therefore not influence the max message length anymore.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add BoundedVec::as_slice

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test Page::{from_message, try_append_message}

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fixup docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Docs

* Do nothing in sweep_queue if the queue does not exist

... otherwise it inserts default values into the storage.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test ring (un)knitting

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Upgrade stress-test

Change the test to not assume that all queued messages will be
processed in the next block but split it over multiple.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More tests...

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Beauty fixes

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Rename BoundedVec::as_slice to as_bounded_slice

Conflicts with deref().as_slice() otherwise.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix imports

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove ReadyRing struct

Was used for testing only. Instead use 'fn assert_ring' which also
check the service head and backlinks.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Beauty fixes

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix stale page watermark

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix test feature and clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* QueueChanged handler is called correctly

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update benches

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Abstract testing functions

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Simplify tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make stuff compile

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Extend overweight execution benchmark

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove TODOs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test service queue with faulty MessageProcessor

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update pallet ui tests to 1.65

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Review doc fixes

Co-authored-by: Robert Klotzner <eskimor@users.noreply.github.com>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add weight_limit to extrinsic weight of execute_overweight

* Correctly return unused weight

* Return actual weight consumed in do_execute_overweight

* Review fixes

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Set version 7.0.0-dev

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make it compile

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Switch message_size to u64

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Switch message_count to u64

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix benchmarks

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make CI green

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Docs

* Update tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* ".git/.scripts/bench-bot.sh" pallet dev pallet_message_queue

* Dont mention README.md in the Cargo.toml

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove reference to readme

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: parity-processbot <>
Co-authored-by: Robert Klotzner <eskimor@users.noreply.github.com>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* zombienet timings adjusted (#12890)

* zombinet tests: add some timeout to allow net spin-up

Sometimes tests are failing at first try, as the pods were not up yet.
Adding timeout should allow the network to spin up properly.

* initial timeout increased to 30s

* Move import queue out of `sc-network` (#12764)

* Move import queue out of `sc-network`

Add supplementary asynchronous API for the import queue which means
it can be run as an independent task and communicated with through
the `ImportQueueService`.

This commit removes removes block and justification imports from
`sc-network` and provides `ChainSync` with a handle to import queue so
it can import blocks and justifications. Polling of the import queue is
moved complete out of `sc-network` and `sc_consensus::Link` is
implemented for `ChainSyncInterfaceHandled` so the import queue
can still influence the syncing process.

* Fix tests

* Apply review comments

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update client/network/sync/src/lib.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

Co-authored-by: Bastian Köcher <git@kchr.de>

* Trace response payload in default `jsonrpsee` middleware (#12886)

* Trace result in default `jsonrpsee` middleware

* `rpc_metrics::extra`

Co-authored-by: Bastian Köcher <git@kchr.de>

Co-authored-by: Bastian Köcher <git@kchr.de>

* Ensure that we inform all tasks to stop before starting the 60 seconds shutdown (#12897)

* Ensure that we inform all tasks to stop before starting the 60 seconds shutdown

The change of waiting in maximum 60 seconds for the node to shutdown actually introduced a bug. We
were actually waiting always 60 seconds as we didn't informed our tasks to shutdown. The solution to
this problem is to drop the task manager as this will then inform all tasks to end. It also adds
tests to ensure that the behaviors work as expected. (This should already have been done in the
first pr! :()

* ".git/.scripts/fmt.sh" 1

Co-authored-by: command-bot <>

* Safe desired targets call (#12826)

* checked call for desired targets

* fix compile

* fmt

* fix tests

* cleaner with and_then

* Fix typo (#12900)

* ValidateUnsigned: Improve docs. (#12870)

* ValidateUnsigned: Improve docs.

* Review comments

* rpc server with HTTP/WS on the same socket (#12663)

* jsonrpsee v0.16

add backwards compatibility

run old http server on http only

* cargo fmt

* update jsonrpsee 0.16.1

* less verbose cors log

* fix nit in log: WS -> HTTP

* revert needless changes in Cargo.lock

* remove unused features in tower

* fix nits; add client-core feature

* jsonrpsee v0.16.2

* `pallet-message-queue`: Fix license (#12895)

* Fix license

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add mock doc

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use explicit call indices (#12891)

* frame-system: explicit call index

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use explicit call indices

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* pallet-template: explicit call index

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* DNM: Temporarily require call_index

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "DNM: Temporarily require call_index"

This reverts commit c4934e312e12af72ca05a8029d7da753a9c99346.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Pin canonincalized block (#12902)

* Remove implicit approval chilling upon slash. (#12420)

* don't read slashing spans when taking election snapshot

* update cargo.toml

* bring back remote test

* fix merge stuff

* fix npos-voters function sig

* remove as much redundant diff as you can

* Update frame/staking/src/pallet/mod.rs

Co-authored-by: Andronik <write@reusable.software>

* fix

* Update frame/staking/src/pallet/impls.rs

* update lock

* fix all tests

* review comments

* fmt

* fix offence bench

* clippy

* ".git/.scripts/bench-bot.sh" pallet dev pallet_staking

Co-authored-by: Andronik <write@reusable.software>
Co-authored-by: Ankan <ankan.anurag@gmail.com>
Co-authored-by: command-bot <>

* bounties calls docs fix (#12909)

Co-authored-by: parity-processbot <>

* pallet-contracts migration pre-upgrade fix for v8 (#12905)

* Only run pre-v8 migration check for versions older than 8

* Logix fix

* use custom environment for publishing crates (#12912)

* [contracts] Add debug buffer limit + enforcement (#12845)

* Add debug buffer limit + enforcement

Add debug buffer limit + enforcement

* use BoundedVec for the debug buffer

* revert schedule (debug buf len limit not needed anymore)

* return DispatchError

* addressed review comments

* frame/remote-externalities: Fix clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/rpc: Add previous export

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Fixup some wrong dependencies (#12899)

* Fixup some wrong dependencies

Dev dependencies should not appear in the feature list. If features are required, they should be
directly enabled for the `dev-dependency`.

* More fixups

* Fix fix

* Remove deprecated feature

* Make all work properly and nice!!

* FMT

* Fix formatting

* add numerator and denominator to Rational128 Debug impl and increase precision of float representation (#12914)

* Fix state-db pinning (#12927)

* Pin all canonicalized blocks

* Added a test

* Docs

* [ci] add job switcher (#12922)

* Use LOG_TARGET in consensus related crates (#12875)

* Use shared LOG_TARGET in consensus related crates
* Rename target from "afg" to "grandpa"

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Vlad <vladimir@parity.io>
Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com>
Co-authored-by: Gavin Wood <gavin@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Robert Klotzner <eskimor@users.noreply.github.com>
Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com>
Co-authored-by: tgmichel <telmo@purestake.com>
Co-authored-by: Ankan <10196091+Ank4n@users.noreply.github.com>
Co-authored-by: Luke Schoen <ltfschoen@users.noreply.github.com>
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>
Co-authored-by: Andronik <write@reusable.software>
Co-authored-by: Ankan <ankan.anurag@gmail.com>
Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>
Co-authored-by: Dino Pačandi <3002868+Dinonard@users.noreply.github.com>
Co-authored-by: João Paulo Silva de Souza <77391175+joao-paulo-parity@users.noreply.github.com>
Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
Co-authored-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
Co-authored-by: Alexander Samusev <41779041+alvicsam@users.noreply.github.com>
Co-authored-by: Davide Galassi <davxy@datawok.net>

* Revert "Lexnv/kiz revamp try runtime stuff (#12932)"

This reverts commit 378cfb26d984bcde467781f07ef8ddb6998212cb.

* fmt

* update

* fix publish

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Vlad <vladimir@parity.io>
Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com>
Co-authored-by: Gavin Wood <gavin@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Robert Klotzner <eskimor@users.noreply.github.com>
Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com>
Co-authored-by: tgmichel <telmo@purestake.com>
Co-authored-by: Ankan <10196091+Ank4n@users.noreply.github.com>
Co-authored-by: Luke Schoen <ltfschoen@users.noreply.github.com>
Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>
Co-authored-by: Andronik <write@reusable.software>
Co-authored-by: Ankan <ankan.anurag@gmail.com>
Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>
Co-authored-by: Dino Pačandi <3002868+Dinonard@users.noreply.github.com>
Co-authored-by: João Paulo Silva de Souza <77391175+joao-paulo-parity@users.noreply.github.com>
Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
Co-authored-by: Alexander Samusev <41779041+alvicsam@users.noreply.github.com>
Co-authored-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Davide Galassi <davxy@datawok.net>
This commit is contained in:
Kian Paimani
2022-12-14 23:59:01 +00:00
committed by GitHub
parent 14bd4bde25
commit c1ed1901e1
40 changed files with 1778 additions and 1462 deletions
@@ -12,11 +12,6 @@ description = "Cli command runtime testing and dry-running"
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
clap = { version = "4.0.9", features = ["derive"] }
log = "0.4.17"
parity-scale-codec = "3.0.0"
serde = "1.0.136"
zstd = { version = "0.11.2", default-features = false }
remote-externalities = { version = "0.10.0-dev", path = "../../remote-externalities", package = "frame-remote-externalities" }
sc-chain-spec = { version = "4.0.0-dev", path = "../../../../client/chain-spec" }
sc-cli = { version = "0.10.0-dev", path = "../../../../client/cli" }
@@ -27,16 +22,27 @@ sp-externalities = { version = "0.13.0", path = "../../../../primitives/external
sp-io = { version = "7.0.0", path = "../../../../primitives/io" }
sp-keystore = { version = "0.13.0", path = "../../../../primitives/keystore" }
sp-runtime = { version = "7.0.0", path = "../../../../primitives/runtime" }
sp-rpc = { version = "6.0.0", path = "../../../../primitives/rpc" }
sp-state-machine = { version = "0.13.0", path = "../../../../primitives/state-machine" }
sp-version = { version = "5.0.0", path = "../../../../primitives/version" }
sp-debug-derive = { path = "../../../../primitives/debug-derive" }
sp-api = { path = "../../../../primitives/api" }
sp-weights = { version = "4.0.0", path = "../../../../primitives/weights" }
frame-try-runtime = { optional = true, path = "../../../../frame/try-runtime" }
substrate-rpc-client = { path = "../../rpc/client" }
parity-scale-codec = "3.0.0"
hex = "0.4.3"
clap = { version = "4.0.9", features = ["derive"] }
log = "0.4.17"
serde = "1.0.136"
zstd = { version = "0.11.2", default-features = false }
[dev-dependencies]
tokio = "1.22.0"
[features]
try-runtime = [
"sp-debug-derive/force-debug",
"frame-try-runtime/try-runtime",
]
@@ -0,0 +1,78 @@
// This file is part of Substrate.
// Copyright (C) 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.
use crate::{build_executor, LiveState, SharedParams, State, LOG_TARGET};
use sc_executor::sp_wasm_interface::HostFunctions;
use sp_runtime::traits::{Block as BlockT, NumberFor};
use std::{fmt::Debug, str::FromStr};
use substrate_rpc_client::{ws_client, StateApi};
/// Configurations of the [`crate::Command::CreateSnapshot`].
#[derive(Debug, Clone, clap::Parser)]
pub struct CreateSnapshotCmd {
/// The source of the snapshot. Must be a remote node.
#[clap(flatten)]
pub from: LiveState,
/// The snapshot path to write to.
///
/// If not provided `<spec-name>-<spec-version>@<block-hash>.snap` will be used.
pub snapshot_path: Option<String>,
}
/// inner command for `Command::CreateSnapshot`.
pub(crate) async fn create_snapshot<Block, HostFns>(
shared: SharedParams,
command: CreateSnapshotCmd,
) -> sc_cli::Result<()>
where
Block: BlockT + serde::de::DeserializeOwned,
Block::Hash: FromStr + serde::de::DeserializeOwned,
Block::Header: serde::de::DeserializeOwned,
<Block::Hash as FromStr>::Err: Debug,
NumberFor<Block>: FromStr,
<NumberFor<Block> as FromStr>::Err: Debug,
HostFns: HostFunctions,
{
let snapshot_path = command.snapshot_path;
if !matches!(shared.runtime, crate::Runtime::Existing) {
return Err("creating a snapshot is only possible with --runtime existing.".into())
}
let path = match snapshot_path {
Some(path) => path,
None => {
let rpc = ws_client(&command.from.uri).await.unwrap();
let remote_spec = StateApi::<Block::Hash>::runtime_version(&rpc, None).await.unwrap();
let path_str = format!(
"{}-{}@{}.snap",
remote_spec.spec_name.to_lowercase(),
remote_spec.spec_version,
command.from.at.clone().unwrap_or("latest".to_owned())
);
log::info!(target: LOG_TARGET, "snapshot path not provided (-s), using '{}'", path_str);
path_str.into()
},
};
let executor = build_executor::<HostFns>(&shared);
let _ = State::Live(command.from)
.into_ext::<Block, HostFns>(&shared, &executor, Some(path.into()))
.await?;
Ok(())
}
@@ -16,30 +16,25 @@
// limitations under the License.
use crate::{
build_executor, ensure_matching_spec, extract_code, full_extensions, hash_of, local_spec,
state_machine_call_with_proof, SharedParams, State, LOG_TARGET,
build_executor, full_extensions, rpc_err_handler, state_machine_call_with_proof, LiveState,
SharedParams, State, LOG_TARGET,
};
use parity_scale_codec::Encode;
use sc_service::{Configuration, NativeExecutionDispatch};
use sp_core::storage::well_known_keys;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor};
use sc_executor::sp_wasm_interface::HostFunctions;
use sp_rpc::{list::ListOrValue, number::NumberOrHex};
use sp_runtime::{
generic::SignedBlock,
traits::{Block as BlockT, Header as HeaderT, NumberFor},
};
use std::{fmt::Debug, str::FromStr};
use substrate_rpc_client::{ws_client, ChainApi};
/// Configurations of the [`Command::ExecuteBlock`].
/// Configurations of the [`crate::Command::ExecuteBlock`].
///
/// This will always call into `TryRuntime_execute_block`, which can optionally skip the state-root
/// check (useful for trying a unreleased runtime), and can execute runtime sanity checks as well.
#[derive(Debug, Clone, clap::Parser)]
pub struct ExecuteBlockCmd {
/// Overwrite the wasm code in state or not.
#[arg(long)]
overwrite_wasm_code: bool,
/// If set the state root check is disabled.
#[arg(long)]
no_state_root_check: bool,
/// Which try-state targets to execute when running this command.
///
/// Expected values:
@@ -49,69 +44,28 @@ pub struct ExecuteBlockCmd {
/// `Staking, System`).
/// - `rr-[x]` where `[x]` is a number. Then, the given number of pallets are checked in a
/// round-robin fashion.
#[arg(long, default_value = "none")]
try_state: frame_try_runtime::TryStateSelect,
/// The block hash at which to fetch the block.
///
/// If the `live` state type is being used, then this can be omitted, and is equal to whatever
/// the `state::at` is. Only use this (with care) when combined with a snapshot.
#[arg(
long,
value_parser = crate::parse::hash
)]
block_at: Option<String>,
#[arg(long, default_value = "all")]
pub try_state: frame_try_runtime::TryStateSelect,
/// The ws uri from which to fetch the block.
///
/// If the `live` state type is being used, then this can be omitted, and is equal to whatever
/// the `state::uri` is. Only use this (with care) when combined with a snapshot.
/// This will always fetch the next block of whatever `state` is referring to, because this is
/// the only sensible combination. In other words, if you have the state of block `n`, you
/// should execute block `n+1` on top of it.
///
/// If `state` is `Live`, this can be ignored and the same uri is used for both.
#[arg(
long,
value_parser = crate::parse::url
)]
block_ws_uri: Option<String>,
pub block_ws_uri: Option<String>,
/// The state type to use.
///
/// For this command only, if the `live` is used, then state of the parent block is fetched.
///
/// If `block_at` is provided, then the [`State::Live::at`] is being ignored.
#[command(subcommand)]
state: State,
pub state: State,
}
impl ExecuteBlockCmd {
async fn block_at<Block: BlockT>(&self, ws_uri: String) -> sc_cli::Result<Block::Hash>
where
Block::Hash: FromStr + serde::de::DeserializeOwned,
<Block::Hash as FromStr>::Err: Debug,
Block::Header: serde::de::DeserializeOwned,
{
let rpc = ws_client(&ws_uri).await?;
match (&self.block_at, &self.state) {
(Some(block_at), State::Snap { .. }) => hash_of::<Block>(block_at),
(Some(block_at), State::Live { .. }) => {
log::warn!(target: LOG_TARGET, "--block-at is provided while state type is live. the `Live::at` will be ignored");
hash_of::<Block>(block_at)
},
(None, State::Live { at: None, .. }) => {
log::warn!(
target: LOG_TARGET,
"No --block-at or --at provided, using the latest finalized block instead"
);
ChainApi::<(), Block::Hash, Block::Header, ()>::finalized_head(&rpc)
.await
.map_err(|e| e.to_string().into())
},
(None, State::Live { at: Some(at), .. }) => hash_of::<Block>(at),
_ => {
panic!("either `--block-at` must be provided, or state must be `live with a proper `--at``");
},
}
}
fn block_ws_uri<Block: BlockT>(&self) -> String
where
Block::Hash: FromStr,
@@ -123,7 +77,7 @@ impl ExecuteBlockCmd {
log::error!(target: LOG_TARGET, "--block-uri is provided while state type is live, Are you sure you know what you are doing?");
block_ws_uri.to_owned()
},
(None, State::Live { uri, .. }) => uri.clone(),
(None, State::Live(LiveState { uri, .. })) => uri.clone(),
(None, State::Snap { .. }) => {
panic!("either `--block-uri` must be provided, or state must be `live`");
},
@@ -131,10 +85,9 @@ impl ExecuteBlockCmd {
}
}
pub(crate) async fn execute_block<Block, ExecDispatch>(
pub(crate) async fn execute_block<Block, HostFns>(
shared: SharedParams,
command: ExecuteBlockCmd,
config: Configuration,
) -> sc_cli::Result<()>
where
Block: BlockT + serde::de::DeserializeOwned,
@@ -142,79 +95,77 @@ where
<Block::Hash as FromStr>::Err: Debug,
Block::Hash: serde::de::DeserializeOwned,
Block::Header: serde::de::DeserializeOwned,
NumberFor<Block>: FromStr,
<NumberFor<Block> as FromStr>::Err: Debug,
ExecDispatch: NativeExecutionDispatch + 'static,
<NumberFor<Block> as TryInto<u64>>::Error: Debug,
HostFns: HostFunctions,
{
let executor = build_executor::<ExecDispatch>(&shared, &config);
let execution = shared.execution;
let executor = build_executor::<HostFns>(&shared);
let ext = command.state.into_ext::<Block, HostFns>(&shared, &executor, None).await?;
// get the block number associated with this block.
let block_ws_uri = command.block_ws_uri::<Block>();
let block_at = command.block_at::<Block>(block_ws_uri.clone()).await?;
let rpc = ws_client(&block_ws_uri).await?;
let block: Block = ChainApi::<(), Block::Hash, Block::Header, _>::block(&rpc, Some(block_at))
.await
.unwrap()
.unwrap();
let parent_hash = block.header().parent_hash();
log::info!(
target: LOG_TARGET,
"fetched block #{:?} from {:?}, parent_hash to fetch the state {:?}",
block.header().number(),
block_ws_uri,
parent_hash
);
let next_hash = next_hash_of::<Block>(&rpc, ext.block_hash).await?;
let ext = {
let builder = command
.state
.builder::<Block>()?
// make sure the state is being build with the parent hash, if it is online.
.overwrite_online_at(parent_hash.to_owned())
.state_version(shared.state_version);
log::info!(target: LOG_TARGET, "fetching next block: {:?} ", next_hash);
let builder = if command.overwrite_wasm_code {
log::info!(
target: LOG_TARGET,
"replacing the in-storage :code: with the local code from {}'s chain_spec (your local repo)",
config.chain_spec.name(),
);
let (code_key, code) = extract_code(&config.chain_spec)?;
builder.inject_hashed_key_value(&[(code_key, code)])
} else {
builder.inject_hashed_key(well_known_keys::CODE)
};
builder.build().await?
};
let block = ChainApi::<(), Block::Hash, Block::Header, SignedBlock<Block>>::block(
&rpc,
Some(next_hash),
)
.await
.map_err(rpc_err_handler)?
.expect("header exists, block should also exist; qed")
.block;
// A digest item gets added when the runtime is processing the block, so we need to pop
// the last one to be consistent with what a gossiped block would contain.
let (mut header, extrinsics) = block.deconstruct();
header.digest_mut().pop();
let block = Block::new(header, extrinsics);
let payload = (block.clone(), !command.no_state_root_check, command.try_state).encode();
let (expected_spec_name, expected_spec_version, _) =
local_spec::<Block, ExecDispatch>(&ext, &executor);
ensure_matching_spec::<Block>(
block_ws_uri.clone(),
expected_spec_name,
expected_spec_version,
shared.no_spec_check_panic,
)
.await;
// for now, hardcoded for the sake of simplicity. We might customize them one day.
let state_root_check = false;
let signature_check = false;
let payload = (block.clone(), state_root_check, signature_check, command.try_state).encode();
let _ = state_machine_call_with_proof::<Block, ExecDispatch>(
let _ = state_machine_call_with_proof::<Block, HostFns>(
&ext,
&executor,
execution,
"TryRuntime_execute_block",
&payload,
full_extensions(),
)?;
log::info!(target: LOG_TARGET, "Core_execute_block executed without errors.");
Ok(())
}
pub(crate) async fn next_hash_of<Block: BlockT>(
rpc: &substrate_rpc_client::WsClient,
hash: Block::Hash,
) -> sc_cli::Result<Block::Hash>
where
Block: BlockT + serde::de::DeserializeOwned,
Block::Header: serde::de::DeserializeOwned,
{
let number = ChainApi::<(), Block::Hash, Block::Header, ()>::header(rpc, Some(hash))
.await
.map_err(rpc_err_handler)
.and_then(|maybe_header| maybe_header.ok_or("header_not_found").map(|h| *h.number()))?;
let next = number + sp_runtime::traits::One::one();
let next_hash = match ChainApi::<(), Block::Hash, Block::Header, ()>::block_hash(
rpc,
Some(ListOrValue::Value(NumberOrHex::Number(
next.try_into().map_err(|_| "failed to convert number to block number")?,
))),
)
.await
.map_err(rpc_err_handler)?
{
ListOrValue::Value(t) => t.expect("value passed in; value comes out; qed"),
_ => unreachable!(),
};
Ok(next_hash)
}
@@ -16,32 +16,33 @@
// limitations under the License.
use crate::{
build_executor, ensure_matching_spec, extract_code, full_extensions, local_spec, parse,
state_machine_call_with_proof, SharedParams, LOG_TARGET,
build_executor, full_extensions, parse, rpc_err_handler, state_machine_call_with_proof,
LiveState, SharedParams, State, LOG_TARGET,
};
use parity_scale_codec::{Decode, Encode};
use remote_externalities::{Builder, Mode, OnlineConfig};
use sc_executor::NativeExecutionDispatch;
use sc_service::Configuration;
use sc_executor::sp_wasm_interface::HostFunctions;
use serde::{de::DeserializeOwned, Serialize};
use sp_core::H256;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor};
use sp_runtime::{
generic::SignedBlock,
traits::{Block as BlockT, Header as HeaderT, NumberFor},
};
use std::{fmt::Debug, str::FromStr};
use substrate_rpc_client::{ws_client, ChainApi, FinalizedHeaders, Subscription, WsClient};
const SUB: &str = "chain_subscribeFinalizedHeads";
const UN_SUB: &str = "chain_unsubscribeFinalizedHeads";
/// Configurations of the [`Command::FollowChain`].
/// Configurations of the [`crate::Command::FollowChain`].
#[derive(Debug, Clone, clap::Parser)]
pub struct FollowChainCmd {
/// The url to connect to.
#[arg(short, long, value_parser = parse::url)]
uri: String,
pub uri: String,
/// If set, then the state root check is enabled.
#[arg(long)]
state_root_check: bool,
pub state_root_check: bool,
/// Which try-state targets to execute when running this command.
///
@@ -52,12 +53,12 @@ pub struct FollowChainCmd {
/// `Staking, System`).
/// - `rr-[x]` where `[x]` is a number. Then, the given number of pallets are checked in a
/// round-robin fashion.
#[arg(long, default_value = "none")]
try_state: frame_try_runtime::TryStateSelect,
#[arg(long, default_value = "all")]
pub try_state: frame_try_runtime::TryStateSelect,
/// If present, a single connection to a node will be kept and reused for fetching blocks.
#[arg(long)]
keep_connection: bool,
pub keep_connection: bool,
}
/// Start listening for with `SUB` at `url`.
@@ -77,10 +78,9 @@ async fn start_subscribing<Header: DeserializeOwned + Serialize + Send + Sync +
Ok((client, sub))
}
pub(crate) async fn follow_chain<Block, ExecDispatch>(
pub(crate) async fn follow_chain<Block, HostFns>(
shared: SharedParams,
command: FollowChainCmd,
config: Configuration,
) -> sc_cli::Result<()>
where
Block: BlockT<Hash = H256> + DeserializeOwned,
@@ -89,26 +89,35 @@ where
<Block::Hash as FromStr>::Err: Debug,
NumberFor<Block>: FromStr,
<NumberFor<Block> as FromStr>::Err: Debug,
ExecDispatch: NativeExecutionDispatch + 'static,
HostFns: HostFunctions,
{
let mut maybe_state_ext = None;
let (rpc, subscription) = start_subscribing::<Block::Header>(&command.uri).await?;
let (code_key, code) = extract_code(&config.chain_spec)?;
let executor = build_executor::<ExecDispatch>(&shared, &config);
let execution = shared.execution;
let mut finalized_headers: FinalizedHeaders<Block, _, _> =
FinalizedHeaders::new(&rpc, subscription);
let mut maybe_state_ext = None;
let executor = build_executor::<HostFns>(&shared);
while let Some(header) = finalized_headers.next().await {
let hash = header.hash();
let number = header.number();
let block: Block = ChainApi::<(), Block::Hash, Block::Header, _>::block(&rpc, Some(hash))
.await
.unwrap()
.unwrap();
let block =
ChainApi::<(), Block::Hash, Block::Header, SignedBlock<Block>>::block(&rpc, Some(hash))
.await
.or_else(|e| {
if matches!(e, substrate_rpc_client::Error::ParseError(_)) {
log::error!(
"failed to parse the block format of remote against the local \
codebase. The block format has changed, and follow-chain cannot run in \
this case. Try running this command in a branch of your codebase that has \
the same block format as the remote chain. For now, we replace the block with an empty one"
);
}
Err(rpc_err_handler(e))
})?
.expect("if header exists, block should also exist.")
.block;
log::debug!(
target: LOG_TARGET,
@@ -120,49 +129,40 @@ where
// create an ext at the state of this block, whatever is the first subscription event.
if maybe_state_ext.is_none() {
let builder = Builder::<Block>::new()
.mode(Mode::Online(OnlineConfig {
transport: command.uri.clone().into(),
at: Some(*header.parent_hash()),
..Default::default()
}))
.state_version(shared.state_version);
let new_ext = builder
.inject_hashed_key_value(&[(code_key.clone(), code.clone())])
.build()
.await?;
log::info!(
target: LOG_TARGET,
"initialized state externalities at {:?}, storage root {:?}",
number,
new_ext.as_backend().root()
);
let (expected_spec_name, expected_spec_version, spec_state_version) =
local_spec::<Block, ExecDispatch>(&new_ext, &executor);
ensure_matching_spec::<Block>(
command.uri.clone(),
expected_spec_name,
expected_spec_version,
shared.no_spec_check_panic,
)
.await;
maybe_state_ext = Some((new_ext, spec_state_version));
let state = State::Live(LiveState {
uri: command.uri.clone(),
// a bit dodgy, we have to un-parse the has to a string again and re-parse it
// inside.
at: Some(hex::encode(header.parent_hash().encode())),
pallet: vec![],
child_tree: true,
});
let ext = state.into_ext::<Block, HostFns>(&shared, &executor, None).await?;
maybe_state_ext = Some(ext);
}
let (state_ext, spec_state_version) =
let state_ext =
maybe_state_ext.as_mut().expect("state_ext either existed or was just created");
let (mut changes, encoded_result) = state_machine_call_with_proof::<Block, ExecDispatch>(
let result = state_machine_call_with_proof::<Block, HostFns>(
state_ext,
&executor,
execution,
"TryRuntime_execute_block",
(block, command.state_root_check, command.try_state.clone()).encode().as_ref(),
full_extensions(),
)?;
);
if let Err(why) = result {
log::error!(
target: LOG_TARGET,
"failed to execute block {:?} due to {:?}",
number,
why
);
continue
}
let (mut changes, encoded_result) = result.expect("checked to be Ok; qed");
let consumed_weight = <sp_weights::Weight as Decode>::decode(&mut &*encoded_result)
.map_err(|e| format!("failed to decode weight: {:?}", e))?;
@@ -171,13 +171,13 @@ where
.drain_storage_changes(
&state_ext.backend,
&mut Default::default(),
// Note that in case a block contains a runtime upgrade,
// state version could potentially be incorrect here,
// this is very niche and would only result in unaligned
// roots, so this use case is ignored for now.
*spec_state_version,
// Note that in case a block contains a runtime upgrade, state version could
// potentially be incorrect here, this is very niche and would only result in
// unaligned roots, so this use case is ignored for now.
state_ext.state_version,
)
.unwrap();
state_ext.backend.apply_transaction(
storage_changes.transaction_storage_root,
storage_changes.transaction,
@@ -15,7 +15,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
pub(crate) mod execute_block;
pub(crate) mod follow_chain;
pub(crate) mod offchain_worker;
pub(crate) mod on_runtime_upgrade;
pub mod create_snapshot;
pub mod execute_block;
pub mod follow_chain;
pub mod offchain_worker;
pub mod on_runtime_upgrade;
@@ -16,34 +16,18 @@
// limitations under the License.
use crate::{
build_executor, ensure_matching_spec, extract_code, full_extensions, hash_of, local_spec,
parse, state_machine_call, SharedParams, State, LOG_TARGET,
build_executor, commands::execute_block::next_hash_of, full_extensions, parse, rpc_err_handler,
state_machine_call, LiveState, SharedParams, State, LOG_TARGET,
};
use parity_scale_codec::Encode;
use sc_executor::NativeExecutionDispatch;
use sc_service::Configuration;
use sp_core::storage::well_known_keys;
use sp_runtime::traits::{Block as BlockT, Header, NumberFor};
use sc_executor::sp_wasm_interface::HostFunctions;
use sp_runtime::traits::{Block as BlockT, NumberFor};
use std::{fmt::Debug, str::FromStr};
use substrate_rpc_client::{ws_client, ChainApi};
/// Configurations of the [`Command::OffchainWorker`].
/// Configurations of the [`crate::Command::OffchainWorker`].
#[derive(Debug, Clone, clap::Parser)]
pub struct OffchainWorkerCmd {
/// Overwrite the wasm code in state or not.
#[arg(long)]
overwrite_wasm_code: bool,
/// The block hash at which to fetch the header.
///
/// If the `live` state type is being used, then this can be omitted, and is equal to whatever
/// the `state::at` is. Only use this (with care) when combined with a snapshot.
#[arg(
long,
value_parser = parse::hash
)]
header_at: Option<String>,
/// The ws uri from which to fetch the header.
///
/// If the `live` state type is being used, then this can be omitted, and is equal to whatever
@@ -52,7 +36,7 @@ pub struct OffchainWorkerCmd {
long,
value_parser = parse::url
)]
header_ws_uri: Option<String>,
pub header_ws_uri: Option<String>,
/// The state type to use.
#[command(subcommand)]
@@ -60,24 +44,6 @@ pub struct OffchainWorkerCmd {
}
impl OffchainWorkerCmd {
fn header_at<Block: BlockT>(&self) -> sc_cli::Result<Block::Hash>
where
Block::Hash: FromStr,
<Block::Hash as FromStr>::Err: Debug,
{
match (&self.header_at, &self.state) {
(Some(header_at), State::Snap { .. }) => hash_of::<Block>(header_at),
(Some(header_at), State::Live { .. }) => {
log::error!(target: LOG_TARGET, "--header-at is provided while state type is live, this will most likely lead to a nonsensical result.");
hash_of::<Block>(header_at)
},
(None, State::Live { at: Some(at), .. }) => hash_of::<Block>(at),
_ => {
panic!("either `--header-at` must be provided, or state must be `live` with a proper `--at`");
},
}
}
fn header_ws_uri<Block: BlockT>(&self) -> String
where
Block::Hash: FromStr,
@@ -89,7 +55,7 @@ impl OffchainWorkerCmd {
log::error!(target: LOG_TARGET, "--header-uri is provided while state type is live, this will most likely lead to a nonsensical result.");
header_ws_uri.to_owned()
},
(None, State::Live { uri, .. }) => uri.clone(),
(None, State::Live(LiveState { uri, .. })) => uri.clone(),
(None, State::Snap { .. }) => {
panic!("either `--header-uri` must be provided, or state must be `live`");
},
@@ -97,76 +63,42 @@ impl OffchainWorkerCmd {
}
}
pub(crate) async fn offchain_worker<Block, ExecDispatch>(
pub(crate) async fn offchain_worker<Block, HostFns>(
shared: SharedParams,
command: OffchainWorkerCmd,
config: Configuration,
) -> sc_cli::Result<()>
where
Block: BlockT + serde::de::DeserializeOwned,
Block::Hash: FromStr,
Block::Header: serde::de::DeserializeOwned,
Block::Hash: FromStr,
<Block::Hash as FromStr>::Err: Debug,
NumberFor<Block>: FromStr,
<NumberFor<Block> as FromStr>::Err: Debug,
ExecDispatch: NativeExecutionDispatch + 'static,
HostFns: HostFunctions,
{
let executor = build_executor(&shared, &config);
let execution = shared.execution;
let executor = build_executor(&shared);
// we first build the externalities with the remote code.
let ext = command.state.into_ext::<Block, HostFns>(&shared, &executor, None).await?;
let header_at = command.header_at::<Block>()?;
let header_ws_uri = command.header_ws_uri::<Block>();
let rpc = ws_client(&header_ws_uri).await?;
let header = ChainApi::<(), Block::Hash, Block::Header, ()>::header(&rpc, Some(header_at))
let next_hash = next_hash_of::<Block>(&rpc, ext.block_hash).await?;
log::info!(target: LOG_TARGET, "fetching next header: {:?} ", next_hash);
let header = ChainApi::<(), Block::Hash, Block::Header, ()>::header(&rpc, Some(next_hash))
.await
.unwrap()
.unwrap();
log::info!(
target: LOG_TARGET,
"fetched header from {:?}, block number: {:?}",
header_ws_uri,
header.number()
);
.map_err(rpc_err_handler)
.map(|maybe_header| maybe_header.ok_or("Header does not exist"))??;
let payload = header.encode();
let ext = {
let builder = command.state.builder::<Block>()?.state_version(shared.state_version);
let builder = if command.overwrite_wasm_code {
log::info!(
target: LOG_TARGET,
"replacing the in-storage :code: with the local code from {}'s chain_spec (your local repo)",
config.chain_spec.name(),
);
let (code_key, code) = extract_code(&config.chain_spec)?;
builder.inject_hashed_key_value(&[(code_key, code)])
} else {
builder.inject_hashed_key(well_known_keys::CODE)
};
builder.build().await?
};
let (expected_spec_name, expected_spec_version, _) =
local_spec::<Block, ExecDispatch>(&ext, &executor);
ensure_matching_spec::<Block>(
header_ws_uri,
expected_spec_name,
expected_spec_version,
shared.no_spec_check_panic,
)
.await;
let _ = state_machine_call::<Block, ExecDispatch>(
let _ = state_machine_call::<Block, HostFns>(
&ext,
&executor,
execution,
"OffchainWorkerApi_offchain_worker",
header.encode().as_ref(),
&payload,
full_extensions(),
)?;
log::info!(target: LOG_TARGET, "OffchainWorkerApi_offchain_worker executed without errors.");
Ok(())
}
@@ -15,31 +15,31 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::{fmt::Debug, str::FromStr};
use parity_scale_codec::Decode;
use sc_executor::NativeExecutionDispatch;
use sc_service::Configuration;
use crate::{build_executor, state_machine_call_with_proof, SharedParams, State, LOG_TARGET};
use parity_scale_codec::{Decode, Encode};
use sc_executor::sp_wasm_interface::HostFunctions;
use sp_runtime::traits::{Block as BlockT, NumberFor};
use sp_weights::Weight;
use std::{fmt::Debug, str::FromStr};
use crate::{
build_executor, ensure_matching_spec, extract_code, local_spec, state_machine_call_with_proof,
SharedParams, State, LOG_TARGET,
};
/// Configurations of the [`Command::OnRuntimeUpgrade`].
/// Configurations of the [`crate::Command::OnRuntimeUpgrade`].
#[derive(Debug, Clone, clap::Parser)]
pub struct OnRuntimeUpgradeCmd {
/// The state type to use.
#[command(subcommand)]
pub state: State,
/// Execute `try_state`, `pre_upgrade` and `post_upgrade` checks as well.
///
/// This will perform more checks, but it will also makes the reported PoV/Weight be
/// inaccurate.
#[clap(long)]
pub checks: bool,
}
pub(crate) async fn on_runtime_upgrade<Block, ExecDispatch>(
pub(crate) async fn on_runtime_upgrade<Block, HostFns>(
shared: SharedParams,
command: OnRuntimeUpgradeCmd,
config: Configuration,
) -> sc_cli::Result<()>
where
Block: BlockT + serde::de::DeserializeOwned,
@@ -48,40 +48,22 @@ where
Block::Header: serde::de::DeserializeOwned,
NumberFor<Block>: FromStr,
<NumberFor<Block> as FromStr>::Err: Debug,
ExecDispatch: NativeExecutionDispatch + 'static,
HostFns: HostFunctions,
{
let executor = build_executor(&shared, &config);
let execution = shared.execution;
let executor = build_executor(&shared);
let ext = command.state.into_ext::<Block, HostFns>(&shared, &executor, None).await?;
let ext = {
let builder = command.state.builder::<Block>()?.state_version(shared.state_version);
let (code_key, code) = extract_code(&config.chain_spec)?;
builder.inject_hashed_key_value(&[(code_key, code)]).build().await?
};
if let Some(uri) = command.state.live_uri() {
let (expected_spec_name, expected_spec_version, _) =
local_spec::<Block, ExecDispatch>(&ext, &executor);
ensure_matching_spec::<Block>(
uri,
expected_spec_name,
expected_spec_version,
shared.no_spec_check_panic,
)
.await;
}
let (_, encoded_result) = state_machine_call_with_proof::<Block, ExecDispatch>(
let (_, encoded_result) = state_machine_call_with_proof::<Block, HostFns>(
&ext,
&executor,
execution,
"TryRuntime_on_runtime_upgrade",
&[],
command.checks.encode().as_ref(),
Default::default(), // we don't really need any extensions here.
)?;
let (weight, total_weight) = <(Weight, Weight) as Decode>::decode(&mut &*encoded_result)
.map_err(|e| format!("failed to decode weight: {:?}", e))?;
log::info!(
target: LOG_TARGET,
"TryRuntime_on_runtime_upgrade executed without errors. Consumed weight = ({} ps, {} byte), total weight = ({} ps, {} byte) ({:.2} %, {:.2} %).",
File diff suppressed because it is too large Load Diff