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

Commit

Permalink
Leave some header related info for inspection (#7727)
Browse files Browse the repository at this point in the history
* Leave some system data for inspection

There is not much benefit in being active when removing this data. It's
actively harmful when one tries to read the block number in runtime
APIs in the context of a block.

* Update the expected root hash

This is excepted since now we persist new members.

* Revert extrinsics_root to `take`

It's going away in one of the following PRs anyway

* Update the state root once again

* Update the comment on the storage items that are left in the storage

Excluding ExtrinsicsRoot since it's going away
  • Loading branch information
pepyakin authored Dec 15, 2020
1 parent 6584375 commit 566ad03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ mod tests {
header: Header {
parent_hash: [69u8; 32].into(),
number: 1,
state_root: hex!("6a3ad91caba5b8ac15c325a36d7568adf6a7e49321865de7527b851d870343d4").into(),
state_root: hex!("ba1a82a264b8007e0c04c9ea35e541593daad08b6e2bf7c0a6780a67d1c55018").into(),
extrinsics_root: hex!("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314").into(),
digest: Digest { logs: vec![], },
},
Expand Down
28 changes: 16 additions & 12 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,15 +1013,27 @@ impl<T: Config> Module<T> {
}
}

/// Remove temporary "environment" entries in storage.
/// Remove temporary "environment" entries in storage, compute the storage root and return the
/// resulting header for this block.
pub fn finalize() -> T::Header {
ExecutionPhase::kill();
ExtrinsicCount::kill();
AllExtrinsicsLen::kill();

let number = <Number<T>>::take();
let parent_hash = <ParentHash<T>>::take();
let mut digest = <Digest<T>>::take();
// The following fields
//
// - <Events<T>>
// - <EventCount<T>>
// - <EventTopics<T>>
// - <Number<T>>
// - <ParentHash<T>>
// - <Digest<T>>
//
// stay to be inspected by the client and will be cleared by `Self::initialize`.
let number = <Number<T>>::get();
let parent_hash = <ParentHash<T>>::get();
let mut digest = <Digest<T>>::get();

let extrinsics_root = <ExtrinsicsRoot<T>>::take();

// move block hash pruning window by one block
Expand Down Expand Up @@ -1049,14 +1061,6 @@ impl<T: Config> Module<T> {
digest.push(item);
}

// The following fields
//
// - <Events<T>>
// - <EventCount<T>>
// - <EventTopics<T>>
//
// stay to be inspected by the client and will be cleared by `Self::initialize`.

<T::Header as traits::Header>::new(number, extrinsics_root, storage_root, parent_hash, digest)
}

Expand Down

0 comments on commit 566ad03

Please sign in to comment.