Skip to content

Commit

Permalink
handle busy error
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniRamirezM committed Aug 13, 2024
1 parent f762b8f commit fc67cd9
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ const (
mockedLocalExitRoot = "0x17c04c3760510b48c6012742c540a81aba4bca2f78b9d14bfd2f123e2e53ea3e"
)

var (
busyError = errors.New("witness server is busy")
)

type finalProofMsg struct {
proverName string
proverID string
Expand Down Expand Up @@ -195,22 +199,26 @@ func (a *Aggregator) retrieveWitness() {
var success bool
for {
dbBatch := <-a.witnessRetrievalChan
inner:
for !success {
var err error
// Get Witness
witness, err := getWitness(dbBatch.Batch.BatchNumber, a.cfg.WitnessURL, a.cfg.UseFullWitness)
dbBatch.Witness, err = getWitness(dbBatch.Batch.BatchNumber, a.cfg.WitnessURL, a.cfg.UseFullWitness)
if err != nil {
log.Errorf("Failed to get witness for batch %d, err: %v", dbBatch.Batch.BatchNumber, err)
if err == busyError {
log.Warnf("Witness server is busy, retrying in %v", a.cfg.RetryTime.Duration)
} else {
log.Errorf("Failed to get witness for batch %d, err: %v", dbBatch.Batch.BatchNumber, err)
}
time.Sleep(a.cfg.RetryTime.Duration)
continue
continue inner
}

dbBatch.Witness = witness

err = a.state.AddBatch(a.ctx, &dbBatch, nil)
if err != nil {
log.Errorf("Error adding batch: %v", err)
time.Sleep(a.cfg.RetryTime.Duration)
continue
continue inner
}
success = true
}
Expand Down Expand Up @@ -1626,6 +1634,9 @@ func getWitness(batchNumber uint64, URL string, fullWitness bool) ([]byte, error

// Check if the response is an error
if response.Error != nil {
if response.Error.Message == "busy" {
return nil, busyError
}
return nil, fmt.Errorf("error from witness for batch %d: %v", batchNumber, response.Error)
}

Expand Down

0 comments on commit fc67cd9

Please sign in to comment.