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

Commit

Permalink
feat(pkg): cherry-pick changes in #334
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Jul 27, 2023
1 parent aa891b0 commit 5ffd0bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 13 additions & 6 deletions pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package rpc
import (
"context"
"errors"
"fmt"
"math/big"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethclient/gethclient"
Expand Down Expand Up @@ -60,30 +62,35 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {
return nil, err
}

isArchive, err := IsArchiveNode(ctx, l1RPC)
taikoL1, err := bindings.NewTaikoL1Client(cfg.TaikoL1Address, l1RPC)
if err != nil {
return nil, err
}

if !isArchive {
return nil, errNotArchiveNode
l2RPC, err := DialClientWithBackoff(ctx, cfg.L2Endpoint, cfg.RetryInterval)
if err != nil {
return nil, err
}

taikoL1, err := bindings.NewTaikoL1Client(cfg.TaikoL1Address, l1RPC)
taikoL2, err := bindings.NewTaikoL2Client(cfg.TaikoL2Address, l2RPC)
if err != nil {
return nil, err
}

l2RPC, err := DialClientWithBackoff(ctx, cfg.L2Endpoint, cfg.RetryInterval)
stateVars, err := taikoL1.GetStateVariables(&bind.CallOpts{Context: ctx})
if err != nil {
return nil, err
}

taikoL2, err := bindings.NewTaikoL2Client(cfg.TaikoL2Address, l2RPC)
isArchive, err := IsArchiveNode(ctx, l1RPC, stateVars.GenesisHeight)
if err != nil {
return nil, err
}

if !isArchive {
return nil, fmt.Errorf("error with RPC endpoint: node (%s) must be archive node", cfg.L1Endpoint)
}

l1RawRPC, err := rpc.Dial(cfg.L1Endpoint)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ 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))
func IsArchiveNode(ctx context.Context, client *ethclient.Client, l2GenesisHeight uint64) (bool, error) {
_, err := client.BalanceAt(ctx, zeroAddress, new(big.Int).SetUint64(l2GenesisHeight))
if err != nil {
if strings.Contains(err.Error(), "missing trie node") {
return false, nil
Expand Down

0 comments on commit 5ffd0bb

Please sign in to comment.