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 5 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
2 changes: 1 addition & 1 deletion prover/proof_producer/zkevm_cmd_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,6 @@ func (p *ZkevmCmdProducer) outputToCalldata(output *ProverCmdOutput) []byte {
// Right now, it is just a stub that does nothing, because it is not possible to cnacel the proof
// with the current zkevm software.
func (p *ZkevmCmdProducer) Cancel(ctx context.Context, blockID *big.Int) error {
log.Info("Cancel proof generation for block ", "blockId", blockID)
log.Info("Cancel proof generation for block", "blockId", blockID)
return nil
}
2 changes: 1 addition & 1 deletion prover/proof_producer/zkevm_rpcd_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,6 @@ func (p *ZkevmRpcdProducer) requestProof(opts *ProofRequestOptions) (*RpcdOutput
// Right now, it is just a stub that does nothing, because it is not possible to cnacel the proof
// with the current zkevm software.
func (p *ZkevmRpcdProducer) Cancel(ctx context.Context, blockID *big.Int) error {
log.Info("Cancel proof generation for block ", "blockId", blockID)
log.Info("Cancel proof generation for block", "blockId", blockID)
return nil
}
36 changes: 26 additions & 10 deletions prover/proof_submitter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ var (
// is retryable.
func isSubmitProofTxErrorRetryable(err error, blockID *big.Int) bool {
if strings.HasPrefix(err.Error(), "L1_NOT_SPECIAL_PROVER") ||
!strings.HasPrefix(err.Error(), "L1_") ||
errors.Is(err, errNeedWaiting) {
!strings.HasPrefix(err.Error(), "L1_") {
return true
}

Expand Down Expand Up @@ -72,7 +71,11 @@ func sendTxWithBackoff(
expectedReward uint64,
sendTxFunc func() (*types.Transaction, error),
) error {
var isUnretryableError bool
var (
isUnretryableError bool
proposedTime = time.Unix(int64(proposedAt), 0)
)

if err := backoff.Retry(func() error {
if ctx.Err() != nil {
return nil
Expand All @@ -91,21 +94,34 @@ 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",
"blockID", blockID,
"delay", targetDelay,
"expectedReward", expectedReward,
"needWaiting", reward < expectedReward,
"blockFee", stateVar.BlockFee,
"proofTimeTarget", stateVar.ProofTimeTarget,
"proposedTime", proposedTime,
"timeToWait", time.Until(proposedTime.Add(time.Duration(targetDelay)*time.Second)),
)

if reward < expectedReward {
if time.Now().Before(proposedTime.Add(time.Duration(targetDelay) * time.Second)) {
return errNeedWaiting
}
}
Expand Down
1 change: 0 additions & 1 deletion prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,5 @@ func (p *Prover) cancelProof(ctx context.Context, blockID uint64) {
if cancel, ok := p.currentBlocksBeingProven[blockID]; ok {
cancel()
delete(p.currentBlocksBeingProven, blockID)
log.Info("Cancelled proof for ", "blockID", blockID)
}
}