Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
3f1de002
Commit
3f1de002
authored
5 years ago
by
Bastian Köcher
Browse files
Options
Downloads
Patches
Plain Diff
Fix review comments
parent
bc512d47
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cumulus/runtime/src/validate_block/implementation.rs
+12
-12
12 additions, 12 deletions
cumulus/runtime/src/validate_block/implementation.rs
with
12 additions
and
12 deletions
cumulus/runtime/src/validate_block/implementation.rs
+
12
−
12
View file @
3f1de002
...
...
@@ -28,7 +28,7 @@ use rstd::{slice, ptr, cmp, vec::Vec, boxed::Box, mem};
use
hash_db
::
HashDB
;
static
mut
STORAGE
:
Option
<
Box
<
Storage
T
>>
=
None
;
static
mut
STORAGE
:
Option
<
Box
<
Storage
>>
=
None
;
/// The message to use as expect message while accessing the `STORAGE`.
const
STORAGE_SET_EXPECT
:
&
str
=
"`STORAGE` needs to be set before calling this function."
;
...
...
@@ -36,11 +36,9 @@ const STORAGE_ROOT_LEN: usize = 32;
/// Extract the hashing algorithm type from the given block type.
type
HashingOf
<
B
>
=
<<
B
as
BlockT
>
::
Header
as
HeaderT
>
::
Hashing
;
/// Extract the hash type from the given block type.
type
HashOf
<
B
>
=
<
B
as
BlockT
>
::
Hash
;
/// Abstract the storage into a trait without `Block` generic.
trait
Storage
T
{
trait
Storage
{
/// Retrieve the value for the given key.
fn
get
(
&
self
,
key
:
&
[
u8
])
->
Option
<
Vec
<
u8
>>
;
...
...
@@ -66,7 +64,7 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(
.expect
(
"Could not decode parachain block."
);
// TODO: Add `PolkadotInherent`.
let
block
=
B
::
new
(
block_data
.header
,
block_data
.extrinsics
);
let
storage
=
Storage
::
<
B
>
::
new
(
let
storage
=
Witness
Storage
::
<
B
>
::
new
(
block_data
.witness_data
,
block_data
.witness_data_storage_root
,
)
.expect
(
"Witness data and storage root always match; qed"
);
...
...
@@ -87,20 +85,21 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(
E
::
execute_block
(
block
);
}
/// The storage implementation used when validating a block.
struct
Storage
<
B
:
BlockT
>
{
/// The storage implementation used when validating a block that is using the
/// witness data as source.
struct
WitnessStorage
<
B
:
BlockT
>
{
witness_data
:
MemoryDB
<<
HashingOf
<
B
>
as
HashT
>
::
Hasher
>
,
overlay
:
hashbrown
::
HashMap
<
Vec
<
u8
>
,
Option
<
Vec
<
u8
>>>
,
storage_root
:
Hash
Of
<
B
>
,
storage_root
:
B
::
Hash
,
}
impl
<
B
:
BlockT
>
Storage
<
B
>
{
impl
<
B
:
BlockT
>
Witness
Storage
<
B
>
{
/// Initialize from the given witness data and storage root.
///
/// Returns an error if given storage root was not found in the witness data.
fn
new
(
data
:
WitnessData
,
storage_root
:
Hash
Of
<
B
>
storage_root
:
B
::
Hash
,
)
->
Result
<
Self
,
&
'static
str
>
{
let
mut
db
=
MemoryDB
::
default
();
data
.into_iter
()
.for_each
(|
i
|
{
db
.insert
(
&
[],
&
i
);
});
...
...
@@ -117,12 +116,13 @@ impl<B: BlockT> Storage<B> {
}
}
impl
<
B
:
BlockT
>
Storage
T
for
Storage
<
B
>
{
impl
<
B
:
BlockT
>
Storage
for
Witness
Storage
<
B
>
{
fn
get
(
&
self
,
key
:
&
[
u8
])
->
Option
<
Vec
<
u8
>>
{
self
.overlay
.get
(
key
)
.cloned
()
.or_else
(||
{
read_trie_value
(
&
self
.witness_data
,
&
self
.storage_root
,
key
&
self
.storage_root
,
key
,
)
.ok
()
})
.unwrap_or
(
None
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment