From ead7fd1df5f5ad18f15388bbe08f36175e4e62e7 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 28 Sep 2023 13:55:06 +0800 Subject: [PATCH] feat(prover): optimize oracle proof submission --- pkg/rpc/utils.go | 14 ++++++++++++++ prover/prover.go | 24 +++++++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/pkg/rpc/utils.go b/pkg/rpc/utils.go index fe33a240d..a8145e1e8 100644 --- a/pkg/rpc/utils.go +++ b/pkg/rpc/utils.go @@ -166,6 +166,20 @@ func NeedNewProof( return true, nil } + l1Origin, err := cli.WaitL1Origin(ctxWithTimeout, id) + if err != nil { + return false, err + } + + if l1Origin.L2BlockHash != transition.BlockHash { + log.Info( + "Different blockhash detected, try submitting a proof", + "local", common.BytesToHash(l1Origin.L2BlockHash[:]), + "protocol", common.BytesToHash(transition.BlockHash[:]), + ) + return true, nil + } + if proverAddress == transition.Prover { log.Info("📬 Block's proof has already been submitted by current prover", "blockID", id) return false, nil diff --git a/prover/prover.go b/prover/prover.go index 4c9b2fe99..1ed725a6a 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -460,20 +460,18 @@ func (p *Prover) onBlockProposed( } // Check whether the block's proof is still needed. - if !p.cfg.OracleProver { - needNewProof, err := rpc.NeedNewProof( - p.ctx, - p.rpc, - event.BlockId, - p.proverAddress, - ) - if err != nil { - return fmt.Errorf("failed to check whether the L2 block needs a new proof: %w", err) - } + needNewProof, err := rpc.NeedNewProof( + p.ctx, + p.rpc, + event.BlockId, + p.proverAddress, + ) + if err != nil { + return fmt.Errorf("failed to check whether the L2 block needs a new proof: %w", err) + } - if !needNewProof { - return nil - } + if !needNewProof { + return nil } // Check if the current prover has seen this block ID before, there was probably