mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-04-23 03:00:50 -04:00
update state roots
This commit is contained in:
@@ -209,6 +209,18 @@ func (r *Layer2Relayer) initializeGenesis() error {
|
||||
return fmt.Errorf("failed to get disk root, block number: %v, err: %w", endChunk.EndBlockNumber, err)
|
||||
}
|
||||
|
||||
if err = r.batchOrm.UpdateStateRootByHash(r.ctx, startFinalizedBatch.Hash, diskRoot.Hex()); err != nil {
|
||||
return fmt.Errorf("failed to update state root by hash: %v, err: %w", startFinalizedBatch.Hash, err)
|
||||
}
|
||||
|
||||
if err = r.chunkOrm.UpdateStateRootByHash(r.ctx, endChunk.Hash, diskRoot.Hex()); err != nil {
|
||||
return fmt.Errorf("failed to update state root by hash: %v, err: %w", endChunk.Hash, err)
|
||||
}
|
||||
|
||||
if err = r.l2BlockOrm.UpdateStateRootByHash(r.ctx, endChunk.EndBlockHash, diskRoot.Hex()); err != nil {
|
||||
return fmt.Errorf("failed to update state root by hash: %v, err: %w", endChunk.EndBlockHash, err)
|
||||
}
|
||||
|
||||
if err = r.commitGenesisBatch(startFinalizedBatch.Hash, startFinalizedBatch.BatchHeader, diskRoot); err != nil {
|
||||
return fmt.Errorf("commit genesis batch failed: %v", err)
|
||||
}
|
||||
|
||||
@@ -324,6 +324,23 @@ func (o *Batch) InsertBatch(ctx context.Context, batch *encoding.Batch, codecVer
|
||||
return &newBatch, nil
|
||||
}
|
||||
|
||||
// UpdateStateRootByHash updates the StateRoot for a batch identified by its hash.
|
||||
func (o *Batch) UpdateStateRootByHash(ctx context.Context, hash string, stateRoot string) error {
|
||||
updateFields := map[string]interface{}{
|
||||
"state_root": stateRoot,
|
||||
}
|
||||
|
||||
db := o.db.WithContext(ctx)
|
||||
db = db.Model(&Batch{})
|
||||
db = db.Where("hash = ?", hash)
|
||||
|
||||
if err := db.Updates(updateFields).Error; err != nil {
|
||||
return fmt.Errorf("Batch.UpdateStateRootByHash error: %w, batch hash: %v", err, hash)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateL2GasOracleStatusAndOracleTxHash updates the L2 gas oracle status and transaction hash for a batch.
|
||||
func (o *Batch) UpdateL2GasOracleStatusAndOracleTxHash(ctx context.Context, hash string, status types.GasOracleStatus, txHash string) error {
|
||||
updateFields := make(map[string]interface{})
|
||||
|
||||
@@ -255,6 +255,23 @@ func (o *Chunk) InsertChunk(ctx context.Context, chunk *encoding.Chunk, codecVer
|
||||
return &newChunk, nil
|
||||
}
|
||||
|
||||
// UpdateStateRootByHash updates the StateRoot for a chunk identified by its hash.
|
||||
func (o *Chunk) UpdateStateRootByHash(ctx context.Context, hash string, stateRoot string) error {
|
||||
updateFields := map[string]interface{}{
|
||||
"state_root": stateRoot,
|
||||
}
|
||||
|
||||
db := o.db.WithContext(ctx)
|
||||
db = db.Model(&Chunk{})
|
||||
db = db.Where("hash = ?", hash)
|
||||
|
||||
if err := db.Updates(updateFields).Error; err != nil {
|
||||
return fmt.Errorf("Chunk.UpdateStateRootByHash error: %w, batch hash: %v", err, hash)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateProvingStatus updates the proving status of a chunk.
|
||||
func (o *Chunk) UpdateProvingStatus(ctx context.Context, hash string, status types.ProvingStatus, dbTX ...*gorm.DB) error {
|
||||
updateFields := make(map[string]interface{})
|
||||
|
||||
@@ -254,3 +254,20 @@ func (o *L2Block) UpdateChunkHashInRange(ctx context.Context, startIndex uint64,
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateStateRootByHash updates the StateRoot for a chunk identified by its hash.
|
||||
func (o *L2Block) UpdateStateRootByHash(ctx context.Context, hash string, stateRoot string) error {
|
||||
updateFields := map[string]interface{}{
|
||||
"state_root": stateRoot,
|
||||
}
|
||||
|
||||
db := o.db.WithContext(ctx)
|
||||
db = db.Model(&L2Block{})
|
||||
db = db.Where("hash = ?", hash)
|
||||
|
||||
if err := db.Updates(updateFields).Error; err != nil {
|
||||
return fmt.Errorf("L2Block.UpdateStateRootByHash error: %w, batch hash: %v", err, hash)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user