From 7e35bac99cd9fd7b44ca2baf09931ea340515360 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Tue, 11 Feb 2020 12:07:04 +0100 Subject: [PATCH] Remove etc specific code after upgrade to multi-geth backend --- bchain/coins/eth/ethparser.go | 6 --- bchain/coins/eth/ethrpc.go | 72 +++++++---------------------- configs/coins/ethereum-classic.json | 2 +- 3 files changed, 18 insertions(+), 62 deletions(-) diff --git a/bchain/coins/eth/ethparser.go b/bchain/coins/eth/ethparser.go index 49cea1fa..48da0e11 100644 --- a/bchain/coins/eth/ethparser.go +++ b/bchain/coins/eth/ethparser.go @@ -76,12 +76,6 @@ type rpcReceipt struct { Logs []*rpcLog `json:"logs"` } -type rpcEtcReceipt struct { - GasUsed string `json:"gasUsed"` - Status int `json:"status"` - Logs []*rpcLog `json:"logs"` -} - type completeTransaction struct { Tx *rpcTransaction `json:"tx"` Receipt *rpcReceipt `json:"receipt,omitempty"` diff --git a/bchain/coins/eth/ethrpc.go b/bchain/coins/eth/ethrpc.go index 158ee94f..df6a3a8e 100644 --- a/bchain/coins/eth/ethrpc.go +++ b/bchain/coins/eth/ethrpc.go @@ -57,7 +57,6 @@ type EthereumRPC struct { chanNewTx chan ethcommon.Hash newTxSubscription *rpc.ClientSubscription ChainConfig *Configuration - isETC bool } // NewEthereumRPC returns new EthRPC instance. @@ -89,9 +88,6 @@ func NewEthereumRPC(config json.RawMessage, pushHandler func(bchain.Notification s.Parser = NewEthereumParser(c.BlockAddressesToKeep) s.timeout = time.Duration(c.RPCTimeout) * time.Second - // detect ethereum classic - s.isETC = s.ChainConfig.CoinName == "Ethereum Classic" - // new blocks notifications handling // the subscription is done in Initialize s.chanNewBlock = make(chan *ethtypes.Header) @@ -206,25 +202,21 @@ func (b *EthereumRPC) InitializeMempool(addrDescForOutpoint bchain.AddrDescForOu } func (b *EthereumRPC) subscribeEvents() error { - if b.isETC { - 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 + // 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 } if err := b.subscribe(func() (*rpc.ClientSubscription, error) { @@ -366,12 +358,6 @@ func (b *EthereumRPC) GetChainInfo() (*bchain.ChainInfo, error) { func (b *EthereumRPC) getBestHeader() (*ethtypes.Header, error) { b.bestHeaderLock.Lock() defer b.bestHeaderLock.Unlock() - // ETC does not have newBlocks subscription, bestHeader must be updated very often (each 1 second) - if b.isETC { - if b.bestHeaderTime.Add(1 * time.Second).Before(time.Now()) { - b.bestHeader = nil - } - } // if the best header was not updated for 15 minutes, there could be a subscription problem, reconnect RPC // do it only in case of normal operation, not initial synchronization if b.bestHeaderTime.Add(15*time.Minute).Before(time.Now()) && !b.bestHeaderTime.IsZero() && b.mempoolInitialized { @@ -634,33 +620,9 @@ func (b *EthereumRPC) GetTransaction(txid string) (*bchain.Tx, error) { return nil, errors.Annotatef(err, "txid %v", txid) } var receipt rpcReceipt - if b.isETC { - var rawReceipt json.RawMessage - var etcReceipt rpcEtcReceipt - err = b.rpc.CallContext(ctx, &rawReceipt, "eth_getTransactionReceipt", hash) - if err != nil { - return nil, errors.Annotatef(err, "txid %v", txid) - } - err = json.Unmarshal(rawReceipt, &etcReceipt) - if err == nil { - receipt.GasUsed = etcReceipt.GasUsed - receipt.Logs = etcReceipt.Logs - if etcReceipt.Status == 0 { - receipt.Status = "0x0" - } else { - receipt.Status = "0x1" - } - } else { - err = json.Unmarshal(rawReceipt, &receipt) - if err != nil { - return nil, errors.Annotatef(err, "unmarshal receipt for txid %v, %v", txid, string(rawReceipt)) - } - } - } else { - err = b.rpc.CallContext(ctx, &receipt, "eth_getTransactionReceipt", hash) - if err != nil { - return nil, errors.Annotatef(err, "txid %v", txid) - } + err = b.rpc.CallContext(ctx, &receipt, "eth_getTransactionReceipt", hash) + if err != nil { + return nil, errors.Annotatef(err, "txid %v", txid) } n, err := ethNumber(tx.BlockNumber) if err != nil { diff --git a/configs/coins/ethereum-classic.json b/configs/coins/ethereum-classic.json index 3bf7e474..015f282a 100644 --- a/configs/coins/ethereum-classic.json +++ b/configs/coins/ethereum-classic.json @@ -41,7 +41,7 @@ "internal_binding_template": ":{{.Ports.BlockbookInternal}}", "public_binding_template": ":{{.Ports.BlockbookPublic}}", "explorer_url": "", - "additional_params": "-resyncindexperiod=4441 -resyncmempoolperiod=2011", + "additional_params": "", "block_chain": { "parse": true, "mempool_workers": 8,