@@ -29,6 +29,7 @@ type Committer struct {
29
29
publisher * publisher.Publisher
30
30
workMode WorkMode
31
31
workModeChan chan WorkMode
32
+ validator * Validator
32
33
}
33
34
34
35
type CommitterOption func (* Committer )
@@ -39,6 +40,12 @@ func WithCommitterWorkModeChan(ch chan WorkMode) CommitterOption {
39
40
}
40
41
}
41
42
43
+ func WithValidator (validator * Validator ) CommitterOption {
44
+ return func (c * Committer ) {
45
+ c .validator = validator
46
+ }
47
+ }
48
+
42
49
func NewCommitter (rpc rpc.IRPCClient , storage storage.IStorage , opts ... CommitterOption ) * Committer {
43
50
triggerInterval := config .Cfg .Committer .Interval
44
51
if triggerInterval == 0 {
@@ -210,6 +217,18 @@ func (c *Committer) getSequentialBlockDataToCommit(ctx context.Context) ([]commo
210
217
return nil , nil
211
218
}
212
219
220
+ if c .validator != nil {
221
+ validBlocks , invalidBlocks , err := c .validator .ValidateBlocks (blocksData )
222
+ if err != nil {
223
+ return nil , err
224
+ }
225
+ if len (invalidBlocks ) > 0 {
226
+ log .Warn ().Msgf ("Found %d invalid blocks in commit batch, continuing with %d valid blocks" , len (invalidBlocks ), len (validBlocks ))
227
+ // continue with valid blocks only
228
+ blocksData = validBlocks
229
+ }
230
+ }
231
+
213
232
// Sort blocks by block number
214
233
sort .Slice (blocksData , func (i , j int ) bool {
215
234
return blocksData [i ].Block .Number .Cmp (blocksData [j ].Block .Number ) < 0
0 commit comments