Skip to content

Commit

Permalink
sort proofs by unrequested first
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Oct 9, 2024
1 parent 1689f4c commit d8d6357
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions proposer/op/proposer/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,13 @@ func (db *ProofDB) GetAllProofsWithStatus(status proofrequest.Status) ([]*ent.Pr
}

func (db *ProofDB) GetNextUnrequestedProof() (*ent.ProofRequest, error) {
// First, try to get an AGG type proof
// Get the unrequested AGG proof with the lowest start block.
aggProof, err := db.client.ProofRequest.Query().
Where(
proofrequest.StatusEQ(proofrequest.StatusUNREQ),
proofrequest.TypeEQ(proofrequest.TypeAGG),
).
Order(ent.Asc(proofrequest.FieldRequestAddedTime)).
Order(ent.Asc(proofrequest.FieldStartBlock)).
First(context.Background())

if err == nil {
Expand All @@ -322,13 +322,13 @@ func (db *ProofDB) GetNextUnrequestedProof() (*ent.ProofRequest, error) {
return nil, fmt.Errorf("failed to query AGG unrequested proof: %w", err)
}

// If we're here, it means no AGG proof was found. Let's try SPAN proof.
// If there's no AGG proof available, get the unrequested SPAN proof with the lowest start block.
spanProof, err := db.client.ProofRequest.Query().
Where(
proofrequest.StatusEQ(proofrequest.StatusUNREQ),
proofrequest.TypeEQ(proofrequest.TypeSPAN),
).
Order(ent.Asc(proofrequest.FieldRequestAddedTime)).
Order(ent.Asc(proofrequest.FieldStartBlock)).
First(context.Background())

if err != nil {
Expand All @@ -339,7 +339,7 @@ func (db *ProofDB) GetNextUnrequestedProof() (*ent.ProofRequest, error) {
return nil, fmt.Errorf("failed to query SPAN unrequested proof: %w", err)
}

// We found a SPAN proof
// Return the SPAN proof
return spanProof, nil
}

Expand Down

0 comments on commit d8d6357

Please sign in to comment.