From b1317789dec44de9a4b7d692515e5560eb2b6da5 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Wed, 5 Sep 2018 16:27:34 +0200 Subject: [PATCH] Handle unsupported newHeads subscription in Ethereum Classic --- bchain/coins/eth/ethrpc.go | 34 +++++++++++++++-------------- configs/coins/ethereum-classic.json | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/bchain/coins/eth/ethrpc.go b/bchain/coins/eth/ethrpc.go index 1285c354..6a8f5240 100644 --- a/bchain/coins/eth/ethrpc.go +++ b/bchain/coins/eth/ethrpc.go @@ -41,9 +41,7 @@ type EthereumRPC struct { client *ethclient.Client rpc *rpc.Client timeout time.Duration - rpcURL string Parser *EthereumParser - CoinName string Testnet bool Network string Mempool *bchain.NonUTXOMempool @@ -143,21 +141,25 @@ func (b *EthereumRPC) Initialize() error { } glog.Info("rpc: block chain ", b.Network) - // subscriptions - if err = b.subscribe(func() (*rpc.ClientSubscription, error) { - // invalidate the previous subscription - it is either the first one or there was an error - b.newBlockSubscription = nil - ctx, cancel := context.WithTimeout(context.Background(), b.timeout) - defer cancel() - sub, err := b.rpc.EthSubscribe(ctx, b.chanNewBlock, "newHeads") - if err != nil { - return nil, errors.Annotatef(err, "EthSubscribe newHeads") + if b.ChainConfig.CoinName == "Ethereum Classic" { + glog.Info(b.ChainConfig.CoinName, " does not support subscription to newHeads") + } else { + // subscriptions + if err = b.subscribe(func() (*rpc.ClientSubscription, error) { + // invalidate the previous subscription - it is either the first one or there was an error + b.newBlockSubscription = nil + ctx, cancel := context.WithTimeout(context.Background(), b.timeout) + defer cancel() + sub, err := b.rpc.EthSubscribe(ctx, b.chanNewBlock, "newHeads") + if err != nil { + return nil, errors.Annotatef(err, "EthSubscribe newHeads") + } + b.newBlockSubscription = sub + glog.Info("Subscribed to newHeads") + return sub, nil + }); err != nil { + return err } - b.newBlockSubscription = sub - glog.Info("Subscribed to newHeads") - return sub, nil - }); err != nil { - return err } if err = b.subscribe(func() (*rpc.ClientSubscription, error) { // invalidate the previous subscription - it is either the first one or there was an error diff --git a/configs/coins/ethereum-classic.json b/configs/coins/ethereum-classic.json index e800da46..f7e49b56 100644 --- a/configs/coins/ethereum-classic.json +++ b/configs/coins/ethereum-classic.json @@ -40,7 +40,7 @@ "internal_binding_template": ":{{.Ports.BlockbookInternal}}", "public_binding_template": ":{{.Ports.BlockbookPublic}}", "explorer_url": "https://gastracker.io/", - "additional_params": "", + "additional_params": "-resyncindexperiod=4441", "block_chain": { "parse": true, "mempool_workers": 8,