@@ -11,7 +11,10 @@ use crate::{
11
11
im_helpers:: { ordmap_for_each_mut, OrdMap } ,
12
12
} ;
13
13
14
- type ContractMap = OrdMap < AccountId , Contract > ;
14
+ // size_of::<Contract>() == 1064, if we don't box it, it would exceed the stack capacity
15
+ // when inserting data, even if we have an 8MB stack size. Not sure why the OrdMap::insert
16
+ // increases the size so significantly.
17
+ type ContractMap = OrdMap < AccountId , Box < Contract > > ;
15
18
16
19
#[ derive( Default , Serialize , Deserialize , Clone , :: scale_info:: TypeInfo ) ]
17
20
pub struct ContractsKeeper {
@@ -24,19 +27,22 @@ pub struct ContractsKeeper {
24
27
25
28
impl ContractsKeeper {
26
29
pub fn insert ( & mut self , contract : Contract ) {
27
- self . contracts . insert ( contract. address ( ) . clone ( ) , contract) ;
30
+ self . contracts
31
+ . insert ( contract. address ( ) . clone ( ) , Box :: new ( contract) ) ;
28
32
}
29
33
30
34
pub fn keys ( & self ) -> impl Iterator < Item = & AccountId > {
31
35
self . contracts . keys ( )
32
36
}
33
37
34
38
pub fn get_mut ( & mut self , id : & AccountId ) -> Option < & mut Contract > {
35
- self . contracts . get_mut ( id)
39
+ let boxed = self . contracts . get_mut ( id) ?;
40
+ Some ( boxed)
36
41
}
37
42
38
43
pub fn get ( & self , id : & AccountId ) -> Option < & Contract > {
39
- self . contracts . get ( id)
44
+ let boxed = self . contracts . get ( id) ?;
45
+ Some ( boxed)
40
46
}
41
47
42
48
#[ allow( clippy:: len_without_is_empty) ]
@@ -56,11 +62,11 @@ impl ContractsKeeper {
56
62
#[ allow( clippy:: iter_kv_map) ]
57
63
std:: mem:: take ( & mut self . contracts )
58
64
. into_iter ( )
59
- . map ( |( _, v) | v)
65
+ . map ( |( _, v) | * v)
60
66
}
61
67
62
68
pub fn iter ( & self ) -> impl Iterator < Item = ( & AccountId , & Contract ) > {
63
- self . contracts . iter ( )
69
+ self . contracts . iter ( ) . map ( | ( k , v ) | ( k , & * * v ) )
64
70
}
65
71
66
72
pub fn apply_local_cache_quotas ( & self ) {
@@ -73,7 +79,7 @@ pub(super) trait ToWeight {
73
79
fn to_weight ( & self ) -> u32 ;
74
80
}
75
81
76
- impl ToWeight for Contract {
82
+ impl ToWeight for Box < Contract > {
77
83
fn to_weight ( & self ) -> u32 {
78
84
self . weight
79
85
}
0 commit comments