arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
hermez-node/coordinator/pipeline.go
coordinator/pipeline.goRaw
  1package coordinator
  2
  3import (
  4	"context"
  5	"database/sql"
  6	"fmt"
  7	"math/big"
  8	"sync"
  9	"time"
 10
 11	"github.com/hermeznetwork/hermez-node/batchbuilder"
 12	"github.com/hermeznetwork/hermez-node/common"
 13	"github.com/hermeznetwork/hermez-node/db/historydb"
 14	"github.com/hermeznetwork/hermez-node/db/l2db"
 15	"github.com/hermeznetwork/hermez-node/eth"
 16	"github.com/hermeznetwork/hermez-node/log"
 17	"github.com/hermeznetwork/hermez-node/prover"
 18	"github.com/hermeznetwork/hermez-node/synchronizer"
 19	"github.com/hermeznetwork/hermez-node/txselector"
 20	"github.com/hermeznetwork/tracerr"
 21)
 22
 23type statsVars struct {
 24	Stats synchronizer.Stats
 25	Vars  common.SCVariablesPtr
 26}
 27
 28type state struct {
 29	batchNum                     common.BatchNum
 30	lastScheduledL1BatchBlockNum int64
 31	lastForgeL1TxsNum            int64
 32	lastSlotForged               int64
 33}
 34
 35// Pipeline manages the forging of batches with parallel server proofs
 36type Pipeline struct {
 37	num    int
 38	cfg    Config
 39	consts common.SCConsts
 40
 41	// state
 42	state         state
 43	started       bool
 44	rw            sync.RWMutex
 45	errAtBatchNum common.BatchNum
 46	lastForgeTime time.Time
 47
 48	proversPool           *ProversPool
 49	provers               []prover.Client
 50	coord                 *Coordinator
 51	txManager             *TxManager
 52	historyDB             *historydb.HistoryDB
 53	l2DB                  *l2db.L2DB
 54	txSelector            *txselector.TxSelector
 55	batchBuilder          *batchbuilder.BatchBuilder
 56	mutexL2DBUpdateDelete *sync.Mutex
 57	purger                *Purger
 58
 59	stats       synchronizer.Stats
 60	vars        common.SCVariables
 61	statsVarsCh chan statsVars
 62
 63	ctx    context.Context
 64	wg     sync.WaitGroup
 65	cancel context.CancelFunc
 66}
 67
 68func (p *Pipeline) setErrAtBatchNum(batchNum common.BatchNum) {
 69	p.rw.Lock()
 70	defer p.rw.Unlock()
 71	p.errAtBatchNum = batchNum
 72}
 73
 74func (p *Pipeline) getErrAtBatchNum() common.BatchNum {
 75	p.rw.RLock()
 76	defer p.rw.RUnlock()
 77	return p.errAtBatchNum
 78}
 79
 80// NewPipeline creates a new Pipeline
 81func NewPipeline(ctx context.Context,
 82	cfg Config,
 83	num int, // Pipeline sequential number
 84	historyDB *historydb.HistoryDB,
 85	l2DB *l2db.L2DB,
 86	txSelector *txselector.TxSelector,
 87	batchBuilder *batchbuilder.BatchBuilder,
 88	mutexL2DBUpdateDelete *sync.Mutex,
 89	purger *Purger,
 90	coord *Coordinator,
 91	txManager *TxManager,
 92	provers []prover.Client,
 93	scConsts *common.SCConsts,
 94) (*Pipeline, error) {
 95	proversPool := NewProversPool(len(provers))
 96	proversPoolSize := 0
 97	for _, prover := range provers {
 98		if err := prover.WaitReady(ctx); err != nil {
 99			log.Errorw("prover.WaitReady", "err", err)
100		} else {
101			proversPool.Add(ctx, prover)
102			proversPoolSize++
103		}
104	}
105	if proversPoolSize == 0 {
106		return nil, tracerr.Wrap(fmt.Errorf("no provers in the pool"))
107	}
108	return &Pipeline{
109		num:                   num,
110		cfg:                   cfg,
111		historyDB:             historyDB,
112		l2DB:                  l2DB,
113		txSelector:            txSelector,
114		batchBuilder:          batchBuilder,
115		provers:               provers,
116		proversPool:           proversPool,
117		mutexL2DBUpdateDelete: mutexL2DBUpdateDelete,
118		purger:                purger,
119		coord:                 coord,
120		txManager:             txManager,
121		consts:                *scConsts,
122		statsVarsCh:           make(chan statsVars, queueLen),
123	}, nil
124}
125
126// SetSyncStatsVars is a thread safe method to sets the synchronizer Stats
127func (p *Pipeline) SetSyncStatsVars(ctx context.Context, stats *synchronizer.Stats,
128	vars *common.SCVariablesPtr) {
129	select {
130	case p.statsVarsCh <- statsVars{Stats: *stats, Vars: *vars}:
131	case <-ctx.Done():
132	}
133}
134
135// reset pipeline state
136func (p *Pipeline) reset(batchNum common.BatchNum,
137	stats *synchronizer.Stats, vars *common.SCVariables) error {
138	p.state = state{
139		batchNum:                     batchNum,
140		lastForgeL1TxsNum:            stats.Sync.LastForgeL1TxsNum,
141		lastScheduledL1BatchBlockNum: 0,
142		lastSlotForged:               -1,
143	}
144	p.stats = *stats
145	p.vars = *vars
146
147	// Reset the StateDB in TxSelector and BatchBuilder from the
148	// synchronizer only if the checkpoint we reset from either:
149	// a. Doesn't exist in the TxSelector/BatchBuilder
150	// b. The batch has already been synced by the synchronizer and has a
151	//    different MTRoot than the BatchBuilder
152	// Otherwise, reset from the local checkpoint.
153
154	// First attempt to reset from local checkpoint if such checkpoint exists
155	existsTxSelector, err := p.txSelector.LocalAccountsDB().CheckpointExists(p.state.batchNum)
156	if err != nil {
157		return tracerr.Wrap(err)
158	}
159	fromSynchronizerTxSelector := !existsTxSelector
160	if err := p.txSelector.Reset(p.state.batchNum, fromSynchronizerTxSelector); err != nil {
161		return tracerr.Wrap(err)
162	}
163	existsBatchBuilder, err := p.batchBuilder.LocalStateDB().CheckpointExists(p.state.batchNum)
164	if err != nil {
165		return tracerr.Wrap(err)
166	}
167	fromSynchronizerBatchBuilder := !existsBatchBuilder
168	if err := p.batchBuilder.Reset(p.state.batchNum, fromSynchronizerBatchBuilder); err != nil {
169		return tracerr.Wrap(err)
170	}
171
172	// After reset, check that if the batch exists in the historyDB, the
173	// stateRoot matches with the local one, if not, force a reset from
174	// synchronizer
175	batch, err := p.historyDB.GetBatch(p.state.batchNum)
176	if tracerr.Unwrap(err) == sql.ErrNoRows {
177		// nothing to do
178	} else if err != nil {
179		return tracerr.Wrap(err)
180	} else {
181		localStateRoot := p.batchBuilder.LocalStateDB().MT.Root().BigInt()
182		if batch.StateRoot.Cmp(localStateRoot) != 0 {
183			log.Debugw("localStateRoot (%v) != historyDB stateRoot (%v).  "+
184				"Forcing reset from Synchronizer", localStateRoot, batch.StateRoot)
185			// StateRoot from synchronizer doesn't match StateRoot
186			// from batchBuilder, force a reset from synchronizer
187			if err := p.txSelector.Reset(p.state.batchNum, true); err != nil {
188				return tracerr.Wrap(err)
189			}
190			if err := p.batchBuilder.Reset(p.state.batchNum, true); err != nil {
191				return tracerr.Wrap(err)
192			}
193		}
194	}
195	return nil
196}
197
198func (p *Pipeline) syncSCVars(vars common.SCVariablesPtr) {
199	updateSCVars(&p.vars, vars)
200}
201
202// handleForgeBatch waits for an available proof server, calls p.forgeBatch to
203// forge the batch and get the zkInputs, and then  sends the zkInputs to the
204// selected proof server so that the proof computation begins.
205func (p *Pipeline) handleForgeBatch(ctx context.Context,
206	batchNum common.BatchNum) (batchInfo *BatchInfo, err error) {
207	// 1. Wait for an available serverProof (blocking call)
208	serverProof, err := p.proversPool.Get(ctx)
209	if ctx.Err() != nil {
210		return nil, ctx.Err()
211	} else if err != nil {
212		log.Errorw("proversPool.Get", "err", err)
213		return nil, tracerr.Wrap(err)
214	}
215	defer func() {
216		// If we encounter any error (notice that this function returns
217		// errors to notify that a batch is not forged not only because
218		// of unexpected errors but also due to benign causes), add the
219		// serverProof back to the pool
220		if err != nil {
221			p.proversPool.Add(ctx, serverProof)
222		}
223	}()
224
225	// 2. Forge the batch internally (make a selection of txs and prepare
226	// all the smart contract arguments)
227	p.mutexL2DBUpdateDelete.Lock()
228	batchInfo, err = p.forgeBatch(batchNum)
229	p.mutexL2DBUpdateDelete.Unlock()
230	if ctx.Err() != nil {
231		return nil, ctx.Err()
232	} else if err != nil {
233		if tracerr.Unwrap(err) == errLastL1BatchNotSynced {
234			log.Warnw("forgeBatch: scheduled L1Batch too early", "err", err,
235				"lastForgeL1TxsNum", p.state.lastForgeL1TxsNum,
236				"syncLastForgeL1TxsNum", p.stats.Sync.LastForgeL1TxsNum)
237		} else if tracerr.Unwrap(err) == errForgeNoTxsBeforeDelay ||
238			tracerr.Unwrap(err) == errForgeBeforeDelay {
239			// no log
240		} else {
241			log.Errorw("forgeBatch", "err", err)
242		}
243		return nil, tracerr.Wrap(err)
244	}
245
246	// 3. Send the ZKInputs to the proof server
247	batchInfo.ServerProof = serverProof
248	if err := p.sendServerProof(ctx, batchInfo); ctx.Err() != nil {
249		return nil, ctx.Err()
250	} else if err != nil {
251		log.Errorw("sendServerProof", "err", err)
252		return nil, tracerr.Wrap(err)
253	}
254	return batchInfo, nil
255}
256
257// Start the forging pipeline
258func (p *Pipeline) Start(batchNum common.BatchNum,
259	stats *synchronizer.Stats, vars *common.SCVariables) error {
260	if p.started {
261		log.Fatal("Pipeline already started")
262	}
263	p.started = true
264
265	if err := p.reset(batchNum, stats, vars); err != nil {
266		return tracerr.Wrap(err)
267	}
268	p.ctx, p.cancel = context.WithCancel(context.Background())
269
270	queueSize := 1
271	batchChSentServerProof := make(chan *BatchInfo, queueSize)
272
273	p.wg.Add(1)
274	go func() {
275		timer := time.NewTimer(zeroDuration)
276		for {
277			select {
278			case <-p.ctx.Done():
279				log.Info("Pipeline forgeBatch loop done")
280				p.wg.Done()
281				return
282			case statsVars := <-p.statsVarsCh:
283				p.stats = statsVars.Stats
284				p.syncSCVars(statsVars.Vars)
285			case <-timer.C:
286				timer.Reset(p.cfg.ForgeRetryInterval)
287				// Once errAtBatchNum != 0, we stop forging
288				// batches because there's been an error and we
289				// wait for the pipeline to be stopped.
290				if p.getErrAtBatchNum() != 0 {
291					continue
292				}
293				batchNum = p.state.batchNum + 1
294				batchInfo, err := p.handleForgeBatch(p.ctx, batchNum)
295				if p.ctx.Err() != nil {
296					continue
297				} else if tracerr.Unwrap(err) == errLastL1BatchNotSynced ||
298					tracerr.Unwrap(err) == errForgeNoTxsBeforeDelay ||
299					tracerr.Unwrap(err) == errForgeBeforeDelay {
300					continue
301				} else if err != nil {
302					p.setErrAtBatchNum(batchNum)
303					p.coord.SendMsg(p.ctx, MsgStopPipeline{
304						Reason: fmt.Sprintf(
305							"Pipeline.handleForgBatch: %v", err),
306						FailedBatchNum: batchNum,
307					})
308					continue
309				}
310				p.lastForgeTime = time.Now()
311
312				p.state.batchNum = batchNum
313				select {
314				case batchChSentServerProof <- batchInfo:
315				case <-p.ctx.Done():
316				}
317				if !timer.Stop() {
318					<-timer.C
319				}
320				timer.Reset(zeroDuration)
321			}
322		}
323	}()
324
325	p.wg.Add(1)
326	go func() {
327		for {
328			select {
329			case <-p.ctx.Done():
330				log.Info("Pipeline waitServerProofSendEth loop done")
331				p.wg.Done()
332				return
333			case batchInfo := <-batchChSentServerProof:
334				// Once errAtBatchNum != 0, we stop forging
335				// batches because there's been an error and we
336				// wait for the pipeline to be stopped.
337				if p.getErrAtBatchNum() != 0 {
338					continue
339				}
340				err := p.waitServerProof(p.ctx, batchInfo)
341				if p.ctx.Err() != nil {
342					continue
343				} else if err != nil {
344					log.Errorw("waitServerProof", "err", err)
345					p.setErrAtBatchNum(batchInfo.BatchNum)
346					p.coord.SendMsg(p.ctx, MsgStopPipeline{
347						Reason: fmt.Sprintf(
348							"Pipeline.waitServerProof: %v", err),
349						FailedBatchNum: batchInfo.BatchNum,
350					})
351					continue
352				}
353				// We are done with this serverProof, add it back to the pool
354				p.proversPool.Add(p.ctx, batchInfo.ServerProof)
355				p.txManager.AddBatch(p.ctx, batchInfo)
356			}
357		}
358	}()
359	return nil
360}
361
362// Stop the forging pipeline
363func (p *Pipeline) Stop(ctx context.Context) {
364	if !p.started {
365		log.Fatal("Pipeline already stopped")
366	}
367	p.started = false
368	log.Info("Stopping Pipeline...")
369	p.cancel()
370	p.wg.Wait()
371	for _, prover := range p.provers {
372		if err := prover.Cancel(ctx); ctx.Err() != nil {
373			continue
374		} else if err != nil {
375			log.Errorw("prover.Cancel", "err", err)
376		}
377	}
378}
379
380// sendServerProof sends the circuit inputs to the proof server
381func (p *Pipeline) sendServerProof(ctx context.Context, batchInfo *BatchInfo) error {
382	p.cfg.debugBatchStore(batchInfo)
383
384	// 7. Call the selected idle server proof with BatchBuilder output,
385	// save server proof info for batchNum
386	if err := batchInfo.ServerProof.CalculateProof(ctx, batchInfo.ZKInputs); err != nil {
387		return tracerr.Wrap(err)
388	}
389	return nil
390}
391
392// check if we reach the ForgeDelay or not before batch forging
393func (p *Pipeline) preForgeBatchCheck(slotCommitted bool, now time.Time) error {
394	if slotCommitted && now.Sub(p.lastForgeTime) < p.cfg.ForgeDelay {
395		return errForgeBeforeDelay
396	}
397	return nil
398}
399
400// forgeBatch forges the batchNum batch.
401func (p *Pipeline) forgeBatch(batchNum common.BatchNum) (batchInfo *BatchInfo, err error) {
402	// remove transactions from the pool that have been there for too long
403	_, err = p.purger.InvalidateMaybe(p.l2DB, p.txSelector.LocalAccountsDB(),
404		p.stats.Sync.LastBlock.Num, int64(batchNum))
405	if err != nil {
406		return nil, tracerr.Wrap(err)
407	}
408	_, err = p.purger.PurgeMaybe(p.l2DB, p.stats.Sync.LastBlock.Num, int64(batchNum))
409	if err != nil {
410		return nil, tracerr.Wrap(err)
411	}
412	// Structure to accumulate data and metadata of the batch
413	now := time.Now()
414	batchInfo = &BatchInfo{PipelineNum: p.num, BatchNum: batchNum}
415	batchInfo.Debug.StartTimestamp = now
416	batchInfo.Debug.StartBlockNum = p.stats.Eth.LastBlock.Num + 1
417
418	var poolL2Txs []common.PoolL2Tx
419	var discardedL2Txs []common.PoolL2Tx
420	var l1UserTxsExtra, l1CoordTxs []common.L1Tx
421	var auths [][]byte
422	var coordIdxs []common.Idx
423
424	// Check if the slot is not yet fulfilled
425	slotCommitted := p.cfg.IgnoreSlotCommitment
426	if p.stats.Sync.Auction.CurrentSlot.ForgerCommitment ||
427		p.stats.Sync.Auction.CurrentSlot.SlotNum == p.state.lastSlotForged {
428		slotCommitted = true
429	}
430
431	// If we haven't reached the ForgeDelay, skip forging the batch
432	if err = p.preForgeBatchCheck(slotCommitted, now); err != nil {
433		return nil, tracerr.Wrap(err)
434	}
435
436	// 1. Decide if we forge L2Tx or L1+L2Tx
437	if p.shouldL1L2Batch(batchInfo) {
438		batchInfo.L1Batch = true
439		if p.state.lastForgeL1TxsNum != p.stats.Sync.LastForgeL1TxsNum {
440			return nil, tracerr.Wrap(errLastL1BatchNotSynced)
441		}
442		// 2a: L1+L2 txs
443		l1UserTxs, err := p.historyDB.GetUnforgedL1UserTxs(p.state.lastForgeL1TxsNum + 1)
444		if err != nil {
445			return nil, tracerr.Wrap(err)
446		}
447		coordIdxs, auths, l1UserTxsExtra, l1CoordTxs, poolL2Txs, discardedL2Txs, err =
448			p.txSelector.GetL1L2TxSelection(p.cfg.TxProcessorConfig, l1UserTxs)
449		if err != nil {
450			return nil, tracerr.Wrap(err)
451		}
452	} else {
453		// 2b: only L2 txs
454		coordIdxs, auths, l1CoordTxs, poolL2Txs, discardedL2Txs, err =
455			p.txSelector.GetL2TxSelection(p.cfg.TxProcessorConfig)
456		if err != nil {
457			return nil, tracerr.Wrap(err)
458		}
459		l1UserTxsExtra = nil
460	}
461
462	// If there are no txs to forge, no l1UserTxs in the open queue to
463	// freeze, and we haven't reached the ForgeNoTxsDelay, skip forging the
464	// batch.
465	if err = p.postForgeBatchCheck(slotCommitted, now, l1UserTxsExtra, l1CoordTxs, poolL2Txs, batchInfo); err != nil {
466		return nil, tracerr.Wrap(err)
467	}
468
469	if batchInfo.L1Batch {
470		p.state.lastScheduledL1BatchBlockNum = p.stats.Eth.LastBlock.Num + 1
471		p.state.lastForgeL1TxsNum++
472	}
473
474	// 3.  Save metadata from TxSelector output for BatchNum
475	batchInfo.L1UserTxsExtra = l1UserTxsExtra
476	batchInfo.L1CoordTxs = l1CoordTxs
477	batchInfo.L1CoordinatorTxsAuths = auths
478	batchInfo.CoordIdxs = coordIdxs
479	batchInfo.VerifierIdx = p.cfg.VerifierIdx
480
481	if err := p.l2DB.StartForging(common.TxIDsFromPoolL2Txs(poolL2Txs),
482		batchInfo.BatchNum); err != nil {
483		return nil, tracerr.Wrap(err)
484	}
485	if err := p.l2DB.UpdateTxsInfo(discardedL2Txs); err != nil {
486		return nil, tracerr.Wrap(err)
487	}
488
489	// Invalidate transactions that become invalid because of
490	// the poolL2Txs selected.  Will mark as invalid the txs that have a
491	// (fromIdx, nonce) which already appears in the selected txs (includes
492	// all the nonces smaller than the current one)
493	err = p.l2DB.InvalidateOldNonces(idxsNonceFromPoolL2Txs(poolL2Txs), batchInfo.BatchNum)
494	if err != nil {
495		return nil, tracerr.Wrap(err)
496	}
497
498	// 4. Call BatchBuilder with TxSelector output
499	configBatch := &batchbuilder.ConfigBatch{
500		TxProcessorConfig: p.cfg.TxProcessorConfig,
501	}
502	zkInputs, err := p.batchBuilder.BuildBatch(coordIdxs, configBatch, l1UserTxsExtra,
503		l1CoordTxs, poolL2Txs)
504	if err != nil {
505		return nil, tracerr.Wrap(err)
506	}
507	l2Txs, err := common.PoolL2TxsToL2Txs(poolL2Txs) // NOTE: This is a big uggly, find a better way
508	if err != nil {
509		return nil, tracerr.Wrap(err)
510	}
511	batchInfo.L2Txs = l2Txs
512
513	// 5. Save metadata from BatchBuilder output for BatchNum
514	batchInfo.ZKInputs = zkInputs
515	batchInfo.Debug.Status = StatusForged
516	p.cfg.debugBatchStore(batchInfo)
517	log.Infow("Pipeline: batch forged internally", "batch", batchInfo.BatchNum)
518
519	p.state.lastSlotForged = p.stats.Sync.Auction.CurrentSlot.SlotNum
520
521	return batchInfo, nil
522}
523
524// check if there is no txs to forge, no l1UserTxs in the open queue to freeze and we haven't reached the ForgeNoTxsDelay
525func (p *Pipeline) postForgeBatchCheck(slotCommitted bool, now time.Time, l1UserTxsExtra, l1CoordTxs []common.L1Tx,
526	poolL2Txs []common.PoolL2Tx, batchInfo *BatchInfo) error {
527	if slotCommitted && now.Sub(p.lastForgeTime) < p.cfg.ForgeNoTxsDelay {
528		noTxs := false
529		if len(l1UserTxsExtra) == 0 && len(l1CoordTxs) == 0 && len(poolL2Txs) == 0 {
530			if batchInfo.L1Batch {
531				// Query the number of unforged L1UserTxs
532				// (either in a open queue or in a frozen
533				// not-yet-forged queue).
534				count, err := p.historyDB.GetUnforgedL1UserTxsCount()
535				if err != nil {
536					return err
537				}
538				// If there are future L1UserTxs, we forge a
539				// batch to advance the queues to be able to
540				// forge the L1UserTxs in the future.
541				// Otherwise, skip.
542				if count == 0 {
543					noTxs = true
544				}
545			} else {
546				noTxs = true
547			}
548		}
549		if noTxs {
550			if err := p.txSelector.Reset(batchInfo.BatchNum-1, false); err != nil {
551				return err
552			}
553			return errForgeNoTxsBeforeDelay
554		}
555	}
556	return nil
557}
558
559// waitServerProof gets the generated zkProof & sends it to the SmartContract
560func (p *Pipeline) waitServerProof(ctx context.Context, batchInfo *BatchInfo) error {
561	proof, pubInputs, err := batchInfo.ServerProof.GetProof(ctx) // blocking call,
562	// until not resolved don't continue. Returns when the proof server has calculated the proof
563	if err != nil {
564		return tracerr.Wrap(err)
565	}
566	batchInfo.Proof = proof
567	batchInfo.PublicInputs = pubInputs
568	batchInfo.ForgeBatchArgs = prepareForgeBatchArgs(batchInfo)
569	batchInfo.Debug.Status = StatusProof
570	p.cfg.debugBatchStore(batchInfo)
571	log.Infow("Pipeline: batch proof calculated", "batch", batchInfo.BatchNum)
572	return nil
573}
574
575func (p *Pipeline) shouldL1L2Batch(batchInfo *BatchInfo) bool {
576	// Take the lastL1BatchBlockNum as the biggest between the last
577	// scheduled one, and the synchronized one.
578	lastL1BatchBlockNum := p.state.lastScheduledL1BatchBlockNum
579	if p.stats.Sync.LastL1BatchBlock > lastL1BatchBlockNum {
580		lastL1BatchBlockNum = p.stats.Sync.LastL1BatchBlock
581	}
582	// Set Debug information
583	batchInfo.Debug.LastScheduledL1BatchBlockNum = p.state.lastScheduledL1BatchBlockNum
584	batchInfo.Debug.LastL1BatchBlock = p.stats.Sync.LastL1BatchBlock
585	batchInfo.Debug.LastL1BatchBlockDelta = p.stats.Eth.LastBlock.Num + 1 - lastL1BatchBlockNum
586	batchInfo.Debug.L1BatchBlockScheduleDeadline =
587		int64(float64(p.vars.Rollup.ForgeL1L2BatchTimeout-1) * p.cfg.L1BatchTimeoutPerc)
588	// Return true if we have passed the l1BatchTimeoutPerc portion of the
589	// range before the l1batch timeout.
590	return p.stats.Eth.LastBlock.Num+1-lastL1BatchBlockNum >=
591		int64(float64(p.vars.Rollup.ForgeL1L2BatchTimeout-1)*p.cfg.L1BatchTimeoutPerc)
592}
593
594func prepareForgeBatchArgs(batchInfo *BatchInfo) *eth.RollupForgeBatchArgs {
595	proof := batchInfo.Proof
596	zki := batchInfo.ZKInputs
597	return &eth.RollupForgeBatchArgs{
598		NewLastIdx:            int64(zki.Metadata.NewLastIdxRaw),
599		NewStRoot:             zki.Metadata.NewStateRootRaw.BigInt(),
600		NewExitRoot:           zki.Metadata.NewExitRootRaw.BigInt(),
601		L1UserTxs:             batchInfo.L1UserTxsExtra,
602		L1CoordinatorTxs:      batchInfo.L1CoordTxs,
603		L1CoordinatorTxsAuths: batchInfo.L1CoordinatorTxsAuths,
604		L2TxsData:             batchInfo.L2Txs,
605		FeeIdxCoordinator:     batchInfo.CoordIdxs,
606		// Circuit selector
607		VerifierIdx: batchInfo.VerifierIdx,
608		L1Batch:     batchInfo.L1Batch,
609		ProofA:      [2]*big.Int{proof.PiA[0], proof.PiA[1]},
610		// Implementation of the verifier need a swap on the proofB vector
611		ProofB: [2][2]*big.Int{
612			{proof.PiB[0][1], proof.PiB[0][0]},
613			{proof.PiB[1][1], proof.PiB[1][0]},
614		},
615		ProofC: [2]*big.Int{proof.PiC[0], proof.PiC[1]},
616	}
617}