diff --git a/pkg/rpc/client.go b/pkg/rpc/client.go index 9dc32747f..fef3aa98b 100644 --- a/pkg/rpc/client.go +++ b/pkg/rpc/client.go @@ -2,6 +2,7 @@ package rpc import ( "context" + "errors" "math/big" "time" @@ -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 @@ -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 diff --git a/pkg/rpc/utils.go b/pkg/rpc/utils.go index 575ae83ca..5782e10e0 100644 --- a/pkg/rpc/utils.go +++ b/pkg/rpc/utils.go @@ -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. @@ -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 +}