Handle unsupported newHeads subscription in Ethereum Classic

This commit is contained in:
Martin Boehm 2018-09-05 16:27:34 +02:00
parent b8dede857c
commit b1317789de
2 changed files with 19 additions and 17 deletions

View File

@ -41,9 +41,7 @@ type EthereumRPC struct {
client *ethclient.Client client *ethclient.Client
rpc *rpc.Client rpc *rpc.Client
timeout time.Duration timeout time.Duration
rpcURL string
Parser *EthereumParser Parser *EthereumParser
CoinName string
Testnet bool Testnet bool
Network string Network string
Mempool *bchain.NonUTXOMempool Mempool *bchain.NonUTXOMempool
@ -143,21 +141,25 @@ func (b *EthereumRPC) Initialize() error {
} }
glog.Info("rpc: block chain ", b.Network) glog.Info("rpc: block chain ", b.Network)
// subscriptions if b.ChainConfig.CoinName == "Ethereum Classic" {
if err = b.subscribe(func() (*rpc.ClientSubscription, error) { glog.Info(b.ChainConfig.CoinName, " does not support subscription to newHeads")
// invalidate the previous subscription - it is either the first one or there was an error } else {
b.newBlockSubscription = nil // subscriptions
ctx, cancel := context.WithTimeout(context.Background(), b.timeout) if err = b.subscribe(func() (*rpc.ClientSubscription, error) {
defer cancel() // invalidate the previous subscription - it is either the first one or there was an error
sub, err := b.rpc.EthSubscribe(ctx, b.chanNewBlock, "newHeads") b.newBlockSubscription = nil
if err != nil { ctx, cancel := context.WithTimeout(context.Background(), b.timeout)
return nil, errors.Annotatef(err, "EthSubscribe newHeads") 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) { if err = b.subscribe(func() (*rpc.ClientSubscription, error) {
// invalidate the previous subscription - it is either the first one or there was an error // invalidate the previous subscription - it is either the first one or there was an error

View File

@ -40,7 +40,7 @@
"internal_binding_template": ":{{.Ports.BlockbookInternal}}", "internal_binding_template": ":{{.Ports.BlockbookInternal}}",
"public_binding_template": ":{{.Ports.BlockbookPublic}}", "public_binding_template": ":{{.Ports.BlockbookPublic}}",
"explorer_url": "https://gastracker.io/", "explorer_url": "https://gastracker.io/",
"additional_params": "", "additional_params": "-resyncindexperiod=4441",
"block_chain": { "block_chain": {
"parse": true, "parse": true,
"mempool_workers": 8, "mempool_workers": 8,