@@ -29,6 +29,7 @@ type Committer struct {
2929 publisher * publisher.Publisher
3030 workMode WorkMode
3131 workModeChan chan WorkMode
32+ validator * Validator
3233}
3334
3435type CommitterOption func (* Committer )
@@ -39,6 +40,12 @@ func WithCommitterWorkModeChan(ch chan WorkMode) CommitterOption {
3940 }
4041}
4142
43+ func WithValidator (validator * Validator ) CommitterOption {
44+ return func (c * Committer ) {
45+ c .validator = validator
46+ }
47+ }
48+
4249func NewCommitter (rpc rpc.IRPCClient , storage storage.IStorage , opts ... CommitterOption ) * Committer {
4350 triggerInterval := config .Cfg .Committer .Interval
4451 if triggerInterval == 0 {
@@ -210,6 +217,18 @@ func (c *Committer) getSequentialBlockDataToCommit(ctx context.Context) ([]commo
210217 return nil , nil
211218 }
212219
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+
213232 // Sort blocks by block number
214233 sort .Slice (blocksData , func (i , j int ) bool {
215234 return blocksData [i ].Block .Number .Cmp (blocksData [j ].Block .Number ) < 0
0 commit comments