Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

fix(prover): move concurrency guard #318

Merged
merged 3 commits into from
Jul 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,36 +950,43 @@ 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
}

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)
}
}()
Expand Down