@@ -34,6 +34,7 @@ use fil_actors_runtime::{
34
34
use fil_actors_runtime:: { MessageAccumulator , DATACAP_TOKEN_ACTOR_ADDR } ;
35
35
use fil_builtin_actors_state:: check:: check_state_invariants;
36
36
use fil_builtin_actors_state:: check:: Tree ;
37
+ use fvm_ipld_blockstore:: Blockstore ;
37
38
use fvm_ipld_blockstore:: MemoryBlockstore ;
38
39
use fvm_ipld_encoding:: ipld_block:: IpldBlock ;
39
40
use fvm_ipld_encoding:: tuple:: * ;
@@ -74,8 +75,11 @@ use std::ops::Add;
74
75
75
76
pub mod util;
76
77
77
- pub struct TestVM < ' bs > {
78
- pub store : & ' bs MemoryBlockstore ,
78
+ pub struct TestVM < ' bs , BS >
79
+ where
80
+ BS : Blockstore ,
81
+ {
82
+ pub store : & ' bs BS ,
79
83
pub state_root : RefCell < Cid > ,
80
84
total_fil : TokenAmount ,
81
85
actors_dirty : RefCell < bool > ,
@@ -121,8 +125,11 @@ pub const TEST_FAUCET_ADDR: Address = Address::new_id(FIRST_NON_SINGLETON_ADDR +
121
125
pub const FIRST_TEST_USER_ADDR : ActorID = FIRST_NON_SINGLETON_ADDR + 3 ;
122
126
123
127
// accounts for verifreg root signer and msig
124
- impl < ' bs > TestVM < ' bs > {
125
- pub fn new ( store : & ' bs MemoryBlockstore ) -> TestVM < ' bs > {
128
+ impl < ' bs , BS > TestVM < ' bs , BS >
129
+ where
130
+ BS : Blockstore ,
131
+ {
132
+ pub fn new ( store : & ' bs MemoryBlockstore ) -> TestVM < ' bs , MemoryBlockstore > {
126
133
let mut actors = Hamt :: < & ' bs MemoryBlockstore , Actor , BytesKey , Sha256 > :: new ( store) ;
127
134
TestVM {
128
135
store,
@@ -140,11 +147,12 @@ impl<'bs> TestVM<'bs> {
140
147
Self { total_fil, ..self }
141
148
}
142
149
143
- pub fn new_with_singletons ( store : & ' bs MemoryBlockstore ) -> TestVM < ' bs > {
150
+ pub fn new_with_singletons ( store : & ' bs MemoryBlockstore ) -> TestVM < ' bs , MemoryBlockstore > {
144
151
let reward_total = TokenAmount :: from_whole ( 1_100_000_000i64 ) ;
145
152
let faucet_total = TokenAmount :: from_whole ( 1_000_000_000i64 ) ;
146
153
147
- let v = TestVM :: new ( store) . with_total_fil ( & reward_total + & faucet_total) ;
154
+ let v = TestVM :: < ' _ , MemoryBlockstore > :: new ( store)
155
+ . with_total_fil ( & reward_total + & faucet_total) ;
148
156
149
157
// system
150
158
let sys_st = SystemState :: new ( store) . unwrap ( ) ;
@@ -283,7 +291,7 @@ impl<'bs> TestVM<'bs> {
283
291
v
284
292
}
285
293
286
- pub fn with_epoch ( self , epoch : ChainEpoch ) -> TestVM < ' bs > {
294
+ pub fn with_epoch ( self , epoch : ChainEpoch ) -> TestVM < ' bs , BS > {
287
295
self . checkpoint ( ) ;
288
296
TestVM {
289
297
store : self . store ,
@@ -352,11 +360,9 @@ impl<'bs> TestVM<'bs> {
352
360
return Some ( act. clone ( ) ) ;
353
361
}
354
362
// go to persisted map
355
- let actors = Hamt :: < & ' bs MemoryBlockstore , Actor , BytesKey , Sha256 > :: load (
356
- & self . state_root . borrow ( ) ,
357
- self . store ,
358
- )
359
- . unwrap ( ) ;
363
+ let actors =
364
+ Hamt :: < & ' bs BS , Actor , BytesKey , Sha256 > :: load ( & self . state_root . borrow ( ) , self . store )
365
+ . unwrap ( ) ;
360
366
let actor = actors. get ( & addr. to_bytes ( ) ) . unwrap ( ) . cloned ( ) ;
361
367
actor. iter ( ) . for_each ( |a| {
362
368
self . actors_cache . borrow_mut ( ) . insert ( addr, a. clone ( ) ) ;
@@ -372,11 +378,9 @@ impl<'bs> TestVM<'bs> {
372
378
373
379
pub fn checkpoint ( & self ) -> Cid {
374
380
// persist cache on top of latest checkpoint and clear
375
- let mut actors = Hamt :: < & ' bs MemoryBlockstore , Actor , BytesKey , Sha256 > :: load (
376
- & self . state_root . borrow ( ) ,
377
- self . store ,
378
- )
379
- . unwrap ( ) ;
381
+ let mut actors =
382
+ Hamt :: < & ' bs BS , Actor , BytesKey , Sha256 > :: load ( & self . state_root . borrow ( ) , self . store )
383
+ . unwrap ( ) ;
380
384
for ( addr, act) in self . actors_cache . borrow ( ) . iter ( ) {
381
385
actors. set ( addr. to_bytes ( ) . into ( ) , act. clone ( ) ) . unwrap ( ) ;
382
386
}
@@ -394,7 +398,7 @@ impl<'bs> TestVM<'bs> {
394
398
395
399
pub fn normalize_address ( & self , addr : & Address ) -> Option < Address > {
396
400
let st = self . get_state :: < InitState > ( INIT_ACTOR_ADDR ) . unwrap ( ) ;
397
- st. resolve_address :: < MemoryBlockstore > ( self . store , addr) . unwrap ( )
401
+ st. resolve_address :: < BS > ( self . store , addr) . unwrap ( )
398
402
}
399
403
400
404
pub fn get_state < T : DeserializeOwned > ( & self , addr : Address ) -> Option < T > {
@@ -497,11 +501,9 @@ impl<'bs> TestVM<'bs> {
497
501
/// Checks the state invariants and returns broken invariants.
498
502
pub fn check_state_invariants ( & self ) -> anyhow:: Result < MessageAccumulator > {
499
503
self . checkpoint ( ) ;
500
- let actors = Hamt :: < & ' bs MemoryBlockstore , Actor , BytesKey , Sha256 > :: load (
501
- & self . state_root . borrow ( ) ,
502
- self . store ,
503
- )
504
- . unwrap ( ) ;
504
+ let actors =
505
+ Hamt :: < & ' bs BS , Actor , BytesKey , Sha256 > :: load ( & self . state_root . borrow ( ) , self . store )
506
+ . unwrap ( ) ;
505
507
506
508
let mut manifest = BiBTreeMap :: new ( ) ;
507
509
actors
@@ -571,7 +573,10 @@ impl InternalMessage {
571
573
}
572
574
}
573
575
574
- impl MessageInfo for InvocationCtx < ' _ , ' _ > {
576
+ impl < BS > MessageInfo for InvocationCtx < ' _ , ' _ , BS >
577
+ where
578
+ BS : Blockstore ,
579
+ {
575
580
fn nonce ( & self ) -> u64 {
576
581
self . top . originator_call_seq
577
582
}
@@ -598,8 +603,11 @@ pub const TEST_VM_RAND_ARRAY: [u8; 32] = [
598
603
] ;
599
604
pub const TEST_VM_INVALID_POST : & str = "i_am_invalid_post" ;
600
605
601
- pub struct InvocationCtx < ' invocation , ' bs > {
602
- v : & ' invocation TestVM < ' bs > ,
606
+ pub struct InvocationCtx < ' invocation , ' bs , BS >
607
+ where
608
+ BS : Blockstore ,
609
+ {
610
+ v : & ' invocation TestVM < ' bs , BS > ,
603
611
top : TopCtx ,
604
612
msg : InternalMessage ,
605
613
allow_side_effects : RefCell < bool > ,
@@ -609,7 +617,10 @@ pub struct InvocationCtx<'invocation, 'bs> {
609
617
subinvocations : RefCell < Vec < InvocationTrace > > ,
610
618
}
611
619
612
- impl < ' invocation , ' bs > InvocationCtx < ' invocation , ' bs > {
620
+ impl < ' invocation , ' bs , BS > InvocationCtx < ' invocation , ' bs , BS >
621
+ where
622
+ BS : Blockstore ,
623
+ {
613
624
fn resolve_target ( & ' invocation self , target : & Address ) -> Result < ( Actor , Address ) , ActorError > {
614
625
if let Some ( a) = self . v . normalize_address ( target) {
615
626
if let Some ( act) = self . v . get_actor ( a) {
@@ -779,8 +790,11 @@ impl<'invocation, 'bs> InvocationCtx<'invocation, 'bs> {
779
790
}
780
791
}
781
792
782
- impl < ' invocation , ' bs > Runtime for InvocationCtx < ' invocation , ' bs > {
783
- type Blockstore = & ' bs MemoryBlockstore ;
793
+ impl < ' invocation , ' bs , BS > Runtime for InvocationCtx < ' invocation , ' bs , BS >
794
+ where
795
+ BS : Blockstore ,
796
+ {
797
+ type Blockstore = & ' bs BS ;
784
798
785
799
fn create_actor (
786
800
& self ,
@@ -822,7 +836,7 @@ impl<'invocation, 'bs> Runtime for InvocationCtx<'invocation, 'bs> {
822
836
Ok ( ( ) )
823
837
}
824
838
825
- fn store ( & self ) -> & & ' bs MemoryBlockstore {
839
+ fn store ( & self ) -> & & ' bs BS {
826
840
& self . v . store
827
841
}
828
842
@@ -1123,7 +1137,10 @@ impl<'invocation, 'bs> Runtime for InvocationCtx<'invocation, 'bs> {
1123
1137
}
1124
1138
}
1125
1139
1126
- impl Primitives for TestVM < ' _ > {
1140
+ impl < BS > Primitives for TestVM < ' _ , BS >
1141
+ where
1142
+ BS : Blockstore ,
1143
+ {
1127
1144
// A "valid" signature has its bytes equal to the plaintext.
1128
1145
// Anything else is considered invalid.
1129
1146
fn verify_signature (
@@ -1179,7 +1196,10 @@ impl Primitives for TestVM<'_> {
1179
1196
}
1180
1197
}
1181
1198
1182
- impl Primitives for InvocationCtx < ' _ , ' _ > {
1199
+ impl < BS > Primitives for InvocationCtx < ' _ , ' _ , BS >
1200
+ where
1201
+ BS : Blockstore ,
1202
+ {
1183
1203
fn verify_signature (
1184
1204
& self ,
1185
1205
signature : & Signature ,
@@ -1218,7 +1238,10 @@ impl Primitives for InvocationCtx<'_, '_> {
1218
1238
}
1219
1239
}
1220
1240
1221
- impl Verifier for InvocationCtx < ' _ , ' _ > {
1241
+ impl < BS > Verifier for InvocationCtx < ' _ , ' _ , BS >
1242
+ where
1243
+ BS : Blockstore ,
1244
+ {
1222
1245
fn verify_seal ( & self , _vi : & SealVerifyInfo ) -> Result < ( ) , anyhow:: Error > {
1223
1246
Ok ( ( ) )
1224
1247
}
@@ -1258,7 +1281,10 @@ impl Verifier for InvocationCtx<'_, '_> {
1258
1281
}
1259
1282
}
1260
1283
1261
- impl RuntimePolicy for InvocationCtx < ' _ , ' _ > {
1284
+ impl < BS > RuntimePolicy for InvocationCtx < ' _ , ' _ , BS >
1285
+ where
1286
+ BS : Blockstore ,
1287
+ {
1262
1288
fn policy ( & self ) -> & Policy {
1263
1289
self . policy
1264
1290
}
0 commit comments