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

Commit

Permalink
feat(rpc): check if L1 rpc is an archive node (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Jul 26, 2023
1 parent 0ebf121 commit b1aa1d3
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 72 deletions.
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f8415a2f73e8a3cdc354a519b5c5af02e715fbf4
013912fc7b74e9212dcbd374f47cf6b3e22252d6
12 changes: 7 additions & 5 deletions bindings/gen_taiko_l1.go

Large diffs are not rendered by default.

130 changes: 65 additions & 65 deletions bindings/gen_taiko_prover_pool_l1.go

Large diffs are not rendered by default.

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 @@ -57,6 +62,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 @@ -173,3 +174,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
}
2 changes: 1 addition & 1 deletion testutils/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s *ClientTestSuite) SetupTest() {
minStakePerCapacity, err := s.RpcClient.TaikoProverPoolL1.MINSTAKEPERCAPACITY(nil)
s.Nil(err)

capacity, err := s.RpcClient.TaikoProverPoolL1.MAXCAPACITYLOWERBOUND(nil)
capacity, err := s.RpcClient.TaikoProverPoolL1.MINCAPACITY(nil)
s.Nil(err)

amt := new(big.Int).Mul(big.NewInt(int64(minStakePerCapacity)), big.NewInt(int64(capacity)))
Expand Down

0 comments on commit b1aa1d3

Please sign in to comment.