From 35ab7a3966964376100e77b4768c1c7d9a258b3c Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Tue, 4 Jun 2024 15:06:40 +0200 Subject: [PATCH] Set unlimited size of ETH RPC message --- bchain/coins/bsc/bscrpc.go | 12 +----------- bchain/coins/eth/ethrpc.go | 23 ++++++++++++++--------- bchain/coins/polygon/polygonrpc.go | 12 +----------- build/docker/bin/Makefile | 1 - 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/bchain/coins/bsc/bscrpc.go b/bchain/coins/bsc/bscrpc.go index 13690576..383f7eb5 100644 --- a/bchain/coins/bsc/bscrpc.go +++ b/bchain/coins/bsc/bscrpc.go @@ -4,8 +4,6 @@ import ( "context" "encoding/json" - "github.com/ethereum/go-ethereum/ethclient" - "github.com/ethereum/go-ethereum/rpc" "github.com/golang/glog" "github.com/juju/errors" "github.com/trezor/blockbook/bchain" @@ -46,15 +44,7 @@ func NewBNBSmartChainRPC(config json.RawMessage, pushHandler func(bchain.Notific // Initialize bnb smart chain rpc interface func (b *BNBSmartChainRPC) Initialize() error { - b.OpenRPC = func(url string) (bchain.EVMRPCClient, bchain.EVMClient, error) { - r, err := rpc.Dial(url) - if err != nil { - return nil, nil, err - } - rc := ð.EthereumRPCClient{Client: r} - ec := ð.EthereumClient{Client: ethclient.NewClient(r)} - return rc, ec, nil - } + b.OpenRPC = eth.OpenRPC rc, ec, err := b.OpenRPC(b.ChainConfig.RPCURL) if err != nil { diff --git a/bchain/coins/eth/ethrpc.go b/bchain/coins/eth/ethrpc.go index a56b3666..1405ea3b 100644 --- a/bchain/coins/eth/ethrpc.go +++ b/bchain/coins/eth/ethrpc.go @@ -107,17 +107,22 @@ func NewEthereumRPC(config json.RawMessage, pushHandler func(bchain.Notification return s, nil } +// OpenRPC opens RPC connection to ETH backend +var OpenRPC = func(url string) (bchain.EVMRPCClient, bchain.EVMClient, error) { + opts := []rpc.ClientOption{} + opts = append(opts, rpc.WithWebsocketMessageSizeLimit(0)) + r, err := rpc.DialOptions(context.Background(), url, opts...) + if err != nil { + return nil, nil, err + } + rc := &EthereumRPCClient{Client: r} + ec := &EthereumClient{Client: ethclient.NewClient(r)} + return rc, ec, nil +} + // Initialize initializes ethereum rpc interface func (b *EthereumRPC) Initialize() error { - b.OpenRPC = func(url string) (bchain.EVMRPCClient, bchain.EVMClient, error) { - r, err := rpc.Dial(url) - if err != nil { - return nil, nil, err - } - rc := &EthereumRPCClient{Client: r} - ec := &EthereumClient{Client: ethclient.NewClient(r)} - return rc, ec, nil - } + b.OpenRPC = OpenRPC rc, ec, err := b.OpenRPC(b.ChainConfig.RPCURL) if err != nil { diff --git a/bchain/coins/polygon/polygonrpc.go b/bchain/coins/polygon/polygonrpc.go index e628018b..d218caf4 100644 --- a/bchain/coins/polygon/polygonrpc.go +++ b/bchain/coins/polygon/polygonrpc.go @@ -4,8 +4,6 @@ import ( "context" "encoding/json" - "github.com/ethereum/go-ethereum/ethclient" - "github.com/ethereum/go-ethereum/rpc" "github.com/golang/glog" "github.com/juju/errors" "github.com/trezor/blockbook/bchain" @@ -38,15 +36,7 @@ func NewPolygonRPC(config json.RawMessage, pushHandler func(bchain.NotificationT // Initialize polygon rpc interface func (b *PolygonRPC) Initialize() error { - b.OpenRPC = func(url string) (bchain.EVMRPCClient, bchain.EVMClient, error) { - r, err := rpc.Dial(url) - if err != nil { - return nil, nil, err - } - rc := ð.EthereumRPCClient{Client: r} - ec := ð.EthereumClient{Client: ethclient.NewClient(r)} - return rc, ec, nil - } + b.OpenRPC = eth.OpenRPC rc, ec, err := b.OpenRPC(b.ChainConfig.RPCURL) if err != nil { diff --git a/build/docker/bin/Makefile b/build/docker/bin/Makefile index 0e52b18c..3636ddd1 100644 --- a/build/docker/bin/Makefile +++ b/build/docker/bin/Makefile @@ -38,5 +38,4 @@ prepare-sources: mkdir -p $(BLOCKBOOK_BASE) cp -r /src $(BLOCKBOOK_SRC) cd $(BLOCKBOOK_SRC) && go mod download - sed -i 's/wsMessageSizeLimit\ =\ 15\ \*\ 1024\ \*\ 1024/wsMessageSizeLimit = 80 * 1024 * 1024/g' $(GOPATH)/pkg/mod/github.com/ethereum/go-ethereum*/rpc/websocket.go sed -i 's/wsMessageSizeLimit\ =\ 15\ \*\ 1024\ \*\ 1024/wsMessageSizeLimit = 80 * 1024 * 1024/g' $(GOPATH)/pkg/mod/github.com/ava-labs/coreth*/rpc/websocket.go