@@ -25,8 +25,8 @@ pub use clarity::vm::clarity::{ClarityConnection, Error};
25
25
use clarity:: vm:: contexts:: { AssetMap , OwnedEnvironment } ;
26
26
use clarity:: vm:: costs:: { CostTracker , ExecutionCost , LimitedCostTracker } ;
27
27
use clarity:: vm:: database:: {
28
- BurnStateDB , ClarityBackingStore , ClarityDatabase , HeadersDB , RollbackWrapper ,
29
- RollbackWrapperPersistedLog , STXBalance , NULL_BURN_STATE_DB , NULL_HEADER_DB ,
28
+ BurnStateDB , ClarityBackingStore , ClarityBackingStoreTransaction , ClarityDatabase , HeadersDB ,
29
+ RollbackWrapper , RollbackWrapperPersistedLog , STXBalance , NULL_BURN_STATE_DB , NULL_HEADER_DB ,
30
30
} ;
31
31
use clarity:: vm:: errors:: Error as InterpreterError ;
32
32
use clarity:: vm:: events:: { STXEventType , STXMintEventData } ;
@@ -53,7 +53,7 @@ use crate::chainstate::stacks::{
53
53
Error as ChainstateError , StacksMicroblockHeader , StacksTransaction , TransactionPayload ,
54
54
TransactionSmartContract , TransactionVersion ,
55
55
} ;
56
- use crate :: clarity_vm:: database:: marf:: { MarfedKV , ReadOnlyMarfStore , WritableMarfStore } ;
56
+ use crate :: clarity_vm:: database:: marf:: MarfedKV ;
57
57
use crate :: core:: { StacksEpoch , StacksEpochId , FIRST_STACKS_BLOCK_ID , GENESIS_EPOCH } ;
58
58
use crate :: util_lib:: boot:: { boot_code_acc, boot_code_addr, boot_code_id, boot_code_tx_auth} ;
59
59
use crate :: util_lib:: db:: Error as DatabaseError ;
@@ -101,15 +101,15 @@ pub struct ClarityInstance {
101
101
/// issuring event dispatches, before the Clarity database commits.
102
102
///
103
103
pub struct PreCommitClarityBlock < ' a > {
104
- datastore : WritableMarfStore < ' a > ,
104
+ datastore : Box < dyn ClarityBackingStoreTransaction + ' a > ,
105
105
commit_to : StacksBlockId ,
106
106
}
107
107
108
108
///
109
109
/// A high-level interface for Clarity VM interactions within a single block.
110
110
///
111
111
pub struct ClarityBlockConnection < ' a , ' b > {
112
- datastore : WritableMarfStore < ' a > ,
112
+ datastore : Box < dyn ClarityBackingStoreTransaction + ' a > ,
113
113
header_db : & ' b dyn HeadersDB ,
114
114
burn_state_db : & ' b dyn BurnStateDB ,
115
115
cost_track : Option < LimitedCostTracker > ,
@@ -160,7 +160,7 @@ impl<'a, 'b> ClarityTransactionConnection<'a, 'b> {
160
160
}
161
161
162
162
pub struct ClarityReadOnlyConnection < ' a > {
163
- datastore : ReadOnlyMarfStore < ' a > ,
163
+ datastore : Box < dyn ClarityBackingStore + ' a > ,
164
164
header_db : & ' a dyn HeadersDB ,
165
165
burn_state_db : & ' a dyn BurnStateDB ,
166
166
epoch : StacksEpochId ,
@@ -196,13 +196,13 @@ macro_rules! using {
196
196
impl ClarityBlockConnection < ' _ , ' _ > {
197
197
#[ cfg( test) ]
198
198
pub fn new_test_conn < ' a , ' b > (
199
- datastore : WritableMarfStore < ' a > ,
199
+ datastore : super :: database :: marf :: WritableMarfStore < ' a > ,
200
200
header_db : & ' b dyn HeadersDB ,
201
201
burn_state_db : & ' b dyn BurnStateDB ,
202
202
epoch : StacksEpochId ,
203
203
) -> ClarityBlockConnection < ' a , ' b > {
204
204
ClarityBlockConnection {
205
- datastore,
205
+ datastore : Box :: new ( datastore ) ,
206
206
header_db,
207
207
burn_state_db,
208
208
cost_track : Some ( LimitedCostTracker :: new_free ( ) ) ,
@@ -251,7 +251,7 @@ impl ClarityBlockConnection<'_, '_> {
251
251
& mut self ,
252
252
burn_state_db : & dyn BurnStateDB ,
253
253
) -> Result < StacksEpochId , Error > {
254
- let mut db = self . datastore . as_clarity_db ( self . header_db , burn_state_db) ;
254
+ let mut db = ClarityDatabase :: new ( self . datastore . as_mut ( ) , self . header_db , burn_state_db) ;
255
255
// NOTE: the begin/roll_back shouldn't be necessary with how this gets used in practice,
256
256
// but is put here defensively.
257
257
db. begin ( ) ;
@@ -328,7 +328,7 @@ impl ClarityInstance {
328
328
} ;
329
329
330
330
ClarityBlockConnection {
331
- datastore,
331
+ datastore : Box :: new ( datastore ) ,
332
332
header_db,
333
333
burn_state_db,
334
334
cost_track,
@@ -352,7 +352,7 @@ impl ClarityInstance {
352
352
let cost_track = Some ( LimitedCostTracker :: new_free ( ) ) ;
353
353
354
354
ClarityBlockConnection {
355
- datastore,
355
+ datastore : Box :: new ( datastore ) ,
356
356
header_db,
357
357
burn_state_db,
358
358
cost_track,
@@ -378,7 +378,7 @@ impl ClarityInstance {
378
378
let cost_track = Some ( LimitedCostTracker :: new_free ( ) ) ;
379
379
380
380
let mut conn = ClarityBlockConnection {
381
- datastore : writable,
381
+ datastore : Box :: new ( writable) ,
382
382
header_db,
383
383
burn_state_db,
384
384
cost_track,
@@ -477,7 +477,7 @@ impl ClarityInstance {
477
477
let cost_track = Some ( LimitedCostTracker :: new_free ( ) ) ;
478
478
479
479
let mut conn = ClarityBlockConnection {
480
- datastore : writable,
480
+ datastore : Box :: new ( writable) ,
481
481
header_db,
482
482
burn_state_db,
483
483
cost_track,
@@ -559,6 +559,7 @@ impl ClarityInstance {
559
559
560
560
pub fn drop_unconfirmed_state ( & mut self , block : & StacksBlockId ) -> Result < ( ) , Error > {
561
561
let datastore = self . datastore . begin_unconfirmed ( block) ;
562
+ let datastore: Box < dyn ClarityBackingStoreTransaction > = Box :: new ( datastore) ;
562
563
datastore. rollback_unconfirmed ( ) ?;
563
564
Ok ( ( ) )
564
565
}
@@ -588,7 +589,7 @@ impl ClarityInstance {
588
589
} ;
589
590
590
591
ClarityBlockConnection {
591
- datastore,
592
+ datastore : Box :: new ( datastore ) ,
592
593
header_db,
593
594
burn_state_db,
594
595
cost_track,
@@ -628,7 +629,7 @@ impl ClarityInstance {
628
629
} ?;
629
630
630
631
Ok ( ClarityReadOnlyConnection {
631
- datastore,
632
+ datastore : Box :: new ( datastore ) ,
632
633
header_db,
633
634
burn_state_db,
634
635
epoch,
@@ -677,7 +678,8 @@ impl ClarityConnection for ClarityBlockConnection<'_, '_> {
677
678
where
678
679
F : FnOnce ( ClarityDatabase ) -> ( R , ClarityDatabase ) ,
679
680
{
680
- let mut db = ClarityDatabase :: new ( & mut self . datastore , self . header_db , self . burn_state_db ) ;
681
+ let mut db =
682
+ ClarityDatabase :: new ( self . datastore . as_mut ( ) , self . header_db , self . burn_state_db ) ;
681
683
db. begin ( ) ;
682
684
let ( result, mut db) = to_do ( db) ;
683
685
db. roll_back ( )
@@ -689,7 +691,7 @@ impl ClarityConnection for ClarityBlockConnection<'_, '_> {
689
691
where
690
692
F : FnOnce ( & mut AnalysisDatabase ) -> R ,
691
693
{
692
- let mut db = AnalysisDatabase :: new ( & mut self . datastore ) ;
694
+ let mut db = AnalysisDatabase :: new ( self . datastore . as_mut ( ) ) ;
693
695
db. begin ( ) ;
694
696
let result = to_do ( & mut db) ;
695
697
db. roll_back ( )
@@ -708,9 +710,8 @@ impl ClarityConnection for ClarityReadOnlyConnection<'_> {
708
710
where
709
711
F : FnOnce ( ClarityDatabase ) -> ( R , ClarityDatabase ) ,
710
712
{
711
- let mut db = self
712
- . datastore
713
- . as_clarity_db ( self . header_db , self . burn_state_db ) ;
713
+ let mut db =
714
+ ClarityDatabase :: new ( self . datastore . as_mut ( ) , self . header_db , self . burn_state_db ) ;
714
715
db. begin ( ) ;
715
716
let ( result, mut db) = to_do ( db) ;
716
717
db. roll_back ( )
@@ -722,7 +723,7 @@ impl ClarityConnection for ClarityReadOnlyConnection<'_> {
722
723
where
723
724
F : FnOnce ( & mut AnalysisDatabase ) -> R ,
724
725
{
725
- let mut db = self . datastore . as_analysis_db ( ) ;
726
+ let mut db = AnalysisDatabase :: new ( self . datastore . as_mut ( ) ) ;
726
727
db. begin ( ) ;
727
728
let result = to_do ( & mut db) ;
728
729
db. roll_back ( )
@@ -773,7 +774,8 @@ impl<'a> ClarityBlockConnection<'a, '_> {
773
774
#[ cfg( test) ]
774
775
pub fn commit_block ( self ) -> LimitedCostTracker {
775
776
debug ! ( "Commit Clarity datastore" ) ;
776
- self . datastore . test_commit ( ) ;
777
+ let bhh = self . datastore . get_block_hash ( ) ;
778
+ self . datastore . commit_to ( & bhh) . unwrap ( ) ;
777
779
778
780
self . cost_track . unwrap ( )
779
781
}
@@ -1709,7 +1711,7 @@ impl<'a> ClarityBlockConnection<'a, '_> {
1709
1711
1710
1712
pub fn start_transaction_processing ( & mut self ) -> ClarityTransactionConnection < ' _ , ' _ > {
1711
1713
ClarityTransactionConnection :: new (
1712
- & mut self . datastore ,
1714
+ self . datastore . as_mut ( ) ,
1713
1715
self . header_db ,
1714
1716
self . burn_state_db ,
1715
1717
& mut self . cost_track ,
@@ -1761,7 +1763,7 @@ impl<'a> ClarityBlockConnection<'a, '_> {
1761
1763
self . datastore . seal ( )
1762
1764
}
1763
1765
1764
- pub fn destruct ( self ) -> WritableMarfStore < ' a > {
1766
+ pub fn destruct ( self ) -> Box < dyn ClarityBackingStore + ' a > {
1765
1767
self . datastore
1766
1768
}
1767
1769
0 commit comments