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

chainHead: Add support for storage closest merkle descendant #14818

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a97fd42
chainHead/api: Add `chain_head_unstable_continue` method
lexnv Aug 2, 2023
fe3404c
chainHead/subscriptions: Register operations for pagination
lexnv Aug 9, 2023
72b26c3
chainHead/subscriptions: Merge limits with registered operation
lexnv Aug 9, 2023
e28d982
chainHead/subscriptions: Expose the operation state
lexnv Aug 10, 2023
1d717df
chain_head/storage: Generate WaitingForContinue event
lexnv Aug 10, 2023
3bbc9ba
chainHead: Use the continue operation
lexnv Aug 10, 2023
5afe9c0
chainHead/tests: Adjust testing to the new storage interface
lexnv Aug 10, 2023
c8e8ed5
chainHead/config: Make pagination limit configurable
lexnv Aug 10, 2023
60492c7
chainHead/tests: Adjust chainHeadConfig
lexnv Aug 10, 2023
6929ec5
chainHead/tests: Check pagination and continue method
lexnv Aug 10, 2023
2791c90
chainHead/api: Add `chainHead_unstable_stopOperation` method
lexnv Aug 11, 2023
8bda477
chainHead/subscription: Add shared atomic state for efficient alloc
lexnv Aug 11, 2023
382ce98
chainHead: Implement operation stop
lexnv Aug 11, 2023
3a5c12a
chainHead/tests: Check that storage ops can be cancelled
lexnv Aug 11, 2023
6d825a6
chainHead/storage: Change docs for query_storage_iter_pagination
lexnv Aug 11, 2023
cab6202
chainHead/subscriptions: Fix merge conflicts
lexnv Aug 16, 2023
141ca3f
chainHead: Replace `async-channel` with `tokio::sync`
lexnv Aug 23, 2023
7ccef40
chainHead/subscription: Add comment about the sender/recv continue
lexnv Aug 23, 2023
e48ba56
Cargo: Point trie-db related crates to git merkle branch
lexnv Aug 22, 2023
08c9082
client: Expose merkle value on storageProvider trait
lexnv Aug 22, 2023
40722f3
primitives/backend: Expose merkle value on Backend trait
lexnv Aug 22, 2023
4a358ee
primitives/trie: Low level functions for reading the merkle value
lexnv Aug 22, 2023
7477c3b
primitives/trie: Implement closest merkle value on TrieBackendEssence
lexnv Aug 22, 2023
b049205
primitives/trie: Implement closest merkle value on TrieBackend
lexnv Aug 22, 2023
4f94afc
client: Implement closest merkle value up until `StorageProvider`
lexnv Aug 22, 2023
253edae
chianHead/storage: Query the storage for closest merkle value
lexnv Aug 22, 2023
9ca904d
chainHead/tests: Check merkle values propagate to the chainHead_storage
lexnv Aug 23, 2023
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
77 changes: 55 additions & 22 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion bin/node/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sc-basic-authorship = { version = "0.10.0-dev", path = "../../../client/basic-au
sp-inherents = { version = "4.0.0-dev", path = "../../../primitives/inherents" }
sp-timestamp = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/timestamp" }
sp-tracing = { version = "10.0.0", path = "../../../primitives/tracing" }
hash-db = "0.16.0"
hash-db = { git = "https://github.com/paritytech/trie.git", branch = "lexnv/expose_merkle_value" }
tempfile = "3.1.0"
fs_extra = "1"
rand = { version = "0.8.5", features = ["small_rng"] }
Expand Down
15 changes: 15 additions & 0 deletions client/api/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,21 @@ pub trait StorageProvider<Block: BlockT, B: Backend<Block>> {
child_info: &ChildInfo,
key: &StorageKey,
) -> sp_blockchain::Result<Option<Block::Hash>>;

/// Given a block's `Hash` and a key, return the closest merkle value.
fn closest_merkle_value(
&self,
hash: Block::Hash,
key: &StorageKey,
) -> sp_blockchain::Result<Option<Block::Hash>>;

/// Given a block's `Hash`, a key and a child storage key, return the closest merkle value.
fn child_closest_merkle_value(
&self,
hash: Block::Hash,
child_info: &ChildInfo,
key: &StorageKey,
) -> sp_blockchain::Result<Option<Block::Hash>>;
}

