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

Commit

Permalink
feat(bindings): introduce TryParsingCustomErrorFromReceipt (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Apr 24, 2024
1 parent 7d39f21 commit 42af8ee
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 37 deletions.
49 changes: 43 additions & 6 deletions bindings/encoding/custom_error.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,53 @@
package encoding

import (
"context"
"errors"
"strings"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

// BlockHashContractCallerAndTransactionReader represents a contract caller and transaction reader.
type BlockHashContractCallerAndTransactionReader interface {
bind.BlockHashContractCaller
ethereum.TransactionReader
}

// TryParsingCustomErrorFromReceipt tries to parse the custom error from the given receipt.
func TryParsingCustomErrorFromReceipt(
ctx context.Context,
rpc BlockHashContractCallerAndTransactionReader,
from common.Address,
receipt *types.Receipt,
) error {
// Fetch the raw transaction.
tx, _, err := rpc.TransactionByHash(ctx, receipt.TxHash)
if err != nil {
return err
}

// Call the contract at the block hash.
_, err = rpc.CallContractAtHash(ctx, ethereum.CallMsg{
From: from,
To: tx.To(),
Gas: tx.Gas(),
GasPrice: tx.GasPrice(),
GasFeeCap: tx.GasFeeCap(),
GasTipCap: tx.GasTipCap(),
Value: tx.Value(),
Data: tx.Data(),
AccessList: tx.AccessList(),
BlobGasFeeCap: tx.BlobGasFeeCap(),
BlobHashes: tx.BlobHashes(),
}, receipt.BlockHash)

return TryParsingCustomError(err)
}

// TryParsingCustomError tries to checks whether the given error is one of the
// custom errors defined the protocol ABIs, if so, it will return
// the matched custom error, otherwise, it simply returns the original error.
Expand All @@ -28,12 +71,6 @@ func TryParsingCustomError(originalError error) error {
}
}

for _, hookCustomError := range AssignmentHookABI.Errors {
if strings.HasPrefix(hookCustomError.ID.Hex(), errData) {
return errors.New(hookCustomError.Name)
}
}

return originalError
}

Expand Down
2 changes: 1 addition & 1 deletion proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (p *Proposer) ProposeOp(ctx context.Context) error {
log.Error(
"Failed to send TaikoL1.proposeBlock transaction",
"index", i,
"error", encoding.TryParsingCustomError(err),
"error", err,
)
continue
}
Expand Down
54 changes: 26 additions & 28 deletions prover/proof_submitter/proof_contester.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,33 @@ func (c *ProofContester) SubmitContest(
return err
}

return encoding.TryParsingCustomError(
c.sender.Send(
ctx,
&proofProducer.ProofWithHeader{
BlockID: blockID,
Meta: meta,
Header: header,
Proof: []byte{},
Opts: &proofProducer.ProofRequestOptions{
EventL1Hash: l1HeaderProposedIn.Hash(),
StateRoot: header.Root,
},
Tier: tier,
return c.sender.Send(
ctx,
&proofProducer.ProofWithHeader{
BlockID: blockID,
Meta: meta,
Header: header,
Proof: []byte{},
Opts: &proofProducer.ProofRequestOptions{
EventL1Hash: l1HeaderProposedIn.Hash(),
StateRoot: header.Root,
},
c.txBuilder.Build(
blockID,
meta,
&bindings.TaikoDataTransition{
ParentHash: header.ParentHash,
BlockHash: header.Hash(),
StateRoot: header.Root,
Graffiti: c.graffiti,
},
&bindings.TaikoDataTierProof{
Tier: transition.Tier,
Data: []byte{},
},
false,
),
Tier: tier,
},
c.txBuilder.Build(
blockID,
meta,
&bindings.TaikoDataTransition{
ParentHash: header.ParentHash,
BlockHash: header.Hash(),
StateRoot: header.Root,
Graffiti: c.graffiti,
},
&bindings.TaikoDataTierProof{
Tier: transition.Tier,
Data: []byte{},
},
false,
),
)
}
4 changes: 2 additions & 2 deletions prover/proof_submitter/proof_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (s *ProofSubmitter) SubmitProof(
}

// Build the TaikoL1.proveBlock transaction and send it to the L1 node.
if err = encoding.TryParsingCustomError(s.sender.Send(
if err = s.sender.Send(
ctx,
proofWithHeader,
s.txBuilder.Build(
Expand All @@ -172,7 +172,7 @@ func (s *ProofSubmitter) SubmitProof(
},
proofWithHeader.Tier == encoding.TierGuardianID,
),
)); err != nil {
); err != nil {
if err.Error() == transaction.ErrUnretryableSubmission.Error() {
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions prover/proof_submitter/transaction/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"

"github.com/taikoxyz/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-client/internal/metrics"
"github.com/taikoxyz/taiko-client/pkg/rpc"
producer "github.com/taikoxyz/taiko-client/prover/proof_producer"
Expand Down Expand Up @@ -75,6 +76,7 @@ func (s *Sender) Send(
"blockID", proofWithHeader.BlockID,
"tier", proofWithHeader.Tier,
"txHash", receipt.TxHash,
"error", encoding.TryParsingCustomErrorFromReceipt(ctx, s.rpc.L1, s.txmgr.From(), receipt),
)
metrics.ProverSubmissionRevertedCounter.Add(1)
return ErrUnretryableSubmission
Expand Down

0 comments on commit 42af8ee

Please sign in to comment.