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

feat(prover): improve proof submission delay calculation #249

Merged
merged 9 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "Push docker image to GCR"

on:
push:
branches: [main]
branches: [main,improve-prover-wait-time-calculation]
tags:
- "v*"

Expand Down
30 changes: 22 additions & 8 deletions prover/proof_submitter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ func sendTxWithBackoff(
expectedReward uint64,
sendTxFunc func() (*types.Transaction, error),
) error {
var isUnretryableError bool
var (
isUnretryableError bool
startAt time.Time = time.Now()
)
if err := backoff.Retry(func() error {
if ctx.Err() != nil {
return nil
Expand All @@ -91,21 +94,32 @@ func sendTxWithBackoff(
}

if needNewProof {
proofTime := uint64(time.Now().Unix()) - (proposedAt)
reward, err := cli.TaikoL1.GetProofReward(nil, proofTime)
stateVar, err := cli.TaikoL1.GetStateVariables(nil)
if err != nil {
log.Warn("Failed to get proof reward", "blockID", blockID, "proofTime", proofTime, "error", err)
log.Warn("Failed to get protocol state variables", "blockID", blockID, "error", err)
return err
}

targetDelay := stateVar.ProofTimeTarget * 4
if stateVar.BlockFee != 0 {
targetDelay = expectedReward / stateVar.BlockFee * stateVar.ProofTimeTarget
if targetDelay < stateVar.ProofTimeTarget/4 {
targetDelay = stateVar.ProofTimeTarget / 4
} else if targetDelay > stateVar.ProofTimeTarget*4 {
targetDelay = stateVar.ProofTimeTarget * 4
}
}

log.Info(
"Current proof reward",
"currentReward", reward,
"Target delay",
"delay", targetDelay,
"expectedReward", expectedReward,
"needWaiting", reward < expectedReward,
"blockFee", stateVar.BlockFee,
"proofTimeTarget", stateVar.ProofTimeTarget,
"startAt", startAt,
)

if reward < expectedReward {
if time.Now().Before(startAt.Add(time.Duration(targetDelay) * time.Second)) {
return errNeedWaiting
}
}
Expand Down