diff --git a/rollup/internal/controller/permissionless_batches/minimal_recovery.go b/rollup/internal/controller/permissionless_batches/minimal_recovery.go index 550927813..71f33b681 100644 --- a/rollup/internal/controller/permissionless_batches/minimal_recovery.go +++ b/rollup/internal/controller/permissionless_batches/minimal_recovery.go @@ -19,10 +19,10 @@ import ( ) const ( - // defaultRestoredChunkIndex is the default index of the last restored fake chunk. It is used to be able to generate new chunks pretending that we have already processed some chunks. - defaultRestoredChunkIndex uint64 = 1337 - // defaultRestoredBundleIndex is the default index of the last restored fake bundle. It is used to be able to generate new bundles pretending that we have already processed some bundles. - defaultRestoredBundleIndex uint64 = 1 + // defaultFakeRestoredChunkIndex is the default index of the last restored fake chunk. It is used to be able to generate new chunks pretending that we have already processed some chunks. + defaultFakeRestoredChunkIndex uint64 = 1337 + // defaultFakeRestoredBundleIndex is the default index of the last restored fake bundle. It is used to be able to generate new bundles pretending that we have already processed some bundles. + defaultFakeRestoredBundleIndex uint64 = 1 ) type MinimalRecovery struct { @@ -61,7 +61,7 @@ func (r *MinimalRecovery) RecoveryNeeded() bool { if err != nil { return true } - if chunk.Index <= defaultRestoredChunkIndex { + if chunk.Index <= defaultFakeRestoredChunkIndex { return true } @@ -77,7 +77,7 @@ func (r *MinimalRecovery) RecoveryNeeded() bool { if err != nil { return true } - if bundle.Index <= defaultRestoredBundleIndex { + if bundle.Index <= defaultFakeRestoredBundleIndex { return true } @@ -273,14 +273,14 @@ func (r *MinimalRecovery) restoreMinimalPreviousState() (*orm.Chunk, *orm.Batch, log.Info("L1 messages count after latest finalized batch", "batch", batchCommitEvent.BatchIndex(), "count", l1MessagesCount) // 5. Insert minimal state to DB. - chunk, err := r.chunkORM.InsertChunkRaw(r.ctx, defaultRestoredChunkIndex, codec.Version(), lastChunk, l1MessagesCount) + chunk, err := r.chunkORM.InsertPermissionlessChunk(r.ctx, defaultFakeRestoredChunkIndex, codec.Version(), lastChunk, l1MessagesCount) if err != nil { return nil, nil, nil, fmt.Errorf("failed to insert chunk raw: %w", err) } log.Info("Inserted last finalized chunk to DB", "chunk", chunk.Index, "hash", chunk.Hash, "StartBlockNumber", chunk.StartBlockNumber, "EndBlockNumber", chunk.EndBlockNumber, "TotalL1MessagesPoppedBefore", chunk.TotalL1MessagesPoppedBefore) - batch, err := r.batchORM.InsertBatchRaw(r.ctx, batchCommitEvent.BatchIndex(), batchCommitEvent.BatchHash(), codec.Version(), chunk) + batch, err := r.batchORM.InsertPermissionlessBatch(r.ctx, batchCommitEvent.BatchIndex(), batchCommitEvent.BatchHash(), codec.Version(), chunk) if err != nil { return nil, nil, nil, fmt.Errorf("failed to insert batch raw: %w", err) } diff --git a/rollup/internal/controller/relayer/full_recovery.go b/rollup/internal/controller/relayer/full_recovery.go index 84c004ec3..c74c65be3 100644 --- a/rollup/internal/controller/relayer/full_recovery.go +++ b/rollup/internal/controller/relayer/full_recovery.go @@ -61,7 +61,7 @@ func NewFullRecovery(ctx context.Context, cfg *config.Config, genesis *core.Gene // The DB state should be clean: the latest batch in the DB should be finalized on L1. This function will // restore all batches between the latest finalized batch in the DB and the latest finalized batch on L1. func (f *FullRecovery) RestoreFullPreviousState() error { - log.Info("Restoring full previous state with", "L1 block height", f.cfg.RecoveryConfig.L1BlockHeight, "latest finalized batch", f.cfg.RecoveryConfig.LatestFinalizedBatch) + log.Info("Restoring full previous state") // 1. Get latest finalized batch stored in DB latestDBBatch, err := f.batchORM.GetLatestBatch(f.ctx) @@ -204,8 +204,6 @@ func (f *FullRecovery) RestoreFullPreviousState() error { if err != nil { return fmt.Errorf("failed to insert bundle in DB transaction: %w", err) } - - fmt.Println("bundle", len(bundle), bundle[0].commit.BatchIndex()) } return nil diff --git a/rollup/internal/orm/batch.go b/rollup/internal/orm/batch.go index 81b594e4e..0bfc22b2c 100644 --- a/rollup/internal/orm/batch.go +++ b/rollup/internal/orm/batch.go @@ -326,48 +326,29 @@ func (o *Batch) InsertBatch(ctx context.Context, batch *encoding.Batch, codecVer return &newBatch, nil } -func (o *Batch) InsertBatchRaw(ctx context.Context, batchIndex *big.Int, batchHash common.Hash, codecVersion encoding.CodecVersion, chunk *Chunk) (*Batch, error) { +func (o *Batch) InsertPermissionlessBatch(ctx context.Context, batchIndex *big.Int, batchHash common.Hash, codecVersion encoding.CodecVersion, chunk *Chunk) (*Batch, error) { now := time.Now() newBatch := &Batch{ - Index: batchIndex.Uint64(), - Hash: batchHash.Hex(), - DataHash: "", - StartChunkIndex: chunk.Index, - StartChunkHash: chunk.Hash, - EndChunkIndex: chunk.Index, - EndChunkHash: chunk.Hash, - StateRoot: "", - WithdrawRoot: "", - ParentBatchHash: "", - BatchHeader: []byte{1, 2, 3}, - CodecVersion: int16(codecVersion), - EnableCompress: false, - BlobBytes: nil, - ChunkProofsStatus: 0, - ProvingStatus: int16(types.ProvingTaskVerified), - Proof: nil, - ProverAssignedAt: nil, - ProvedAt: &now, - ProofTimeSec: 0, - RollupStatus: int16(types.RollupFinalized), - CommitTxHash: "", - CommittedAt: nil, - FinalizeTxHash: "", - FinalizedAt: &now, - OracleStatus: 0, - OracleTxHash: "", - BlobDataProof: nil, - BlobSize: 0, - BundleHash: "", - TotalL1CommitGas: 0, - TotalL1CommitCalldataSize: 0, + Index: batchIndex.Uint64(), + Hash: batchHash.Hex(), + StartChunkIndex: chunk.Index, + StartChunkHash: chunk.Hash, + EndChunkIndex: chunk.Index, + EndChunkHash: chunk.Hash, + BatchHeader: []byte{1, 2, 3}, + CodecVersion: int16(codecVersion), + EnableCompress: false, + ProvingStatus: int16(types.ProvingTaskVerified), + ProvedAt: &now, + RollupStatus: int16(types.RollupFinalized), + FinalizedAt: &now, } db := o.db.WithContext(ctx) db = db.Model(&Batch{}) if err := db.Create(newBatch).Error; err != nil { - return nil, fmt.Errorf("Batch.InsertBatchRaw error: %w", err) + return nil, fmt.Errorf("Batch.InsertPermissionlessBatch error: %w", err) } return newBatch, nil diff --git a/rollup/internal/orm/chunk.go b/rollup/internal/orm/chunk.go index 020b26998..32f549b11 100644 --- a/rollup/internal/orm/chunk.go +++ b/rollup/internal/orm/chunk.go @@ -256,7 +256,7 @@ func (o *Chunk) InsertChunk(ctx context.Context, chunk *encoding.Chunk, codecVer return &newChunk, nil } -func (o *Chunk) InsertChunkRaw(ctx context.Context, index uint64, codecVersion encoding.CodecVersion, chunk *encoding.DAChunkRawTx, totalL1MessagePoppedBefore uint64) (*Chunk, error) { +func (o *Chunk) InsertPermissionlessChunk(ctx context.Context, index uint64, codecVersion encoding.CodecVersion, chunk *encoding.DAChunkRawTx, totalL1MessagePoppedBefore uint64) (*Chunk, error) { // Create some unique identifier. It is not really used for anything except in DB. var chunkBytes []byte for _, block := range chunk.Blocks { @@ -268,28 +268,21 @@ func (o *Chunk) InsertChunkRaw(ctx context.Context, index uint64, codecVersion e numBlocks := len(chunk.Blocks) emptyHash := common.Hash{}.Hex() newChunk := &Chunk{ - Index: index, - Hash: hash.Hex(), - StartBlockNumber: chunk.Blocks[0].Number(), - StartBlockHash: emptyHash, - EndBlockNumber: chunk.Blocks[numBlocks-1].Number(), - EndBlockHash: emptyHash, - TotalL2TxGas: 0, - TotalL2TxNum: 0, - TotalL1CommitCalldataSize: 0, - TotalL1CommitGas: 0, - StartBlockTime: chunk.Blocks[0].Timestamp(), - TotalL1MessagesPoppedBefore: totalL1MessagePoppedBefore, - TotalL1MessagesPoppedInChunk: 0, - ParentChunkHash: emptyHash, - StateRoot: emptyHash, - ParentChunkStateRoot: emptyHash, - WithdrawRoot: emptyHash, - CodecVersion: int16(codecVersion), - EnableCompress: false, - ProvingStatus: int16(types.ProvingTaskVerified), - CrcMax: 0, - BlobSize: 0, + Index: index, + Hash: hash.Hex(), + StartBlockNumber: chunk.Blocks[0].Number(), + StartBlockHash: emptyHash, + EndBlockNumber: chunk.Blocks[numBlocks-1].Number(), + EndBlockHash: emptyHash, + StartBlockTime: chunk.Blocks[0].Timestamp(), + TotalL1MessagesPoppedBefore: totalL1MessagePoppedBefore, + ParentChunkHash: emptyHash, + StateRoot: emptyHash, + ParentChunkStateRoot: emptyHash, + WithdrawRoot: emptyHash, + CodecVersion: int16(codecVersion), + EnableCompress: false, + ProvingStatus: int16(types.ProvingTaskVerified), } db := o.db.WithContext(ctx)