@@ -11,6 +11,7 @@ import {
11
11
SettlementContractConfig ,
12
12
MandatorySettlementModulesRecord ,
13
13
MandatoryProtocolModulesRecord ,
14
+ BlockProverPublicOutput ,
14
15
} from "@proto-kit/protocol" ;
15
16
import {
16
17
AccountUpdate ,
@@ -20,6 +21,7 @@ import {
20
21
PublicKey ,
21
22
Signature ,
22
23
Transaction ,
24
+ fetchAccount ,
23
25
} from "o1js" ;
24
26
import { inject } from "tsyringe" ;
25
27
import {
@@ -45,6 +47,7 @@ import { AsyncMerkleTreeStore } from "../state/async/AsyncMerkleTreeStore";
45
47
import { CachedMerkleTreeStore } from "../state/merkle/CachedMerkleTreeStore" ;
46
48
import { BlockProofSerializer } from "../protocol/production/helpers/BlockProofSerializer" ;
47
49
import { Settlement } from "../storage/model/Settlement" ;
50
+ import { FeeStrategy } from "../protocol/baselayer/fees/FeeStrategy" ;
48
51
49
52
import { IncomingMessageAdapter } from "./messages/IncomingMessageAdapter" ;
50
53
import type { OutgoingMessageQueue } from "./messages/WithdrawalQueue" ;
@@ -107,7 +110,9 @@ export class SettlementModule
107
110
@inject ( "TransactionSender" )
108
111
private readonly transactionSender : MinaTransactionSender ,
109
112
@inject ( "AreProofsEnabled" )
110
- private readonly areProofsEnabled : AreProofsEnabled
113
+ private readonly areProofsEnabled : AreProofsEnabled ,
114
+ @inject ( "FeeStrategy" )
115
+ private readonly feeStrategy : FeeStrategy
111
116
) {
112
117
super ( ) ;
113
118
}
@@ -234,8 +239,8 @@ export class SettlementModule
234
239
sender : feepayer . toPublicKey ( ) ,
235
240
// eslint-disable-next-line no-plusplus
236
241
nonce : nonce ++ ,
237
- fee : String ( 0.01 * 1e9 ) ,
238
- memo : "Protokit settle " ,
242
+ fee : this . feeStrategy . getFee ( ) ,
243
+ memo : "roll up actions " ,
239
244
} ,
240
245
async ( ) => {
241
246
await settlement . rollupOutgoingMessages (
@@ -246,7 +251,10 @@ export class SettlementModule
246
251
247
252
const signedTx = this . signTransaction ( tx , [ feepayer ] ) ;
248
253
249
- await this . transactionSender . proveAndSendTransaction ( signedTx ) ;
254
+ await this . transactionSender . proveAndSendTransaction (
255
+ signedTx ,
256
+ "included"
257
+ ) ;
250
258
251
259
this . outgoingMessageQueue . pop ( OUTGOING_MESSAGE_BATCH_SIZE ) ;
252
260
@@ -259,33 +267,51 @@ export class SettlementModule
259
267
}
260
268
/* eslint-enable no-await-in-loop */
261
269
270
+ private async fetchContractAccounts ( ) {
271
+ const contracts = this . getContracts ( ) ;
272
+ if ( contracts !== undefined ) {
273
+ const c1 = await fetchAccount ( {
274
+ publicKey : contracts . settlement . address ,
275
+ tokenId : contracts . settlement . tokenId ,
276
+ } ) ;
277
+ const c2 = await fetchAccount ( {
278
+ publicKey : contracts . dispatch . address ,
279
+ tokenId : contracts . dispatch . tokenId ,
280
+ } ) ;
281
+ }
282
+ }
283
+
262
284
public async settleBatch (
263
285
batch : SettleableBatch ,
264
286
options : {
265
287
nonce ?: number ;
266
288
} = { }
267
289
) : Promise < Settlement > {
290
+ await this . fetchContractAccounts ( ) ;
268
291
const { settlement, dispatch } = this . getContracts ( ) ;
269
292
const { feepayer } = this . config ;
270
293
271
294
log . debug ( "Preparing settlement" ) ;
272
295
273
- const lastSettlementL1Block = settlement . lastSettlementL1Block . get ( ) . value ;
296
+ const lastSettlementL1BlockHeight =
297
+ settlement . lastSettlementL1BlockHeight . get ( ) . value ;
274
298
const signature = Signature . create ( feepayer , [
275
299
BATCH_SIGNATURE_PREFIX ,
276
- lastSettlementL1Block ,
300
+ lastSettlementL1BlockHeight ,
277
301
] ) ;
278
302
279
- const fromSequenceStateHash = dispatch . honoredMessagesHash . get ( ) ;
280
- const latestSequenceStateHash = settlement . account . actionState . get ( ) ;
303
+ const fromSequenceStateHash = BlockProverPublicOutput . fromFields (
304
+ batch . proof . publicOutput . map ( ( x ) => Field ( x ) )
305
+ ) . incomingMessagesHash ;
306
+ const latestSequenceStateHash = dispatch . account . actionState . get ( ) ;
281
307
282
308
// Fetch actions and store them into the messageStorage
283
309
const actions = await this . incomingMessagesAdapter . getPendingMessages (
284
- settlement . address ,
310
+ dispatch . address ,
285
311
{
286
312
fromActionHash : fromSequenceStateHash . toString ( ) ,
287
313
toActionHash : latestSequenceStateHash . toString ( ) ,
288
- fromL1Block : Number ( lastSettlementL1Block . toString ( ) ) ,
314
+ fromL1BlockHeight : Number ( lastSettlementL1BlockHeight . toString ( ) ) ,
289
315
}
290
316
) ;
291
317
await this . messageStorage . pushMessages (
@@ -302,7 +328,7 @@ export class SettlementModule
302
328
{
303
329
sender : feepayer . toPublicKey ( ) ,
304
330
nonce : options ?. nonce ,
305
- fee : String ( 0.01 * 1e9 ) ,
331
+ fee : this . feeStrategy . getFee ( ) ,
306
332
memo : "Protokit settle" ,
307
333
} ,
308
334
async ( ) => {
@@ -320,7 +346,7 @@ export class SettlementModule
320
346
321
347
this . signTransaction ( tx , [ feepayer ] ) ;
322
348
323
- await this . transactionSender . proveAndSendTransaction ( tx ) ;
349
+ await this . transactionSender . proveAndSendTransaction ( tx , "included" ) ;
324
350
325
351
log . info ( "Settlement transaction send queued" ) ;
326
352
@@ -355,16 +381,24 @@ export class SettlementModule
355
381
? new SignedSettlementPermissions ( )
356
382
: new ProvenSettlementPermissions ( ) ;
357
383
384
+ if ( this . baseLayer . config . network . type !== "local" ) {
385
+ // const ac1 = await fetchAccount({ publicKey: feepayer });
386
+ // console.log(ac1);
387
+ }
388
+
389
+ // this.baseLayer
390
+ // .originalNetwork!
358
391
const tx = await Mina . transaction (
359
392
{
360
393
sender : feepayer ,
361
394
nonce,
362
- fee : String ( 0.01 * 1e9 ) ,
395
+ fee : this . feeStrategy . getFee ( ) ,
363
396
memo : "Protokit settlement deploy" ,
364
397
} ,
365
398
async ( ) => {
366
399
AccountUpdate . fundNewAccount ( feepayer , 2 ) ;
367
400
await settlement . deploy ( {
401
+ // TODO Create compilation task that generates those artifacts if proofs enabled
368
402
verificationKey : undefined ,
369
403
} ) ;
370
404
settlement . account . permissions . set ( permissions . settlementContract ( ) ) ;
@@ -379,7 +413,7 @@ export class SettlementModule
379
413
380
414
// This should already apply the tx result to the
381
415
// cached accounts / local blockchain
382
- await this . transactionSender . proveAndSendTransaction ( tx ) ;
416
+ await this . transactionSender . proveAndSendTransaction ( tx , "included" ) ;
383
417
384
418
this . addresses = {
385
419
settlement : settlementKey . toPublicKey ( ) ,
@@ -394,7 +428,7 @@ export class SettlementModule
394
428
{
395
429
sender : feepayer ,
396
430
nonce : nonce + 1 ,
397
- fee : String ( 0.01 * 1e9 ) ,
431
+ fee : this . feeStrategy . getFee ( ) ,
398
432
memo : "Protokit settlement init" ,
399
433
} ,
400
434
async ( ) => {
@@ -407,7 +441,10 @@ export class SettlementModule
407
441
408
442
const initTxSigned = this . signTransaction ( initTx , [ feepayerKey ] ) ;
409
443
410
- await this . transactionSender . proveAndSendTransaction ( initTxSigned ) ;
444
+ await this . transactionSender . proveAndSendTransaction (
445
+ initTxSigned ,
446
+ "included"
447
+ ) ;
411
448
}
412
449
413
450
public async start ( ) : Promise < void > {
0 commit comments