From af29c9503def11c373c16555c020307348c5cff6 Mon Sep 17 00:00:00 2001 From: jeff <113397187+cyberhorsey@users.noreply.github.com> Date: Fri, 14 Jul 2023 11:20:35 -0700 Subject: [PATCH] fix(prover): move concurrency guard (#318) --- prover/prover.go | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/prover/prover.go b/prover/prover.go index 780f4b9f8..b971f4d11 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -950,6 +950,8 @@ func (p *Prover) requestProofForBlockId(blockId *big.Int, l1Height *big.Int) err }) p.currentBlocksBeingProvenMutex.Unlock() + p.proposeConcurrencyGuard <- struct{}{} + if err := p.validProofSubmitter.RequestProof(ctx, event); err != nil { return err } @@ -957,29 +959,34 @@ func (p *Prover) requestProofForBlockId(blockId *big.Int, l1Height *big.Int) err return nil } - p.proposeConcurrencyGuard <- struct{}{} - - go func() { + handleBlockProposedEvent := func() error { defer func() { <-p.proposeConcurrencyGuard }() + iter, err := eventIterator.NewBlockProposedIterator(p.ctx, &eventIterator.BlockProposedIteratorConfig{ + Client: p.rpc.L1, + TaikoL1: p.rpc.TaikoL1, + StartHeight: l1Height, + EndHeight: new(big.Int).Add(l1Height, common.Big1), + OnBlockProposedEvent: onBlockProposed, + FilterQuery: []*big.Int{blockId}, + }) + if err != nil { + return err + } + + return iter.Iter() + } + + go func() { if err := backoff.Retry( func() error { - iter, err := eventIterator.NewBlockProposedIterator(p.ctx, &eventIterator.BlockProposedIteratorConfig{ - Client: p.rpc.L1, - TaikoL1: p.rpc.TaikoL1, - StartHeight: l1Height, - EndHeight: new(big.Int).Add(l1Height, common.Big1), - OnBlockProposedEvent: onBlockProposed, - FilterQuery: []*big.Int{blockId}, - }) - if err != nil { - return err - } - - return iter.Iter() + return handleBlockProposedEvent() }, backoff.WithMaxRetries(backoff.NewConstantBackOff(p.cfg.BackOffRetryInterval), p.cfg.BackOffMaxRetrys), ); err != nil { + p.currentBlocksBeingProvenMutex.Lock() + defer p.currentBlocksBeingProvenMutex.Unlock() + delete(p.currentBlocksBeingProven, blockId.Uint64()) log.Error("Request proof with a given block ID", "blockID", blockId, "error", err) } }()