/// Client backend.
Expand Down
2 changes: 1 addition & 1 deletion client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { package = "parity-scale-codec", version = "3.6.1", features = [
"derive",
] }
hash-db = "0.16.0"
hash-db = { git = "https://github.com/paritytech/trie.git", branch = "lexnv/expose_merkle_value" }
kvdb = "0.13.0"
kvdb-memorydb = "0.13.0"
kvdb-rocksdb = { version = "0.19.0", optional = true }
Expand Down
18 changes: 18 additions & 0 deletions client/db/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,24 @@ impl<B: BlockT> StateBackend<HashingFor<B>> for BenchmarkingState<B> {
.child_storage_hash(child_info, key)
}

fn closest_merkle_value(&self, key: &[u8]) -> Result<Option<B::Hash>, Self::Error> {
self.add_read_key(None, key);
self.state.borrow().as_ref().ok_or_else(state_err)?.closest_merkle_value(key)
}

fn child_closest_merkle_value(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<B::Hash>, Self::Error> {
self.add_read_key(None, key);
self.state
.borrow()
.as_ref()
.ok_or_else(state_err)?
.child_closest_merkle_value(child_info, key)
}

fn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error> {
self.add_read_key(None, key);
self.state.borrow().as_ref().ok_or_else(state_err)?.exists_storage(key)
Expand Down
12 changes: 12 additions & 0 deletions client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ impl<B: BlockT> StateBackend<HashingFor<B>> for RefTrackingState<B> {
self.state.child_storage_hash(child_info, key)
}

fn closest_merkle_value(&self, key: &[u8]) -> Result<Option<B::Hash>, Self::Error> {
self.state.closest_merkle_value(key)
}

fn child_closest_merkle_value(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<B::Hash>, Self::Error> {
self.state.child_closest_merkle_value(child_info, key)
}

fn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error> {
self.state.exists_storage(key)
}
Expand Down
12 changes: 12 additions & 0 deletions client/db/src/record_stats_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ impl<S: StateBackend<HashingFor<B>>, B: BlockT> StateBackend<HashingFor<B>>
self.state.child_storage_hash(child_info, key)
}

fn closest_merkle_value(&self, key: &[u8]) -> Result<Option<B::Hash>, Self::Error> {
self.state.closest_merkle_value(key)
}

fn child_closest_merkle_value(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Result<Option<B::Hash>, Self::Error> {
self.state.child_closest_merkle_value(child_info, key)
}

fn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error> {
self.state.exists_storage(key)
}
Expand Down
27 changes: 27 additions & 0 deletions client/rpc-spec-v2/src/chain_head/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,31 @@ pub trait ChainHeadApi<Hash> {
/// This method is unstable and subject to change in the future.
#[method(name = "chainHead_unstable_unpin", blocking)]
fn chain_head_unstable_unpin(&self, follow_subscription: String, hash: Hash) -> RpcResult<()>;

/// Resumes a storage fetch started with `chainHead_storage` after it has generated an
/// `operationWaitingForContinue` event.
///
/// # Unstable
///
/// This method is unstable and subject to change in the future.
#[method(name = "chainHead_unstable_continue", blocking)]
fn chain_head_unstable_continue(
&self,
follow_subscription: String,
operation_id: String,
) -> RpcResult<()>;

/// Stops an operation started with chainHead_unstable_body, chainHead_unstable_call, or
/// chainHead_unstable_storage. If the operation was still in progress, this interrupts it. If
/// the operation was already finished, this call has no effect.
///
/// # Unstable
///
/// This method is unstable and subject to change in the future.
#[method(name = "chainHead_unstable_stopOperation", blocking)]
fn chain_head_unstable_stop_operation(
&self,
follow_subscription: String,
operation_id: String,
) -> RpcResult<()>;
}
Loading