mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-12 07:28:08 -05:00
Compare commits
1 Commits
develop
...
feat/upgra
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b5fddc7eb |
@@ -2,6 +2,7 @@ package relayer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
@@ -19,7 +20,6 @@ import (
|
||||
"github.com/scroll-tech/da-codec/encoding/codecv4"
|
||||
"github.com/scroll-tech/go-ethereum/accounts/abi"
|
||||
"github.com/scroll-tech/go-ethereum/common"
|
||||
gethTypes "github.com/scroll-tech/go-ethereum/core/types"
|
||||
"github.com/scroll-tech/go-ethereum/crypto"
|
||||
"github.com/scroll-tech/go-ethereum/crypto/kzg4844"
|
||||
"github.com/scroll-tech/go-ethereum/ethclient"
|
||||
@@ -35,7 +35,6 @@ import (
|
||||
"scroll-tech/rollup/internal/config"
|
||||
"scroll-tech/rollup/internal/controller/sender"
|
||||
"scroll-tech/rollup/internal/orm"
|
||||
rutils "scroll-tech/rollup/internal/utils"
|
||||
)
|
||||
|
||||
// Layer2Relayer is responsible for:
|
||||
@@ -176,73 +175,101 @@ func NewLayer2Relayer(ctx context.Context, l2Client *ethclient.Client, db *gorm.
|
||||
}
|
||||
|
||||
func (r *Layer2Relayer) initializeGenesis() error {
|
||||
if count, err := r.batchOrm.GetBatchCount(r.ctx); err != nil {
|
||||
return fmt.Errorf("failed to get batch count: %v", err)
|
||||
} else if count > 0 {
|
||||
log.Info("genesis already imported", "batch count", count)
|
||||
//if count, err := r.batchOrm.GetBatchCount(r.ctx); err != nil {
|
||||
// return fmt.Errorf("failed to get batch count: %v", err)
|
||||
//} else if count > 0 {
|
||||
// log.Info("genesis already imported", "batch count", count)
|
||||
// return nil
|
||||
//}
|
||||
|
||||
latestBatch, err := r.batchOrm.GetLatestBatch(r.ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get latest batch: %v", err)
|
||||
}
|
||||
if latestBatch.Index > 274314 {
|
||||
log.Info("genesis already imported")
|
||||
return nil
|
||||
}
|
||||
|
||||
genesis, err := r.l2Client.HeaderByNumber(r.ctx, big.NewInt(0))
|
||||
//genesis, err := r.l2Client.HeaderByNumber(r.ctx, big.NewInt(0))
|
||||
lastBernoulliBatch, err := r.batchOrm.GetBatchByIndex(r.ctx, 274314 /* last bernoulli batch */)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to retrieve L2 genesis header: %v", err)
|
||||
//return fmt.Errorf("failed to retrieve L2 genesis header: %v", err)
|
||||
log.Error("Failed to fetch pending L2 batches", "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info("retrieved L2 genesis header", "hash", genesis.Hash().String())
|
||||
|
||||
chunk := &encoding.Chunk{
|
||||
Blocks: []*encoding.Block{{
|
||||
Header: genesis,
|
||||
Transactions: nil,
|
||||
WithdrawRoot: common.Hash{},
|
||||
RowConsumption: &gethTypes.RowConsumption{},
|
||||
}},
|
||||
}
|
||||
|
||||
err = r.db.Transaction(func(dbTX *gorm.DB) error {
|
||||
var dbChunk *orm.Chunk
|
||||
dbChunk, err = r.chunkOrm.InsertChunk(r.ctx, chunk, rutils.CodecConfig{Version: encoding.CodecV0}, rutils.ChunkMetrics{}, dbTX)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to insert chunk: %v", err)
|
||||
}
|
||||
|
||||
if err = r.chunkOrm.UpdateProvingStatus(r.ctx, dbChunk.Hash, types.ProvingTaskVerified, dbTX); err != nil {
|
||||
return fmt.Errorf("failed to update genesis chunk proving status: %v", err)
|
||||
}
|
||||
|
||||
batch := &encoding.Batch{
|
||||
Index: 0,
|
||||
TotalL1MessagePoppedBefore: 0,
|
||||
ParentBatchHash: common.Hash{},
|
||||
Chunks: []*encoding.Chunk{chunk},
|
||||
}
|
||||
|
||||
var dbBatch *orm.Batch
|
||||
dbBatch, err = r.batchOrm.InsertBatch(r.ctx, batch, rutils.CodecConfig{Version: encoding.CodecV0}, rutils.BatchMetrics{}, dbTX)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to insert batch: %v", err)
|
||||
}
|
||||
|
||||
if err = r.chunkOrm.UpdateBatchHashInRange(r.ctx, 0, 0, dbBatch.Hash, dbTX); err != nil {
|
||||
return fmt.Errorf("failed to update batch hash for chunks: %v", err)
|
||||
}
|
||||
|
||||
if err = r.batchOrm.UpdateProvingStatus(r.ctx, dbBatch.Hash, types.ProvingTaskVerified, dbTX); err != nil {
|
||||
return fmt.Errorf("failed to update genesis batch proving status: %v", err)
|
||||
}
|
||||
|
||||
if err = r.batchOrm.UpdateRollupStatus(r.ctx, dbBatch.Hash, types.RollupFinalized, dbTX); err != nil {
|
||||
return fmt.Errorf("failed to update genesis batch rollup status: %v", err)
|
||||
}
|
||||
|
||||
// commit genesis batch on L1
|
||||
// note: we do this inside the DB transaction so that we can revert all DB changes if this step fails
|
||||
return r.commitGenesisBatch(dbBatch.Hash, dbBatch.BatchHeader, common.HexToHash(dbBatch.StateRoot))
|
||||
})
|
||||
|
||||
// commit genesis batch on L1
|
||||
// note: we do this inside the DB transaction so that we can revert all DB changes if this step fails
|
||||
err = r.commitGenesisBatch(lastBernoulliBatch.Hash, lastBernoulliBatch.BatchHeader, common.HexToHash(lastBernoulliBatch.StateRoot))
|
||||
if err != nil {
|
||||
return fmt.Errorf("update genesis transaction failed: %v", err)
|
||||
return fmt.Errorf("274314 update genesis transaction failed: %v", err)
|
||||
}
|
||||
log.Info("import genesis transaction successfully batch index: 274314")
|
||||
|
||||
zeroBatchHeader := "0000000000000000000000000000000000000000000000000061a5de00a189b490960523626c576089401f5413e4ca6f5fe5f16004d764ccd00000000000000000000000000000000000000000000000000000000000000000"
|
||||
zeroBatchHeaderBytes, _ := hex.DecodeString(zeroBatchHeader)
|
||||
err = r.commitGenesisBatch("0x5aaeb6101a47fc16866e80d77ffe090b6a7b3cf7d988be981646ab6aedfa2c42", zeroBatchHeaderBytes, common.HexToHash("0x08d535cc60f40af5dd3b31e0998d7567c2d568b224bed2ba26070aeb078d1339"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("0 update genesis transaction failed: %v", err)
|
||||
}
|
||||
log.Info("import genesis transaction successfully batch index 0")
|
||||
|
||||
//log.Info("retrieved L2 genesis header", "hash", genesis.Hash().String())
|
||||
//
|
||||
//chunk := &encoding.Chunk{
|
||||
// Blocks: []*encoding.Block{{
|
||||
// Header: genesis,
|
||||
// Transactions: nil,
|
||||
// WithdrawRoot: common.Hash{},
|
||||
// RowConsumption: &gethTypes.RowConsumption{},
|
||||
// }},
|
||||
//}
|
||||
|
||||
//err = r.db.Transaction(func(dbTX *gorm.DB) error {
|
||||
// var dbChunk *orm.Chunk
|
||||
// dbChunk, err = r.chunkOrm.InsertChunk(r.ctx, chunk, rutils.CodecConfig{Version: encoding.CodecV0}, rutils.ChunkMetrics{}, dbTX)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("failed to insert chunk: %v", err)
|
||||
// }
|
||||
//
|
||||
// if err = r.chunkOrm.UpdateProvingStatus(r.ctx, dbChunk.Hash, types.ProvingTaskVerified, dbTX); err != nil {
|
||||
// return fmt.Errorf("failed to update genesis chunk proving status: %v", err)
|
||||
// }
|
||||
//
|
||||
// batch := &encoding.Batch{
|
||||
// Index: 0,
|
||||
// TotalL1MessagePoppedBefore: 0,
|
||||
// ParentBatchHash: common.Hash{},
|
||||
// Chunks: []*encoding.Chunk{chunk},
|
||||
// }
|
||||
//
|
||||
// var dbBatch *orm.Batch
|
||||
// dbBatch, err = r.batchOrm.InsertBatch(r.ctx, batch, rutils.CodecConfig{Version: encoding.CodecV0}, rutils.BatchMetrics{}, dbTX)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("failed to insert batch: %v", err)
|
||||
// }
|
||||
//
|
||||
// if err = r.chunkOrm.UpdateBatchHashInRange(r.ctx, 0, 0, dbBatch.Hash, dbTX); err != nil {
|
||||
// return fmt.Errorf("failed to update batch hash for chunks: %v", err)
|
||||
// }
|
||||
//
|
||||
// if err = r.batchOrm.UpdateProvingStatus(r.ctx, dbBatch.Hash, types.ProvingTaskVerified, dbTX); err != nil {
|
||||
// return fmt.Errorf("failed to update genesis batch proving status: %v", err)
|
||||
// }
|
||||
//
|
||||
// if err = r.batchOrm.UpdateRollupStatus(r.ctx, dbBatch.Hash, types.RollupFinalized, dbTX); err != nil {
|
||||
// return fmt.Errorf("failed to update genesis batch rollup status: %v", err)
|
||||
// }
|
||||
//
|
||||
// // commit genesis batch on L1
|
||||
// // note: we do this inside the DB transaction so that we can revert all DB changes if this step fails
|
||||
// return r.commitGenesisBatch(dbBatch.Hash, dbBatch.BatchHeader, common.HexToHash(dbBatch.StateRoot))
|
||||
//})
|
||||
|
||||
//if err != nil {
|
||||
// return fmt.Errorf("update genesis transaction failed: %v", err)
|
||||
//}
|
||||
|
||||
log.Info("successfully imported genesis chunk and batch")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user