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

Commit

Permalink
feat(rpc): cherry-pick changes in #332
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Jul 26, 2023
1 parent de14cf8 commit aa891b0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rpc

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

Expand All @@ -12,6 +13,10 @@ import (
"github.com/taikoxyz/taiko-client/bindings"
)

var (
errNotArchiveNode = errors.New("error with rpc: node must be archive node")
)

// Client contains all L1/L2 RPC clients that a driver needs.
type Client struct {
// Geth ethclient clients
Expand Down Expand Up @@ -55,6 +60,15 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {
return nil, err
}

isArchive, err := IsArchiveNode(ctx, l1RPC)
if err != nil {
return nil, err
}

if !isArchive {
return nil, errNotArchiveNode
}

taikoL1, err := bindings.NewTaikoL1Client(cfg.TaikoL1Address, l1RPC)
if err != nil {
return nil, err
Expand Down
14 changes: 14 additions & 0 deletions pkg/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
var (
waitReceiptPollingInterval = 3 * time.Second
defaultWaitReceiptTimeout = 1 * time.Minute
zeroAddress = common.HexToAddress("0x0000000000000000000000000000000000000000")
)

// GetProtocolStateVariables gets the protocol states from TaikoL1 contract.
Expand Down Expand Up @@ -245,3 +246,16 @@ func StringToBytes32(str string) [32]byte {

return b
}

func IsArchiveNode(ctx context.Context, client *ethclient.Client) (bool, error) {
_, err := client.BalanceAt(ctx, zeroAddress, big.NewInt(1))
if err != nil {
if strings.Contains(err.Error(), "missing trie node") {
return false, nil
}

return false, err
}

return true, nil
}

0 comments on commit aa891b0

Please sign in to comment.