From f49e801a26dcce58f2ef83d6b874de2e7e103cd0 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 29 May 2023 19:07:02 +0800 Subject: [PATCH 1/9] feat(prover): improve proof submission delay calculation --- prover/proof_submitter/util.go | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/prover/proof_submitter/util.go b/prover/proof_submitter/util.go index 5b4243104..c9e1f71ef 100644 --- a/prover/proof_submitter/util.go +++ b/prover/proof_submitter/util.go @@ -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 @@ -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 } } From 39c3090c2067bc3d5a64329ed237b94c0d04bb7a Mon Sep 17 00:00:00 2001 From: David Date: Mon, 29 May 2023 19:22:38 +0800 Subject: [PATCH 2/9] chore: update workflow --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1b1491c56..2a0d9cd98 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main] + branches: [main,improve-prover-wait-time-calculation] tags: - "v*" From ed1686e5339c4a2f531f2af5e6b109ff7c6f9f25 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 29 May 2023 19:22:56 +0800 Subject: [PATCH 3/9] chore: update workflow --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 2a0d9cd98..1b1491c56 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main,improve-prover-wait-time-calculation] + branches: [main] tags: - "v*" From 9287795da144c47f5c1c1b34d7cfb552034c99c5 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 29 May 2023 19:52:34 +0800 Subject: [PATCH 4/9] feat: update logs --- prover/proof_submitter/util.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/prover/proof_submitter/util.go b/prover/proof_submitter/util.go index c9e1f71ef..1dd8203cd 100644 --- a/prover/proof_submitter/util.go +++ b/prover/proof_submitter/util.go @@ -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 } @@ -112,11 +111,13 @@ func sendTxWithBackoff( log.Info( "Target delay", + "blockID", blockID, "delay", targetDelay, "expectedReward", expectedReward, "blockFee", stateVar.BlockFee, "proofTimeTarget", stateVar.ProofTimeTarget, "startAt", startAt, + "timeToWait", time.Until(startAt.Add(time.Duration(targetDelay)*time.Second)), ) if time.Now().Before(startAt.Add(time.Duration(targetDelay) * time.Second)) { From 7003cc20e454ae78ec82b177df43c8a7adb15e2e Mon Sep 17 00:00:00 2001 From: David Date: Tue, 30 May 2023 01:05:48 +0800 Subject: [PATCH 5/9] feat: update logs --- .github/workflows/docker.yml | 2 +- prover/proof_producer/zkevm_cmd_producer.go | 2 +- prover/proof_producer/zkevm_rpcd_producer.go | 2 +- prover/proof_submitter/util.go | 9 +++++---- prover/prover.go | 1 - 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1b1491c56..2a0d9cd98 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main] + branches: [main,improve-prover-wait-time-calculation] tags: - "v*" diff --git a/prover/proof_producer/zkevm_cmd_producer.go b/prover/proof_producer/zkevm_cmd_producer.go index 130a85a4c..dc8348aee 100644 --- a/prover/proof_producer/zkevm_cmd_producer.go +++ b/prover/proof_producer/zkevm_cmd_producer.go @@ -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 } diff --git a/prover/proof_producer/zkevm_rpcd_producer.go b/prover/proof_producer/zkevm_rpcd_producer.go index 9678288a2..7140b92ee 100644 --- a/prover/proof_producer/zkevm_rpcd_producer.go +++ b/prover/proof_producer/zkevm_rpcd_producer.go @@ -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 } diff --git a/prover/proof_submitter/util.go b/prover/proof_submitter/util.go index 1dd8203cd..0c558289b 100644 --- a/prover/proof_submitter/util.go +++ b/prover/proof_submitter/util.go @@ -73,8 +73,9 @@ func sendTxWithBackoff( ) error { var ( isUnretryableError bool - startAt time.Time = time.Now() + proposedTime = time.Unix(int64(proposedAt), 0) ) + if err := backoff.Retry(func() error { if ctx.Err() != nil { return nil @@ -116,11 +117,11 @@ func sendTxWithBackoff( "expectedReward", expectedReward, "blockFee", stateVar.BlockFee, "proofTimeTarget", stateVar.ProofTimeTarget, - "startAt", startAt, - "timeToWait", time.Until(startAt.Add(time.Duration(targetDelay)*time.Second)), + "proposedTime", proposedTime, + "timeToWait", time.Until(proposedTime.Add(time.Duration(targetDelay)*time.Second)), ) - if time.Now().Before(startAt.Add(time.Duration(targetDelay) * time.Second)) { + if time.Now().Before(proposedTime.Add(time.Duration(targetDelay) * time.Second)) { return errNeedWaiting } } diff --git a/prover/prover.go b/prover/prover.go index 5fb4a69e4..91616cc94 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -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) } } From 5457ac6d1e118776ad12bf871617f0cf22413931 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 30 May 2023 01:05:56 +0800 Subject: [PATCH 6/9] feat: update logs --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 2a0d9cd98..1b1491c56 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main,improve-prover-wait-time-calculation] + branches: [main] tags: - "v*" From 878b0dd8bcb9a112b1dfce7165fc5cc50be878b0 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 30 May 2023 01:31:54 +0800 Subject: [PATCH 7/9] feat: update logs --- driver/state/state.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/driver/state/state.go b/driver/state/state.go index 2e789bc33..d6deea238 100644 --- a/driver/state/state.go +++ b/driver/state/state.go @@ -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" ) @@ -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. From b6343fcdf3ba6a3cc63b49b79019518ad568fa7e Mon Sep 17 00:00:00 2001 From: David Date: Tue, 30 May 2023 01:41:16 +0800 Subject: [PATCH 8/9] feat: update logs --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1b1491c56..2a0d9cd98 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main] + branches: [main,improve-prover-wait-time-calculation] tags: - "v*" From 6133b2cda566e880051b3e9b7fdee43b88db622f Mon Sep 17 00:00:00 2001 From: David Date: Tue, 30 May 2023 01:41:49 +0800 Subject: [PATCH 9/9] chore: update workflows --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 2a0d9cd98..1b1491c56 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: "Push docker image to GCR" on: push: - branches: [main,improve-prover-wait-time-calculation] + branches: [main] tags: - "v*"