Skip to content

Commit 7a65337

Browse files
committed
validate blocks before committing
1 parent 0b45721 commit 7a65337

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

internal/orchestrator/committer.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Committer struct {
2929
publisher *publisher.Publisher
3030
workMode WorkMode
3131
workModeChan chan WorkMode
32+
validator *Validator
3233
}
3334

3435
type CommitterOption func(*Committer)
@@ -59,6 +60,7 @@ func NewCommitter(rpc rpc.IRPCClient, storage storage.IStorage, opts ...Committe
5960
lastCommittedBlock: commitFromBlock,
6061
publisher: publisher.GetInstance(),
6162
workMode: "",
63+
validator: NewValidator(rpc, storage),
6264
}
6365

6466
for _, opt := range opts {
@@ -210,6 +212,15 @@ func (c *Committer) getSequentialBlockDataToCommit(ctx context.Context) ([]commo
210212
return nil, nil
211213
}
212214

215+
validBlocks, invalidBlocks, err := c.validator.ValidateBlocks(blocksData)
216+
if err != nil {
217+
return nil, err
218+
}
219+
if len(invalidBlocks) > 0 {
220+
// continue with valid blocks only
221+
blocksData = validBlocks
222+
}
223+
213224
// Sort blocks by block number
214225
sort.Slice(blocksData, func(i, j int) bool {
215226
return blocksData[i].Block.Number.Cmp(blocksData[j].Block.Number) < 0

0 commit comments

Comments
 (0)