From aa3d6ec7442d9257f99b0f345aa291a5d023cbba Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Sun, 9 Jul 2023 23:44:28 -0700 Subject: [PATCH] move proverpool --- packages/eventindexer/indexer/filter.go | 75 ++++++++++++------- .../indexer/filter_then_subscribe.go | 10 --- 2 files changed, 46 insertions(+), 39 deletions(-) diff --git a/packages/eventindexer/indexer/filter.go b/packages/eventindexer/indexer/filter.go index d8eef5875d..d0c2d6a4d5 100644 --- a/packages/eventindexer/indexer/filter.go +++ b/packages/eventindexer/indexer/filter.go @@ -21,44 +21,61 @@ func L1FilterFunc( svc *Service, filterOpts *bind.FilterOpts, ) error { - blockProvenEvents, err := svc.taikol1.FilterBlockProven(filterOpts, nil) - if err != nil { - return errors.Wrap(err, "svc.taikol1.FilterBlockProven") - } + if svc.taikol1 != nil { + blockProvenEvents, err := svc.taikol1.FilterBlockProven(filterOpts, nil) + if err != nil { + return errors.Wrap(err, "svc.taikol1.FilterBlockProven") + } - err = svc.saveBlockProvenEvents(ctx, chainID, blockProvenEvents) - if err != nil { - return errors.Wrap(err, "svc.saveBlockProvenEvents") - } + err = svc.saveBlockProvenEvents(ctx, chainID, blockProvenEvents) + if err != nil { + return errors.Wrap(err, "svc.saveBlockProvenEvents") + } - blockProposedEvents, err := svc.taikol1.FilterBlockProposed(filterOpts, nil) - if err != nil { - return errors.Wrap(err, "svc.taikol1.FilterBlockProposed") - } + blockProposedEvents, err := svc.taikol1.FilterBlockProposed(filterOpts, nil) + if err != nil { + return errors.Wrap(err, "svc.taikol1.FilterBlockProposed") + } - err = svc.saveBlockProposedEvents(ctx, chainID, blockProposedEvents) - if err != nil { - return errors.Wrap(err, "svc.saveBlockProposedEvents") - } + err = svc.saveBlockProposedEvents(ctx, chainID, blockProposedEvents) + if err != nil { + return errors.Wrap(err, "svc.saveBlockProposedEvents") + } - blockVerifiedEvents, err := svc.taikol1.FilterBlockVerified(filterOpts, nil) - if err != nil { - return errors.Wrap(err, "svc.taikol1.FilterBlockVerified") - } + blockVerifiedEvents, err := svc.taikol1.FilterBlockVerified(filterOpts, nil) + if err != nil { + return errors.Wrap(err, "svc.taikol1.FilterBlockVerified") + } - err = svc.saveBlockVerifiedEvents(ctx, chainID, blockVerifiedEvents) - if err != nil { - return errors.Wrap(err, "svc.saveBlockVerifiedEvents") + err = svc.saveBlockVerifiedEvents(ctx, chainID, blockVerifiedEvents) + if err != nil { + return errors.Wrap(err, "svc.saveBlockVerifiedEvents") + } } - messagesSent, err := svc.bridge.FilterMessageSent(filterOpts, nil) - if err != nil { - return errors.Wrap(err, "svc.bridge.FilterMessageSent") + if svc.bridge != nil { + messagesSent, err := svc.bridge.FilterMessageSent(filterOpts, nil) + if err != nil { + return errors.Wrap(err, "svc.bridge.FilterMessageSent") + } + + err = svc.saveMessageSentEvents(ctx, chainID, messagesSent) + if err != nil { + return errors.Wrap(err, "svc.saveMessageSentEvents") + } } - err = svc.saveMessageSentEvents(ctx, chainID, messagesSent) - if err != nil { - return errors.Wrap(err, "svc.saveMessageSentEvents") + if svc.proverPool != nil { + slashedEvents, err := svc.proverPool.FilterSlashed(filterOpts, nil) + if err != nil { + return errors.Wrap(err, "svc.proverPool.FilterSlashed") + } + + err = svc.saveSlashedEvents(ctx, chainID, slashedEvents) + if err != nil { + return errors.Wrap(err, "svc.saveSlashedEvents") + } + } return nil diff --git a/packages/eventindexer/indexer/filter_then_subscribe.go b/packages/eventindexer/indexer/filter_then_subscribe.go index fe0331243b..1eb27b8b0e 100644 --- a/packages/eventindexer/indexer/filter_then_subscribe.go +++ b/packages/eventindexer/indexer/filter_then_subscribe.go @@ -73,16 +73,6 @@ func (svc *Service) FilterThenSubscribe( return errors.Wrap(err, "filter") } - slashedEvents, err := svc.proverPool.FilterSlashed(filterOpts, nil) - if err != nil { - return errors.Wrap(err, "svc.proverPool.FilterSlashed") - } - - err = svc.saveSlashedEvents(ctx, chainID, slashedEvents) - if err != nil { - return errors.Wrap(err, "svc.saveSlashedEvents") - } - header, err := svc.ethClient.HeaderByNumber(ctx, big.NewInt(int64(end))) if err != nil { return errors.Wrap(err, "svc.ethClient.HeaderByNumber")