Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions sequencer/closingsignalsmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ func newClosingSignalsManager(ctx context.Context, dbManager dbManagerInterface,
func (c *closingSignalsManager) Start() {
go c.checkForcedBatches()
go c.checkGERUpdate()
go c.checkSendToL1Timeout()
}

func (c *closingSignalsManager) checkSendToL1Timeout() {
for {
timestamp, err := c.dbManager.GetLatestVirtualBatchTimestamp(c.ctx, nil)
if err != nil {
log.Errorf("error checking latest virtual batch timestamp: %v", err)
time.Sleep(c.cfg.ClosingSignalsManagerWaitForL1OperationsInSec.Duration)
} else {
limit := time.Now().Unix() - int64(c.cfg.SendingToL1DeadlineTimeoutInSec.Duration.Seconds())

if timestamp.Unix() < limit {
c.closingSignalCh.SendingToL1TimeoutCh <- true
time.Sleep(c.cfg.ClosingSignalsManagerWaitForL1OperationsInSec.Duration)
} else {
time.Sleep(time.Duration(limit-timestamp.Unix()) * time.Second)
}
}
}
}

func (c *closingSignalsManager) checkGERUpdate() {
Expand Down
2 changes: 1 addition & 1 deletion sequencer/closingsignalsmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func setupTest(t *testing.T) {
panic(err)
}

zkProverURI := testutils.GetEnv("ZKPROVER_URI", "34.245.104.156")
zkProverURI := testutils.GetEnv("ZKPROVER_URI", "localhost")
mtDBServerConfig := merkletree.Config{URI: fmt.Sprintf("%s:50061", zkProverURI)}
var mtDBCancel context.CancelFunc
mtDBServiceClient, mtDBClientConn, mtDBCancel = merkletree.NewMTDBServiceClient(ctx, mtDBServerConfig)
Expand Down
5 changes: 5 additions & 0 deletions sequencer/dbmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,8 @@ func (d *dbManager) GetTransactionsByBatchNumber(ctx context.Context, batchNumbe
func (d *dbManager) UpdateTxStatus(ctx context.Context, hash common.Hash, newStatus pool.TxStatus) error {
return d.txPool.UpdateTxStatus(ctx, hash, newStatus)
}

// GetLatestVirtualBatchTimestamp gets last virtual batch timestamp
func (d *dbManager) GetLatestVirtualBatchTimestamp(ctx context.Context, dbTx pgx.Tx) (time.Time, error) {
return d.state.GetLatestVirtualBatchTimestamp(ctx, dbTx)
}
2 changes: 1 addition & 1 deletion sequencer/dbmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func setupDBManager() {
panic(err)
}

zkProverURI := testutils.GetEnv("ZKPROVER_URI", "34.245.104.156")
zkProverURI := testutils.GetEnv("ZKPROVER_URI", "localhost")
mtDBServerConfig := merkletree.Config{URI: fmt.Sprintf("%s:50061", zkProverURI)}
var mtDBCancel context.CancelFunc
mtDBServiceClient, mtDBClientConn, mtDBCancel = merkletree.NewMTDBServiceClient(ctx, mtDBServerConfig)
Expand Down
3 changes: 3 additions & 0 deletions sequencer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type stateInterface interface {
ProcessSequencerBatch(ctx context.Context, batchNumber uint64, batchL2Data []byte, caller state.CallerLabel, dbTx pgx.Tx) (*state.ProcessBatchResponse, error)
GetForcedBatchesSince(ctx context.Context, forcedBatchNumber uint64, dbTx pgx.Tx) ([]*state.ForcedBatch, error)
GetLastTrustedForcedBatchNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
GetLatestVirtualBatchTimestamp(ctx context.Context, dbTx pgx.Tx) (time.Time, error)
}

type workerInterface interface {
Expand Down Expand Up @@ -109,6 +110,7 @@ type dbManagerInterface interface {
GetLastTrustedForcedBatchNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
GetBalanceByStateRoot(ctx context.Context, address common.Address, root common.Hash) (*big.Int, error)
UpdateTxStatus(ctx context.Context, hash common.Hash, newStatus pool.TxStatus) error
GetLatestVirtualBatchTimestamp(ctx context.Context, dbTx pgx.Tx) (time.Time, error)
}

type dbManagerStateInterface interface {
Expand All @@ -135,6 +137,7 @@ type dbManagerStateInterface interface {
GetForcedBatchesSince(ctx context.Context, forcedBatchNumber uint64, dbTx pgx.Tx) ([]*state.ForcedBatch, error)
GetLastTrustedForcedBatchNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
GetBalanceByStateRoot(ctx context.Context, address common.Address, root common.Hash) (*big.Int, error)
GetLatestVirtualBatchTimestamp(ctx context.Context, dbTx pgx.Tx) (time.Time, error)
}

type ethTxManager interface {
Expand Down
21 changes: 21 additions & 0 deletions sequencer/mock_db_manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions sequencer/mock_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions state/pgstatestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,21 @@ func (p *PostgresStorage) GetLastVirtualBatchNum(ctx context.Context, dbTx pgx.T
return batchNum, nil
}

// GetLatestVirtualBatchTimestamp gets last virtual batch timestamp
func (p *PostgresStorage) GetLatestVirtualBatchTimestamp(ctx context.Context, dbTx pgx.Tx) (time.Time, error) {
const getLastVirtualBatchTimestampSQL = `SELECT MAX(block.received_at) FROM state.virtual_batch INNER JOIN state.block ON state.block.block_num = virtual_batch.block_num`
var timestamp time.Time
e := p.getExecQuerier(dbTx)
err := e.QueryRow(ctx, getLastVirtualBatchTimestampSQL).Scan(&timestamp)

if errors.Is(err, pgx.ErrNoRows) {
return time.Unix(0, 0), ErrNotFound
} else if err != nil {
return time.Unix(0, 0), err
}
return timestamp, nil
}

// SetLastBatchNumberSeenOnEthereum sets the last batch number that affected
// the roll-up in order to allow the components to know if the state
// is synchronized or not
Expand Down
4 changes: 2 additions & 2 deletions test/config/test.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ Port = 50060
StoreBackend = "PostgreSQL"

[MTClient]
URI = "34.245.104.156:50061"
URI = "zkevm-prover:50061"

[Executor]
URI = "34.245.104.156:50071"
URI = "zkevm-prover:50071"

[BroadcastServer]
Host = "0.0.0.0"
Expand Down