1

Inside final_checks(header: &System::Header) method

fn final_checks() {
    let new_header = <frame_system::Pallet::<System>>::finalize();
    ...
    let storage_root = new_header.state_root();
    assert!(header.state_root() == storage_root, "Storage root must match that..);
    ... 
}

I am not sure why header.state_root() and storage_root should be equal. As far as I know, final_checks() are called right after all extrinsincs are executed, which could change the state of the storage and leads to change of state_root. What am I missing?

1 Answer 1

1

The new header should have the new storage root.

So when you are done executing the whole block, you can check that your current state root, after all extrinsics and state changes, matches what is expected by the block header. That is what is being checked here if you look carefully, and makes sense to me.

// check storage root.
let storage_root = new_header.state_root();
header.state_root().check_equal(storage_root);
assert!(header.state_root() == storage_root, "Storage root must match that calculated.");
1
  • Yeah I know new header has the new storage root after all extrinsincs. What I am confused is not new header, just the block header. When block header is created, is state root calculated by predispatch? If so, then it makes sense to me.
    – coco_yoon
    Commented Nov 16, 2022 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.