@@ -13,9 +13,7 @@ import {
13
13
} from "../../sequencer/builder/SequencerModule" ;
14
14
import { BatchStorage } from "../../storage/repositories/BatchStorage" ;
15
15
import { SettleableBatch } from "../../storage/model/Batch" ;
16
- import { CachedStateService } from "../../state/state/CachedStateService" ;
17
16
import { CachedMerkleTreeStore } from "../../state/merkle/CachedMerkleTreeStore" ;
18
- import { AsyncStateService } from "../../state/async/AsyncStateService" ;
19
17
import { AsyncMerkleTreeStore } from "../../state/async/AsyncMerkleTreeStore" ;
20
18
import { BlockWithResult } from "../../storage/model/Block" ;
21
19
@@ -27,8 +25,9 @@ export type StateRecord = Record<string, Field[] | undefined>;
27
25
28
26
interface BatchMetadata {
29
27
batch : SettleableBatch ;
30
- stateService : CachedStateService ;
31
- merkleStore : CachedMerkleTreeStore ;
28
+ changes : {
29
+ commit : ( ) => Promise < void > ;
30
+ } ;
32
31
}
33
32
34
33
const errors = {
@@ -49,8 +48,6 @@ export class BatchProducerModule extends SequencerModule {
49
48
private productionInProgress = false ;
50
49
51
50
public constructor (
52
- @inject ( "AsyncStateService" )
53
- private readonly asyncStateService : AsyncStateService ,
54
51
@inject ( "AsyncMerkleStore" )
55
52
private readonly merkleStore : AsyncMerkleTreeStore ,
56
53
@inject ( "BatchStorage" ) private readonly batchStorage : BatchStorage ,
@@ -61,11 +58,6 @@ export class BatchProducerModule extends SequencerModule {
61
58
super ( ) ;
62
59
}
63
60
64
- private async applyStateChanges ( batch : BatchMetadata ) {
65
- await batch . stateService . mergeIntoParent ( ) ;
66
- await batch . merkleStore . mergeIntoParent ( ) ;
67
- }
68
-
69
61
/**
70
62
* Main function to call when wanting to create a new block based on the
71
63
* transactions that are present in the mempool. This function should also
@@ -89,8 +81,11 @@ export class BatchProducerModule extends SequencerModule {
89
81
`Batch produced (${ batchWithStateDiff . batch . blockHashes . length } blocks, ${ numTxs } txs)`
90
82
) ;
91
83
92
- // Apply state changes to current StateService
93
- await this . applyStateChanges ( batchWithStateDiff ) ;
84
+ // Apply state changes to current MerkleTreeStore
85
+ await batchWithStateDiff . changes . commit ( ) ;
86
+
87
+ // TODO Add transition from unproven to proven state for stateservice
88
+ // This needs proper DB-level masking
94
89
}
95
90
return batchWithStateDiff ?. batch ;
96
91
}
@@ -158,8 +153,7 @@ export class BatchProducerModule extends SequencerModule {
158
153
toNetworkState : batch . toNetworkState ,
159
154
} ,
160
155
161
- stateService : batch . stateService ,
162
- merkleStore : batch . merkleStore ,
156
+ changes : batch . changes ,
163
157
} ;
164
158
}
165
159
@@ -181,36 +175,35 @@ export class BatchProducerModule extends SequencerModule {
181
175
blockId : number
182
176
) : Promise < {
183
177
proof : Proof < BlockProverPublicInput , BlockProverPublicOutput > ;
184
- // TODO Return State services as commit-only object
185
- stateService : CachedStateService ;
186
- merkleStore : CachedMerkleTreeStore ;
178
+ changes : {
179
+ commit : ( ) => Promise < void > ;
180
+ } ;
187
181
fromNetworkState : NetworkState ;
188
182
toNetworkState : NetworkState ;
189
183
} > {
190
184
if ( blocks . length === 0 || blocks . flat ( 1 ) . length === 0 ) {
191
185
throw errors . blockWithoutTxs ( ) ;
192
186
}
193
187
194
- const stateServices = {
195
- // TODO Remove stateService
196
- stateService : new CachedStateService ( this . asyncStateService ) ,
197
- merkleTreeStore : new CachedMerkleTreeStore ( this . merkleStore ) ,
198
- } ;
188
+ const merkleTreeStore = new CachedMerkleTreeStore ( this . merkleStore ) ;
199
189
200
190
const trace = await this . batchTraceService . traceBatch (
201
191
blocks . map ( ( block ) => block ) ,
202
- stateServices
192
+ merkleTreeStore
203
193
) ;
204
194
205
195
const proof = await this . batchFlow . executeBatch ( trace , blockId ) ;
206
196
207
197
const fromNetworkState = blocks [ 0 ] . block . networkState . before ;
208
198
const toNetworkState = blocks . at ( - 1 ) ! . result . afterNetworkState ;
209
199
200
+ const changes = {
201
+ commit : merkleTreeStore . commit ,
202
+ } ;
203
+
210
204
return {
211
205
proof,
212
- stateService : stateServices . stateService ,
213
- merkleStore : stateServices . merkleTreeStore ,
206
+ changes,
214
207
fromNetworkState,
215
208
toNetworkState,
216
209
} ;
0 commit comments