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

Commit ba43ca1

Browse files
circlespainterbkchr
authored andcommitted
Fix #1536: do not require to construct a block for encoding it (#3813)
* Fix #1536: do not require to construct a block for encoding it * Bump `impl_version` * Improve `Block::encode_from` signature and rustdoc (from review by @bkchr)
1 parent a1d8124 commit ba43ca1

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

core/client/src/client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,10 +1059,10 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
10591059
}
10601060
};
10611061

1062-
let encoded_block = <Block as BlockT>::new(
1063-
import_headers.pre().clone(),
1064-
body.unwrap_or_default(),
1065-
).encode();
1062+
let encoded_block = <Block as BlockT>::encode_from(
1063+
import_headers.pre(),
1064+
&body.unwrap_or_default()
1065+
);
10661066

10671067
let (_, storage_update, changes_update) = self.executor
10681068
.call_at_state::<_, _, NeverNativeValue, fn() -> _>(

core/sr-primitives/src/generic/block.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ where
9393
fn new(header: Self::Header, extrinsics: Vec<Self::Extrinsic>) -> Self {
9494
Block { header, extrinsics }
9595
}
96+
fn encode_from(header: &Self::Header, extrinsics: &[Self::Extrinsic]) -> Vec<u8> {
97+
(header, extrinsics).encode()
98+
}
9699
}
97100

98101
/// Abstraction over a substrate block and justification.

core/sr-primitives/src/testing.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ impl<Xt: 'static + Codec + Sized + Send + Sync + Serialize + Clone + Eq + Debug
259259
fn new(header: Self::Header, extrinsics: Vec<Self::Extrinsic>) -> Self {
260260
Block { header, extrinsics }
261261
}
262+
fn encode_from(header: &Self::Header, extrinsics: &[Self::Extrinsic]) -> Vec<u8> {
263+
(header, extrinsics).encode()
264+
}
262265
}
263266

264267
impl<'a, Xt> Deserialize<'a> for Block<Xt> where Block<Xt>: Decode {

core/sr-primitives/src/traits.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,8 @@ pub trait Block: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebugButNotDes
687687
fn hash(&self) -> Self::Hash {
688688
<<Self::Header as Header>::Hashing as Hash>::hash_of(self.header())
689689
}
690+
/// Create an encoded block from the given `header` and `extrinsics` without requiring to create an instance.
691+
fn encode_from(header: &Self::Header, extrinsics: &[Self::Extrinsic]) -> Vec<u8>;
690692
}
691693

692694
/// Something that acts like an `Extrinsic`.

node/runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
8585
// implementation changes and behavior does not, then leave spec_version as
8686
// is and increment impl_version.
8787
spec_version: 175,
88-
impl_version: 175,
88+
impl_version: 176,
8989
apis: RUNTIME_API_VERSIONS,
9090
};
9191

0 commit comments

Comments
 (0)