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

Commit

Permalink
feat(prover): improve proof submission delay calculation (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored May 29, 2023
1 parent f64a762 commit 7cc5d54
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
13 changes: 4 additions & 9 deletions driver/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-client/metrics"
"github.com/taikoxyz/taiko-client/pkg/rpc"
)
Expand Down Expand Up @@ -167,17 +168,11 @@ func (s *State) startSubscriptions(ctx context.Context) {
case e := <-s.blockProposedCh:
s.setHeadBlockID(e.Id)
case e := <-s.blockProvenCh:
if e.BlockHash != s.BlockDeadendHash {
log.Info("✅ Valid block proven", "blockID", e.Id, "hash", common.Hash(e.BlockHash), "prover", e.Prover)
} else {
log.Info("❎ Invalid block proven", "blockID", e.Id, "prover", e.Prover)
if e.Prover != encoding.SystemProverAddress && e.Prover != encoding.OracleProverAddress {
log.Info("✅ Block proven", "blockID", e.Id, "hash", common.Hash(e.BlockHash), "prover", e.Prover)
}
case e := <-s.blockVerifiedCh:
if e.BlockHash != s.BlockDeadendHash {
log.Info("📈 Valid block verified", "blockID", e.Id, "hash", common.Hash(e.BlockHash))
} else {
log.Info("🗑 Invalid block verified", "blockID", e.Id)
}
log.Info("📈 Block verified", "blockID", e.Id, "hash", common.Hash(e.BlockHash))
case e := <-s.crossChainSynced:
// Verify the protocol synced block, check if it exists in
// L2 execution engine.
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)
}
}

0 comments on commit 7cc5d54

Please sign in to comment.