Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(taiko-client): remove useless function and correct erorr handling #17463

Merged
merged 12 commits into from
Jun 4, 2024
8 changes: 6 additions & 2 deletions packages/taiko-client/pkg/rpc/beaconclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,17 @@ func (c *BeaconClient) GetBlobs(ctx context.Context, time uint64) ([]*blob.Sidec
return nil, err
}

var sidecars *blob.SidecarsResponse
resBytes, err := c.Get(ctxWithTimeout, c.BaseURL().Path+fmt.Sprintf(sidecarsRequestURL, slot))
if err != nil {
return nil, err
}

return sidecars.Data, json.Unmarshal(resBytes, &sidecars)
mask-pp marked this conversation as resolved.
Show resolved Hide resolved
var sidecars *blob.SidecarsResponse
if err = json.Unmarshal(resBytes, &sidecars); err != nil {
return nil, err
}

return sidecars.Data, nil
}

// timeToSlot returns the slots of the given timestamp.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package anchortxvalidator

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

Expand Down Expand Up @@ -48,30 +46,16 @@ func (v *AnchorTxValidator) ValidateAnchorTx(tx *types.Transaction) error {
}

method, err := encoding.TaikoL2ABI.MethodById(tx.Data())
if err != nil || method.Name != "anchor" {
return fmt.Errorf("invalid TaikoL2.anchor transaction selector, error: %w", err)
}

return nil
}

// GetAndValidateAnchorTxReceipt gets and validates the `TaikoL2.anchor` transaction's receipt.
func (v *AnchorTxValidator) GetAndValidateAnchorTxReceipt(
ctx context.Context,
tx *types.Transaction,
) (*types.Receipt, error) {
receipt, err := v.rpc.L2.TransactionReceipt(ctx, tx.Hash())
if err != nil {
return nil, fmt.Errorf("failed to get TaikoL2.anchor transaction receipt, error: %w", err)
return fmt.Errorf("failed to get TaikoL2.anchor transaction method: %w", err)
}

if receipt.Status != types.ReceiptStatusSuccessful {
return nil, fmt.Errorf("invalid TaikoL2.anchor transaction receipt status: %d", receipt.Status)
}

if len(receipt.Logs) == 0 {
return nil, errors.New("no event found in TaikoL2.anchor transaction receipt")
if method.Name != "anchor" {
return fmt.Errorf(
"invalid TaikoL2.anchor transaction selector, expect: %s, actual: %s",
"anchor",
method.Name,
)
}

return receipt, nil
return nil
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package anchortxvalidator

import (
"context"
"os"
"testing"

Expand Down Expand Up @@ -64,20 +63,7 @@ func (s *AnchorTxValidatorTestSuite) TestValidateAnchorTx() {

// invalid method selector
tx = types.MustSignNewTx(goldenTouchPriKey, signer, dynamicFeeTxTx)
s.ErrorContains(s.v.ValidateAnchorTx(tx), "invalid TaikoL2.anchor transaction selector")
}

func (s *AnchorTxValidatorTestSuite) TestGetAndValidateAnchorTxReceipt() {
tx := types.NewTransaction(
100,
common.BytesToAddress(testutils.RandomBytes(32)),
common.Big1,
100000,
common.Big1,
[]byte{},
)
_, err := s.v.GetAndValidateAnchorTxReceipt(context.Background(), tx)
s.NotNil(err)
s.ErrorContains(s.v.ValidateAnchorTx(tx), "failed to get TaikoL2.anchor transaction method")
}

func TestAnchorTxValidatorTestSuite(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions packages/taiko-client/prover/event_handler/block_proposed.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

var (
errL1Reorged = errors.New("L1 reorged")
errL1Reorged = errors.New("l1 reorged")
mask-pp marked this conversation as resolved.
Show resolved Hide resolved
proofExpirationDelay = 6 * 12 * time.Second // 6 ethereum blocks
)

Expand Down Expand Up @@ -212,7 +212,7 @@ func (h *BlockProposedEventHandler) checkL1Reorg(
)

return fmt.Errorf(
"L1 block hash mismatch due to L1 reorg: %s != %s",
"l1 block hash mismatch due to L1 reorg: %s != %s",
YoGhurt111 marked this conversation as resolved.
Show resolved Hide resolved
lastL1OriginHeader.Hash(),
e.Meta.L1Hash,
)
Expand Down
Loading