Skip to content

Commit

Permalink
sync: Remove checking of the extrinsics root (paritytech#5686)
Browse files Browse the repository at this point in the history
With the introduction of `system_version` in paritytech#4257 the
extrinsic root may also use the `V1` layout. At this point in the sync code it would require some special
handling to find out the `system_version`. So, this pull request is removing it. The extrinsics root is checked
when executing the block later, so that at least no invalid block gets imported.
  • Loading branch information
bkchr authored and nazar-pc committed Sep 27, 2024
1 parent 08fa8f5 commit 39eec15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
15 changes: 15 additions & 0 deletions prdoc/pr_5686.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
title: "sync: Remove checking of the extrinsics root"

doc:
- audience: Node Dev
description: |
Remove checking the extrinsics root as part of the sync code.
With the introduction of `system_version` and the possibility to use the `V1`
layout for the trie when calculating the extrinsics root, it would require the
sync code to fetch the runtime version first before knowing which layout to use
when building the extrinsic root.
The extrinsics root is still checked when executing a block on chain.

crates:
- name: sc-network-sync
bump: patch
22 changes: 1 addition & 21 deletions substrate/client/network/sync/src/strategy/chain_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ use crate::{
LOG_TARGET,
};

use codec::Encode;
use log::{debug, error, info, trace, warn};
use prometheus_endpoint::{register, Gauge, PrometheusError, Registry, U64};
use sc_client_api::{BlockBackend, ProofProvider};
Expand All @@ -57,8 +56,7 @@ use sp_blockchain::{Error as ClientError, HeaderBackend, HeaderMetadata};
use sp_consensus::{BlockOrigin, BlockStatus};
use sp_runtime::{
traits::{
Block as BlockT, CheckedSub, Hash, HashingFor, Header as HeaderT, NumberFor, One,
SaturatedConversion, Zero,
Block as BlockT, CheckedSub, Header as HeaderT, NumberFor, One, SaturatedConversion, Zero,
},
EncodedJustification, Justifications,
};
Expand Down Expand Up @@ -2295,24 +2293,6 @@ pub fn validate_blocks<Block: BlockT>(
return Err(BadPeer(*peer_id, rep::BAD_BLOCK));
}
}
if let (Some(header), Some(body)) = (&b.header, &b.body) {
let expected = *header.extrinsics_root();
let got = HashingFor::<Block>::ordered_trie_root(
body.iter().map(Encode::encode).collect(),
sp_runtime::StateVersion::V0,
);
if expected != got {
debug!(
target: LOG_TARGET,
"Bad extrinsic root for a block {} received from {}. Expected {:?}, got {:?}",
b.hash,
peer_id,
expected,
got,
);
return Err(BadPeer(*peer_id, rep::BAD_BLOCK));
}
}
}

Ok(blocks.first().and_then(|b| b.header.as_ref()).map(|h| *h.number()))
Expand Down

0 comments on commit 39eec15

Please sign in to comment.