Skip to content

Commit

Permalink
fix: fetch proofs that failed on server correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Sep 4, 2024
1 parent 584b41c commit 6663fac
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion contracts/zkconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"startingBlockNumber": 16795981,
"startingBlockNumber": 16833525,
"l2RollupNode": "",
"submissionInterval": 150,
"l2BlockTime": 2,
Expand Down
20 changes: 20 additions & 0 deletions proposer/op/proposer/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,26 @@ func (db *ProofDB) GetLatestEndBlock() (uint64, error) {
return uint64(maxEnd.EndBlock), nil
}

// If a proof failed to be sent to the prover network, it's status will be set to FAILED, but the prover request ID will be empty.
// This function returns all such proofs.
func (db *ProofDB) GetProofsFailedOnServer() ([]*ent.ProofRequest, error) {
proofs, err := db.client.ProofRequest.Query().
Where(
proofrequest.StatusEQ(proofrequest.StatusFAILED),
proofrequest.ProverRequestIDEQ(""),
).
All(context.Background())

if err != nil {
if ent.IsNotFound(err) {
return nil, nil
}
return nil, fmt.Errorf("failed to query failed proof: %w", err)
}

return proofs, nil
}

// Get all pending proofs with a status of requested and a prover ID that is not empty.
func (db *ProofDB) GetAllPendingProofs() ([]*ent.ProofRequest, error) {
proofs, err := db.client.ProofRequest.Query().
Expand Down
36 changes: 19 additions & 17 deletions proposer/op/proposer/prove.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import (
"github.com/succinctlabs/op-succinct-go/proposer/db/ent/proofrequest"
)

// 1) Retry all failed proofs
// Process all of the pending proofs.
func (l *L2OutputSubmitter) ProcessPendingProofs() error {
failedReqs, err := l.db.GetAllProofsWithStatus(proofrequest.StatusFAILED)
// Retrieve all proofs that failed without reaching the prover network (specifically, proofs that failed with no proof ID).
failedReqs, err := l.db.GetProofsFailedOnServer()
if err != nil {
return fmt.Errorf("failed to get proofs failed on server: %w", err)
}
Expand All @@ -30,7 +31,8 @@ func (l *L2OutputSubmitter) ProcessPendingProofs() error {
}

// Get all pending proofs with a status of requested and a prover ID that is not empty.
// TODO: There should be a proofrequest status where the prover ID is not empty.
// TODO: There should be a separate proofrequest status for proofs that failed before reaching the prover network,
// and those that failed after reaching the prover network.
reqs, err := l.db.GetAllPendingProofs()
if err != nil {
return err
Expand Down Expand Up @@ -83,22 +85,22 @@ func (l *L2OutputSubmitter) RetryRequest(req *ent.ProofRequest) error {
l.Log.Error("failed to add new proof request", "err")
return err
}
}
} else {
// If a SPAN proof failed, assume it was too big and the SP1 runtime OOM'd.
// Therefore, create two new entries for the original proof split in half.
l.Log.Info("span proof failed, splitting in half to retry", "req", req)
tmpStart := req.StartBlock
tmpEnd := tmpStart + ((req.EndBlock - tmpStart) / 2)
for i := 0; i < 2; i++ {
err := l.db.NewEntryWithReqAddedTimestamp("SPAN", tmpStart, tmpEnd, 0)
if err != nil {
l.Log.Error("failed to add new proof request", "err", err)
return err
}

// If a SPAN proof failed, assume it was too big and the SP1 runtime OOM'd.
// Therefore, create two new entries for the original proof split in half.
l.Log.Info("span proof failed, splitting in half to retry", "req", req)
tmpStart := req.StartBlock
tmpEnd := tmpStart + ((req.EndBlock - tmpStart) / 2)
for i := 0; i < 2; i++ {
err := l.db.NewEntryWithReqAddedTimestamp("SPAN", tmpStart, tmpEnd, 0)
if err != nil {
l.Log.Error("failed to add new proof request", "err", err)
return err
tmpStart = tmpEnd + 1
tmpEnd = req.EndBlock
}

tmpStart = tmpEnd + 1
tmpEnd = req.EndBlock
}

return nil
Expand Down

0 comments on commit 6663fac

Please sign in to comment.