@@ -623,6 +623,9 @@ where
623
623
struct SubstrateStackSubstate < ' config > {
624
624
metadata : StackSubstateMetadata < ' config > ,
625
625
deletes : BTreeSet < H160 > ,
626
+ creates : BTreeSet < H160 > ,
627
+ /// Account transient storage (discarded after every transaction. (see EIP-1153))
628
+ transient_storage : BTreeMap < ( H160 , H256 ) , H256 > ,
626
629
logs : Vec < Log > ,
627
630
parent : Option < Box < SubstrateStackSubstate < ' config > > > ,
628
631
}
@@ -641,6 +644,8 @@ impl<'config> SubstrateStackSubstate<'config> {
641
644
metadata : self . metadata . spit_child ( gas_limit, is_static) ,
642
645
parent : None ,
643
646
deletes : BTreeSet :: new ( ) ,
647
+ creates : BTreeSet :: new ( ) ,
648
+ transient_storage : BTreeMap :: new ( ) ,
644
649
logs : Vec :: new ( ) ,
645
650
} ;
646
651
mem:: swap ( & mut entering, self ) ;
@@ -657,6 +662,7 @@ impl<'config> SubstrateStackSubstate<'config> {
657
662
self . metadata . swallow_commit ( exited. metadata ) ?;
658
663
self . logs . append ( & mut exited. logs ) ;
659
664
self . deletes . append ( & mut exited. deletes ) ;
665
+ self . transient_storage . append ( & mut exited. transient_storage ) ;
660
666
661
667
sp_io:: storage:: commit_transaction ( ) ;
662
668
Ok ( ( ) )
@@ -715,6 +721,36 @@ impl<'config> SubstrateStackSubstate<'config> {
715
721
. unwrap_or ( true )
716
722
}
717
723
}
724
+
725
+ pub fn known_transient_storage ( & self , address : H160 , key : H256 ) -> Option < H256 > {
726
+ if let Some ( value) = self . transient_storage . get ( & ( address, key) ) {
727
+ Some ( * value)
728
+ } else if let Some ( parent) = self . parent . as_ref ( ) {
729
+ parent. known_transient_storage ( address, key)
730
+ } else {
731
+ None
732
+ }
733
+ }
734
+
735
+ pub fn created ( & self , address : H160 ) -> bool {
736
+ if self . creates . contains ( & address) {
737
+ return true ;
738
+ }
739
+
740
+ if let Some ( parent) = self . parent . as_ref ( ) {
741
+ return parent. created ( address) ;
742
+ }
743
+
744
+ false
745
+ }
746
+
747
+ pub fn set_transient_storage ( & mut self , address : H160 , key : H256 , value : H256 ) {
748
+ self . transient_storage . insert ( ( address, key) , value) ;
749
+ }
750
+
751
+ pub fn set_created ( & mut self , address : H160 ) {
752
+ self . creates . insert ( address) ;
753
+ }
718
754
}
719
755
720
756
#[ derive( Default , Clone , Eq , PartialEq ) ]
@@ -748,6 +784,8 @@ impl<'vicinity, 'config, T: Config> SubstrateStackState<'vicinity, 'config, T> {
748
784
substate : SubstrateStackSubstate {
749
785
metadata,
750
786
deletes : BTreeSet :: new ( ) ,
787
+ creates : BTreeSet :: new ( ) ,
788
+ transient_storage : BTreeMap :: new ( ) ,
751
789
logs : Vec :: new ( ) ,
752
790
parent : None ,
753
791
} ,
@@ -856,10 +894,15 @@ where
856
894
)
857
895
}
858
896
859
- /// FIXME: DO NOT call it for now! The dependent [evm::backend::Backend] trait has new methods added in this version,
860
- /// see this [commit](https://github.com/rust-ethereum/evm/commit/cfb378dac0640a6ac78687dd734241760f6ce125).
861
- fn transient_storage ( & self , _address : H160 , _index : H256 ) -> H256 {
862
- todo ! ( )
897
+ fn transient_storage ( & self , address : H160 , index : H256 ) -> H256 {
898
+ self . substate
899
+ . known_transient_storage ( address, index)
900
+ . unwrap_or_else ( || {
901
+ self . original_storage
902
+ . get ( & ( address, index) )
903
+ . cloned ( )
904
+ . unwrap_or_else ( || self . storage ( address, index) )
905
+ } )
863
906
}
864
907
}
865
908
@@ -1251,22 +1294,16 @@ where
1251
1294
}
1252
1295
}
1253
1296
1254
- /// FIXME: DO NOT call it for now! The dependent [evm::executor::stack::executor::StackState] trait has new methods added in this version,
1255
- /// see this [commit](https://github.com/rust-ethereum/evm/commit/cfb378dac0640a6ac78687dd734241760f6ce125).
1256
- fn set_transient_storage ( & mut self , _address : H160 , _key : H256 , _value : H256 ) {
1257
- todo ! ( )
1297
+ fn set_transient_storage ( & mut self , address : H160 , key : H256 , value : H256 ) {
1298
+ self . substate . set_transient_storage ( address, key, value)
1258
1299
}
1259
1300
1260
- /// FIXME: DO NOT call it for now! The dependent [evm::executor::stack::executor::StackState] trait has new methods added in this version,
1261
- /// see this [commit](https://github.com/rust-ethereum/evm/commit/cfb378dac0640a6ac78687dd734241760f6ce125).
1262
- fn created ( & self , _address : H160 ) -> bool {
1263
- todo ! ( )
1301
+ fn created ( & self , address : H160 ) -> bool {
1302
+ self . substate . created ( address)
1264
1303
}
1265
1304
1266
- /// FIXME: DO NOT call it for now! The dependent [evm::executor::stack::executor::StackState] trait has new methods added in this version,
1267
- /// see this [commit](https://github.com/rust-ethereum/evm/commit/cfb378dac0640a6ac78687dd734241760f6ce125).
1268
- fn set_created ( & mut self , _address : H160 ) {
1269
- todo ! ( )
1305
+ fn set_created ( & mut self , address : H160 ) {
1306
+ self . substate . set_created ( address)
1270
1307
}
1271
1308
}
1272
1309
0 commit comments