@@ -32,8 +32,12 @@ use crate::{
32
32
Justifications ,
33
33
} ;
34
34
use alloc:: vec:: Vec ;
35
+ use codec:: { DecodeWithMemLimit , Error , Input } ;
35
36
use sp_core:: RuntimeDebug ;
36
37
38
+ /// Maximum heap size for a block (in bytes).
39
+ const MAX_BLOCK_HEAP_SIZE : usize = 50 * 1024 * 1024 ; // 50 MiB
40
+
37
41
/// Something to identify a block.
38
42
#[ derive( PartialEq , Eq , Clone , Encode , Decode , RuntimeDebug ) ]
39
43
pub enum BlockId < Block : BlockT > {
@@ -79,18 +83,34 @@ impl<Block: BlockT> fmt::Display for BlockId<Block> {
79
83
80
84
/// Abstraction over a substrate block.
81
85
#[ derive(
82
- PartialEq , Eq , Clone , Encode , Decode , DecodeWithMemTracking , RuntimeDebug , scale_info:: TypeInfo ,
86
+ PartialEq , Eq , Clone , Encode , DecodeWithMemTracking , RuntimeDebug , scale_info:: TypeInfo ,
83
87
) ]
84
88
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
85
89
#[ cfg_attr( feature = "serde" , serde( rename_all = "camelCase" ) ) ]
86
90
#[ cfg_attr( feature = "serde" , serde( deny_unknown_fields) ) ]
91
+ #[ codec( decode_with_mem_tracking_bound(
92
+ Header : DecodeWithMemTracking ,
93
+ Extrinsic : DecodeWithMemTracking )
94
+ ) ]
87
95
pub struct Block < Header , Extrinsic > {
88
96
/// The block header.
89
97
pub header : Header ,
90
98
/// The accompanying extrinsics.
91
99
pub extrinsics : Vec < Extrinsic > ,
92
100
}
93
101
102
+ impl < Header , Extrinsic > Decode for Block < Header , Extrinsic >
103
+ where
104
+ Header : DecodeWithMemTracking ,
105
+ Extrinsic : DecodeWithMemTracking ,
106
+ {
107
+ fn decode < I : Input > ( input : & mut I ) -> Result < Self , Error > {
108
+ let ( header, extrinsics) =
109
+ DecodeWithMemLimit :: decode_with_mem_limit ( input, MAX_BLOCK_HEAP_SIZE ) ?;
110
+ Ok ( Self { header, extrinsics } )
111
+ }
112
+ }
113
+
94
114
impl < Header , Extrinsic > traits:: HeaderProvider for Block < Header , Extrinsic >
95
115
where
96
116
Header : HeaderT ,
0 commit comments