Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jonastheis committed Nov 26, 2024
1 parent ec9d862 commit 6ef4775
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -61,7 +61,7 @@ func (r *MinimalRecovery) RecoveryNeeded() bool {
if err != nil {
return true
}
if chunk.Index <= defaultRestoredChunkIndex {
if chunk.Index <= defaultFakeRestoredChunkIndex {
return true
}

Expand All @@ -77,7 +77,7 @@ func (r *MinimalRecovery) RecoveryNeeded() bool {
if err != nil {
return true
}
if bundle.Index <= defaultRestoredBundleIndex {
if bundle.Index <= defaultFakeRestoredBundleIndex {
return true
}

Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 1 addition & 3 deletions rollup/internal/controller/relayer/full_recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
49 changes: 15 additions & 34 deletions rollup/internal/orm/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 16 additions & 23 deletions rollup/internal/orm/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 6ef4775

Please sign in to comment.