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

Commit

Permalink
feat(pkg): improve archive node check (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Jul 27, 2023
1 parent 8d92b7a commit c6cd1b0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
30 changes: 16 additions & 14 deletions pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ 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"
"github.com/ethereum/go-ethereum/rpc"
"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 @@ -62,15 +59,6 @@ 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 All @@ -94,6 +82,20 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {
return nil, err
}

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

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
2 changes: 2 additions & 0 deletions pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func (c *Client) GetPoolContent(
blockMaxGasLimit uint32,
maxBytesPerTxList uint64,
locals []common.Address,
maxTransactions uint64,
) ([]types.Transactions, error) {
var localsArg []string
for _, local := range locals {
Expand All @@ -232,6 +233,7 @@ func (c *Client) GetPoolContent(
maxBytesPerTxList,
minTxGasLimit,
localsArg,
maxTransactions,
)

return result, err
Expand Down
6 changes: 3 additions & 3 deletions pkg/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ 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 {
// IsArchiveNode checks if the given node is an archive node.
func IsArchiveNode(ctx context.Context, client *ethclient.Client, l2GenesisHeight uint64) (bool, error) {
if _, err := client.BalanceAt(ctx, zeroAddress, new(big.Int).SetUint64(l2GenesisHeight)); err != nil {
if strings.Contains(err.Error(), "missing trie node") {
return false, nil
}
Expand Down
1 change: 1 addition & 0 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func (p *Proposer) ProposeOp(ctx context.Context) error {
p.protocolConfigs.BlockMaxGasLimit,
p.protocolConfigs.BlockMaxTxListBytes,
p.locals,
p.maxProposedTxListsPerEpoch,
)
if err != nil {
return fmt.Errorf("failed to fetch transaction pool content: %w", err)
Expand Down

0 comments on commit c6cd1b0

Please sign in to comment.