Skip to content

Commit bcb2463

Browse files
author
colinlyguo
committed
update block number
1 parent b116ab5 commit bcb2463

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

rollup/internal/controller/relayer/l2_relayer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ func (r *Layer2Relayer) initializeGenesis() error {
217217
return fmt.Errorf("failed to update state root by hash: %v, err: %w", endChunk.Hash, err)
218218
}
219219

220-
if err = r.l2BlockOrm.UpdateStateRootByHash(r.ctx, endChunk.EndBlockHash, diskRoot.Hex()); err != nil {
221-
return fmt.Errorf("failed to update state root by hash: %v, err: %w", endChunk.EndBlockHash, err)
220+
if err = r.l2BlockOrm.UpdateStateRootByNumber(r.ctx, endChunk.EndBlockNumber, diskRoot.Hex()); err != nil {
221+
return fmt.Errorf("failed to update state root by number: %v, err: %w", endChunk.EndBlockNumber, err)
222222
}
223223

224224
if err = r.commitGenesisBatch(startFinalizedBatch.Hash, startFinalizedBatch.BatchHeader, diskRoot); err != nil {

rollup/internal/orm/l2_block.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,18 @@ func (o *L2Block) UpdateChunkHashInRange(ctx context.Context, startIndex uint64,
255255
return nil
256256
}
257257

258-
// UpdateStateRootByHash updates the StateRoot for a chunk identified by its hash.
259-
func (o *L2Block) UpdateStateRootByHash(ctx context.Context, hash string, stateRoot string) error {
258+
// UpdateStateRootByNumber updates the StateRoot for a chunk identified by its number.
259+
func (o *L2Block) UpdateStateRootByNumber(ctx context.Context, number uint64, stateRoot string) error {
260260
updateFields := map[string]interface{}{
261261
"state_root": stateRoot,
262262
}
263263

264264
db := o.db.WithContext(ctx)
265265
db = db.Model(&L2Block{})
266-
db = db.Where("hash = ?", hash)
266+
db = db.Where("number = ?", number)
267267

268268
if err := db.Updates(updateFields).Error; err != nil {
269-
return fmt.Errorf("L2Block.UpdateStateRootByHash error: %w, block hash: %v", err, hash)
269+
return fmt.Errorf("L2Block.UpdateStateRootByNumber error: %w, block number: %v", err, number)
270270
}
271271

272272
return nil

0 commit comments

Comments
 (0)