Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update permission less rpc's batch time #3580

Closed
Closed
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
1 change: 1 addition & 0 deletions state/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ type storage interface {
AddL1InfoTreeRecursiveRootToExitRoot(ctx context.Context, exitRoot *L1InfoTreeRecursiveExitRootStorageEntry, dbTx pgx.Tx) error
GetAllL1InfoTreeRecursiveRootEntries(ctx context.Context, dbTx pgx.Tx) ([]L1InfoTreeRecursiveExitRootStorageEntry, error)
GetLatestL1InfoTreeRecursiveRoot(ctx context.Context, maxBlockNumber uint64, dbTx pgx.Tx) (L1InfoTreeRecursiveExitRootStorageEntry, error)
UpdateBatchTimestamp(ctx context.Context, batchNumber uint64, batchTime time.Time, dbTx pgx.Tx) error
storeblobsequences
}

Expand Down
4 changes: 4 additions & 0 deletions state/mocks/mock_storage.go

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

8 changes: 8 additions & 0 deletions state/pgstatestorage/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -1054,3 +1054,11 @@ func (p *PostgresStorage) GetNotCheckedBatches(ctx context.Context, dbTx pgx.Tx)

return batches, nil
}

func (p *PostgresStorage) UpdateBatchTimestamp(ctx context.Context, batchNumber uint64, batchTime time.Time, dbTx pgx.Tx) error {
const updateL2DataSQL = "UPDATE state.batch SET timestamp = $1 WHERE batch_num = $2"

e := p.getExecQuerier(dbTx)
_, err := e.Exec(ctx, updateL2DataSQL, batchTime.UTC(), batchNumber)
return err
}
27 changes: 27 additions & 0 deletions synchronizer/actions/etrog/processor_l1_sequence_batches.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type stateProcessSequenceBatches interface {
AddVirtualBatch(ctx context.Context, virtualBatch *state.VirtualBatch, dbTx pgx.Tx) error
AddTrustedReorg(ctx context.Context, trustedReorg *state.TrustedReorg, dbTx pgx.Tx) error
GetL1InfoTreeDataFromBatchL2Data(ctx context.Context, batchL2Data []byte, dbTx pgx.Tx) (map[uint32]state.L1DataV2, common.Hash, common.Hash, error)
UpdateBatchTimestamp(ctx context.Context, batchNumber uint64, batchTime time.Time, dbTx pgx.Tx) error
}

type syncProcessSequenceBatchesInterface interface {
Expand Down Expand Up @@ -276,6 +277,12 @@ func (p *ProcessorL1SequenceBatchesEtrog) ProcessSequenceBatches(ctx context.Con
}
return err
}

// Update the existing batch with L1's MaxSequenceTimestamp
err = p.updatePermissionLessBatchTimestamp(ctx, batch.BatchNumber, l1BlockTimestamp, dbTx)
if err != nil {
return err
}
}

// Call the check trusted state method to compare trusted and virtual state
Expand Down Expand Up @@ -419,3 +426,23 @@ func (p *ProcessorL1SequenceBatchesEtrog) checkTrustedState(ctx context.Context,
func (p *ProcessorL1SequenceBatchesEtrog) halt(ctx context.Context, err error) {
p.halter.CriticalError(ctx, err)
}

// updatePermissionLessBatchTimestamp updates the batch timestamp for permission less rpc
func (p *ProcessorL1SequenceBatchesEtrog) updatePermissionLessBatchTimestamp(ctx context.Context, batchNumber uint64, batchTime time.Time, dbTx pgx.Tx) error {
if p.sync.IsTrustedSequencer() {
return nil
}

log.Infof("Permission less rpc updates batch timestamp for batch: %v with new timestamp:%v", batchNumber, batchTime)
err := p.state.UpdateBatchTimestamp(ctx, batchNumber, batchTime, dbTx)
if err != nil {
log.Errorf("error update batch timestamp for batch: %v, batchTime:%v, . Error; %v", batchNumber, batchTime, err)
rollbackErr := dbTx.Rollback(ctx)
if rollbackErr != nil {
log.Errorf("error rolling back state. BatchNumber: %d, batchTime:%v, rollbackErr: %v", batchNumber, batchTime, rollbackErr)
return rollbackErr
}
return err
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func TestL1SequenceBatchesTrustedBatchSequencedThatAlreadyExistsHappyPath(t *tes
l1InfoRoot := common.HexToHash(hashExamplesValues[0])
l1Block := newL1Block(mocks, batch, l1InfoRoot)
expectationsPreExecution(t, mocks, ctx, batch, nil)
mocks.Synchronizer.EXPECT().IsTrustedSequencer().Return(false)
executionResponse := newProcessBatchResponseV2(batch)
expectationsForExecution(t, mocks, ctx, l1Block.SequencedBatches[1][0], l1Block.ReceivedAt, executionResponse)
mocks.State.EXPECT().AddAccumulatedInputHash(ctx, executionResponse.NewBatchNum, common.BytesToHash(executionResponse.NewAccInputHash), mocks.DbTx).Return(nil)
Expand All @@ -116,6 +117,7 @@ func TestL1SequenceBatchesPermissionlessBatchSequencedThatAlreadyExistsHappyPath
l1Block := newL1Block(mocks, batch, l1InfoRoot)
expectationsPreExecution(t, mocks, ctx, batch, nil)
executionResponse := newProcessBatchResponseV2(batch)
mocks.Synchronizer.EXPECT().IsTrustedSequencer().Return(false)
expectationsForExecution(t, mocks, ctx, l1Block.SequencedBatches[1][0], l1Block.ReceivedAt, executionResponse)
mocks.State.EXPECT().AddAccumulatedInputHash(ctx, executionResponse.NewBatchNum, common.BytesToHash(executionResponse.NewAccInputHash), mocks.DbTx).Return(nil)
expectationsAddSequencedBatch(t, mocks, ctx, executionResponse)
Expand Down

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

1 change: 1 addition & 0 deletions synchronizer/common/syncinterfaces/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type StateFullInterface interface {
UpdateForkIDBlockNumber(ctx context.Context, forkdID uint64, newBlockNumber uint64, updateMemCache bool, dbTx pgx.Tx) error
GetLastL2BlockNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
GetL2BlockByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*state.L2Block, error)
UpdateBatchTimestamp(ctx context.Context, batchNumber uint64, batchTime time.Time, dbTx pgx.Tx) error
StateBlobSequencerReader
StateBlobSequenceWriter
}