Skip to content

Commit f9abc3f

Browse files
author
colinlyguo
committed
update block hashes
1 parent d2e6185 commit f9abc3f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

coordinator/internal/logic/provertask/chunk_prover_task.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/prometheus/client_golang/prometheus"
1111
"github.com/prometheus/client_golang/prometheus/promauto"
1212
"github.com/scroll-tech/da-codec/encoding"
13+
"github.com/scroll-tech/go-ethereum/common"
1314
"github.com/scroll-tech/go-ethereum/log"
1415
"github.com/scroll-tech/go-ethereum/params"
1516
"gorm.io/gorm"
@@ -196,15 +197,30 @@ func (cp *ChunkProverTask) hardForkName(ctx *gin.Context, chunkTask *orm.Chunk)
196197
}
197198

198199
func (cp *ChunkProverTask) formatProverTask(ctx context.Context, task *orm.ProverTask, hardForkName string) (*coordinatorType.GetTaskSchema, error) {
199-
// Get block hashes.
200-
blockHashes, dbErr := cp.blockOrm.GetL2BlockHashesByChunkHash(ctx, task.TaskID)
201-
if dbErr != nil || len(blockHashes) == 0 {
200+
dbChunk, err := cp.chunkOrm.GetChunkByHash(ctx, task.TaskID)
201+
if err != nil {
202+
return nil, fmt.Errorf("failed to fetch chunk by hash:%s err:%w", task.TaskID, err)
203+
}
204+
205+
blocks, dbErr := cp.blockOrm.GetL2BlocksInRange(ctx, dbChunk.StartBlockNumber+1, dbChunk.EndBlockNumber+1)
206+
if dbErr != nil || len(blocks) == 0 {
202207
return nil, fmt.Errorf("failed to fetch block hashes of a chunk, chunk hash:%s err:%w", task.TaskID, dbErr)
203208
}
204209

210+
if len(blocks) != int(dbChunk.EndBlockNumber-dbChunk.StartBlockNumber+1) {
211+
return nil, fmt.Errorf("failed to fetch all block hashes of a chunk, chunk hash:%s, expected block number:%d, actual block number:%d",
212+
task.TaskID, dbChunk.EndBlockNumber-dbChunk.StartBlockNumber+1, len(blocks))
213+
}
214+
215+
var blockHashes []common.Hash
216+
for _, block := range blocks {
217+
blockHashes = append(blockHashes, block.Header.Hash())
218+
}
219+
205220
taskDetail := message.ChunkTaskDetail{
206221
BlockHashes: blockHashes,
207222
}
223+
208224
blockHashesBytes, err := json.Marshal(taskDetail)
209225
if err != nil {
210226
return nil, fmt.Errorf("failed to marshal block hashes hash:%s, err:%w", task.TaskID, err)

0 commit comments

Comments
 (0)