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

feat(prover): check proof status before sending the transaction #731

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions prover/proof_submitter/transaction/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package transaction

import (
"context"
"fmt"
"math/big"
"strings"

Expand Down Expand Up @@ -41,6 +42,15 @@ func (s *Sender) Send(
proofWithHeader *producer.ProofWithHeader,
buildTx TxBuilder,
) error {
// Check if the proof has already been submitted.
proofStatus, err := rpc.GetBlockProofStatus(ctx, s.rpc, proofWithHeader.BlockID, proofWithHeader.Opts.ProverAddress)
if err != nil {
return err
}
if proofStatus.IsSubmitted && !proofStatus.Invalid {
return fmt.Errorf("a valid proof for block %d is already submitted", proofWithHeader.BlockID)
}

// Check if this proof is still needed to be submitted.
ok, err := s.validateProof(ctx, proofWithHeader)
if err != nil || !ok {
Expand Down
34 changes: 0 additions & 34 deletions prover/proof_submitter/transaction/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,40 +93,6 @@ func (s *TransactionTestSuite) TestSendTxWithBackoff() {
},
func(*bind.TransactOpts) (*txmgr.TxCandidate, error) { return nil, errors.New("L1_TEST") },
))

s.Nil(s.sender.Send(
context.Background(),
&producer.ProofWithHeader{
Meta: meta,
BlockID: common.Big1,
Header: &types.Header{},
Opts: &producer.ProofRequestOptions{EventL1Hash: l1Head.Hash()},
},
func(*bind.TransactOpts) (*txmgr.TxCandidate, error) {
height, err := s.RPCClient.L1.BlockNumber(context.Background())
s.Nil(err)

var block *types.Block
for {
block, err = s.RPCClient.L1.BlockByNumber(context.Background(), new(big.Int).SetUint64(height))
s.Nil(err)
if block.Transactions().Len() != 0 {
break
}
height--
}

tx := block.Transactions()[0]

return &txmgr.TxCandidate{
TxData: tx.Data(),
Blobs: nil,
To: tx.To(),
GasLimit: tx.Gas(),
Value: tx.Value(),
}, nil
},
))
}

func TestTxSenderTestSuite(t *testing.T) {
Expand Down
Loading