mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-12 07:28:08 -05:00
Compare commits
1 Commits
develop
...
a-script-t
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27435fa380 |
@@ -75,6 +75,18 @@ func (*Batch) TableName() string {
|
||||
return "batch"
|
||||
}
|
||||
|
||||
// GetBatchHashByIndex retrieves the hash of the batch given its index.
|
||||
// used for the script.
|
||||
func (o *Batch) GetBatchHashByIndex(ctx context.Context, index uint64) (string, error) {
|
||||
db := o.db.WithContext(ctx)
|
||||
var batch Batch
|
||||
err := db.Select("hash").Where("index = ?", index).First(&batch).Error
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Batch.GetBatchHashByIndex error: %w, index: %v", err, index)
|
||||
}
|
||||
return batch.Hash, nil
|
||||
}
|
||||
|
||||
// GetUnassignedBatch retrieves unassigned batch based on the specified limit.
|
||||
// The returned batch are sorted in ascending order by their index.
|
||||
func (o *Batch) GetUnassignedBatch(ctx context.Context, startChunkIndex, endChunkIndex uint64, maxActiveAttempts, maxTotalAttempts uint8) (*Batch, error) {
|
||||
|
||||
81
coordinator/internal/script/batch_task_69767.json
Normal file
81
coordinator/internal/script/batch_task_69767.json
Normal file
File diff suppressed because one or more lines are too long
206
coordinator/internal/script/batch_task_69768.json
Normal file
206
coordinator/internal/script/batch_task_69768.json
Normal file
File diff suppressed because one or more lines are too long
256
coordinator/internal/script/batch_task_69769.json
Normal file
256
coordinator/internal/script/batch_task_69769.json
Normal file
File diff suppressed because one or more lines are too long
256
coordinator/internal/script/batch_task_69770.json
Normal file
256
coordinator/internal/script/batch_task_69770.json
Normal file
File diff suppressed because one or more lines are too long
231
coordinator/internal/script/batch_task_69771.json
Normal file
231
coordinator/internal/script/batch_task_69771.json
Normal file
File diff suppressed because one or more lines are too long
256
coordinator/internal/script/batch_task_69772.json
Normal file
256
coordinator/internal/script/batch_task_69772.json
Normal file
File diff suppressed because one or more lines are too long
256
coordinator/internal/script/batch_task_69773.json
Normal file
256
coordinator/internal/script/batch_task_69773.json
Normal file
File diff suppressed because one or more lines are too long
256
coordinator/internal/script/batch_task_69774.json
Normal file
256
coordinator/internal/script/batch_task_69774.json
Normal file
File diff suppressed because one or more lines are too long
231
coordinator/internal/script/batch_task_69775.json
Normal file
231
coordinator/internal/script/batch_task_69775.json
Normal file
File diff suppressed because one or more lines are too long
231
coordinator/internal/script/batch_task_69776.json
Normal file
231
coordinator/internal/script/batch_task_69776.json
Normal file
File diff suppressed because one or more lines are too long
121
coordinator/internal/script/main.go
Normal file
121
coordinator/internal/script/main.go
Normal file
@@ -0,0 +1,121 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/scroll-tech/go-ethereum/common"
|
||||
"github.com/scroll-tech/go-ethereum/log"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"scroll-tech/common/database"
|
||||
"scroll-tech/common/types/message"
|
||||
"scroll-tech/coordinator/internal/orm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.LogfmtFormat()))
|
||||
glogger.Verbosity(log.LvlInfo)
|
||||
log.Root().SetHandler(glogger)
|
||||
|
||||
if len(os.Args) < 2 {
|
||||
log.Crit("no batch index range provided")
|
||||
return
|
||||
}
|
||||
|
||||
indexRange := os.Args[1]
|
||||
indices := strings.Split(indexRange, "-")
|
||||
if len(indices) != 2 {
|
||||
log.Crit("invalid batch index range format. Use start-end", "providedRange", indexRange)
|
||||
return
|
||||
}
|
||||
|
||||
startIndex, err := strconv.Atoi(indices[0])
|
||||
endIndex, err2 := strconv.Atoi(indices[1])
|
||||
if err != nil || err2 != nil || startIndex > endIndex {
|
||||
log.Crit("invalid batch index range", "start", indices[0], "end", indices[1], "err", err, "err2", err2)
|
||||
return
|
||||
}
|
||||
|
||||
db, err := database.InitDB(&database.Config{
|
||||
DriverName: "postgres",
|
||||
DSN: os.Getenv("DB_DSN"),
|
||||
MaxOpenNum: 200,
|
||||
MaxIdleNum: 20,
|
||||
})
|
||||
if err != nil {
|
||||
log.Crit("failed to init db", "err", err)
|
||||
}
|
||||
defer func() {
|
||||
if deferErr := database.CloseDB(db); deferErr != nil {
|
||||
log.Error("failed to close db", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
for i := startIndex; i <= endIndex; i++ {
|
||||
batchIndex := uint64(i)
|
||||
resultBytes, err := getBatchTask(db, batchIndex)
|
||||
if err != nil {
|
||||
log.Crit("failed to get batch task", "batchIndex", batchIndex, "err", err)
|
||||
continue
|
||||
}
|
||||
|
||||
outputFilename := fmt.Sprintf("batch_task_%d.json", batchIndex)
|
||||
if err = os.WriteFile(outputFilename, resultBytes, 0644); err != nil {
|
||||
log.Crit("failed to write output file", "filename", outputFilename, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getBatchTask(db *gorm.DB, batchIndex uint64) ([]byte, error) {
|
||||
batchHash, err := orm.NewBatch(db).GetBatchHashByIndex(context.Background(), batchIndex)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to get batch hash by index: %d err: %w ", batchIndex, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chunks, err := orm.NewChunk(db).GetChunksByBatchHash(context.Background(), batchHash)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to get chunk proofs for batch task id: %s err: %w ", batchHash, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var chunkProofs []*message.ChunkProof
|
||||
var chunkInfos []*message.ChunkInfo
|
||||
for _, chunk := range chunks {
|
||||
var proof message.ChunkProof
|
||||
if encodeErr := json.Unmarshal(chunk.Proof, &proof); encodeErr != nil {
|
||||
return nil, fmt.Errorf("Chunk.GetProofsByBatchHash unmarshal proof error: %w, batch hash: %v, chunk hash: %v", encodeErr, batchHash, chunk.Hash)
|
||||
}
|
||||
chunkProofs = append(chunkProofs, &proof)
|
||||
|
||||
chunkInfo := message.ChunkInfo{
|
||||
ChainID: 534351, // sepolia
|
||||
PrevStateRoot: common.HexToHash(chunk.ParentChunkStateRoot),
|
||||
PostStateRoot: common.HexToHash(chunk.StateRoot),
|
||||
WithdrawRoot: common.HexToHash(chunk.WithdrawRoot),
|
||||
DataHash: common.HexToHash(chunk.Hash),
|
||||
IsPadding: false,
|
||||
}
|
||||
if proof.ChunkInfo != nil {
|
||||
chunkInfo.TxBytes = proof.ChunkInfo.TxBytes
|
||||
}
|
||||
chunkInfos = append(chunkInfos, &chunkInfo)
|
||||
}
|
||||
|
||||
taskDetail := message.BatchTaskDetail{
|
||||
ChunkInfos: chunkInfos,
|
||||
ChunkProofs: chunkProofs,
|
||||
}
|
||||
|
||||
chunkProofsBytes, err := json.MarshalIndent(taskDetail, "", " ")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal chunk proofs, taskID:%s err:%w", batchHash, err)
|
||||
}
|
||||
|
||||
return chunkProofsBytes, nil
|
||||
}
|
||||
Reference in New Issue
Block a user