Compare commits

...

5 Commits

Author SHA1 Message Date
georgehao
793983cc98 add log 2024-07-17 16:37:50 +08:00
georgehao
eec19faab6 fix 2024-07-17 16:13:12 +08:00
georgehao
f530448e65 mock the first genesis batch 2024-07-16 15:21:19 +08:00
georgehao
deeafc93e7 Merge branch 'feat/upgrade4' of github.com:scroll-tech/scroll into feat/upgrade4_mock 2024-07-12 11:45:17 +08:00
georgehao
fc47cefc8d upgrad4-test 2024-07-12 11:19:24 +08:00
2 changed files with 15 additions and 64 deletions

View File

@@ -119,7 +119,7 @@ func action(ctx *cli.Context) error {
go utils.Loop(subCtx, 2*time.Second, l2relayer.ProcessPendingBatches)
go utils.Loop(subCtx, 15*time.Second, l2relayer.ProcessCommittedBatches)
go utils.Loop(subCtx, 15*time.Second, l2relayer.ProcessPendingBundles)
go utils.Loop(subCtx, 15*time.Second, l2relayer.ProcessPendingBundles)

View File

@@ -18,7 +18,6 @@ import (
"github.com/scroll-tech/da-codec/encoding/codecv3"
"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"
@@ -34,7 +33,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:
@@ -175,70 +173,15 @@ 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)
return nil
}
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)
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, 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, 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)
}
@@ -255,6 +198,8 @@ func (r *Layer2Relayer) commitGenesisBatch(batchHash string, batchHeader []byte,
return fmt.Errorf("failed to pack importGenesisBatch with batch header: %v and state root: %v. error: %v", common.Bytes2Hex(batchHeader), stateRoot, packErr)
}
log.Info("calldata", "calldata", calldata)
// submit genesis batch to L1 rollup contract
txHash, err := r.commitSender.SendTransaction(batchHash, &r.cfg.RollupContractAddress, calldata, nil, 0)
if err != nil {
@@ -518,6 +463,12 @@ func (r *Layer2Relayer) ProcessPendingBundles() {
}
}
if bundle.EndBatchIndex < 274315 {
if err := r.finalizeBundle(bundle, false); err != nil {
log.Error("Failed to finalize timeout bundle without proof", "index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex, "err", err)
}
}
case types.ProvingTaskVerified:
log.Info("Start to roll up zk proof", "hash", bundle.Hash)
r.metrics.rollupL2RelayerProcessPendingBundlesFinalizedTotal.Inc()