diff --git a/bchain/coins/eth/ethrpc.go b/bchain/coins/eth/ethrpc.go index 9656e6c3..eb0bdc2d 100644 --- a/bchain/coins/eth/ethrpc.go +++ b/bchain/coins/eth/ethrpc.go @@ -31,11 +31,13 @@ const ( // Configuration represents json config file type Configuration struct { - CoinName string `json:"coin_name"` - CoinShortcut string `json:"coin_shortcut"` - RPCURL string `json:"rpc_url"` - RPCTimeout int `json:"rpc_timeout"` - BlockAddressesToKeep int `json:"block_addresses_to_keep"` + CoinName string `json:"coin_name"` + CoinShortcut string `json:"coin_shortcut"` + RPCURL string `json:"rpc_url"` + RPCTimeout int `json:"rpc_timeout"` + BlockAddressesToKeep int `json:"block_addresses_to_keep"` + MempoolTxTimeoutHours int `json:"mempoolTxTimeoutHours"` + QueryBackendOnMempoolResync bool `json:"queryBackendOnMempoolResync"` } // EthereumRPC is an interface to JSON-RPC eth service. @@ -162,7 +164,8 @@ func (b *EthereumRPC) Initialize() error { // CreateMempool creates mempool if not already created, however does not initialize it func (b *EthereumRPC) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, error) { if b.Mempool == nil { - b.Mempool = bchain.NewMempoolEthereumType(chain) + b.Mempool = bchain.NewMempoolEthereumType(chain, b.ChainConfig.MempoolTxTimeoutHours, b.ChainConfig.QueryBackendOnMempoolResync) + glog.Info("mempool created, MempoolTxTimeoutHours=", b.ChainConfig.MempoolTxTimeoutHours, ", QueryBackendOnMempoolResync=", b.ChainConfig.QueryBackendOnMempoolResync) } return b.Mempool, nil } diff --git a/bchain/mempool_ethereum_type.go b/bchain/mempool_ethereum_type.go index 4eb5b969..33e44e72 100644 --- a/bchain/mempool_ethereum_type.go +++ b/bchain/mempool_ethereum_type.go @@ -6,24 +6,28 @@ import ( "github.com/golang/glog" ) -const mempoolTimeoutTime = 24 * time.Hour const mempoolTimeoutRunPeriod = 10 * time.Minute // MempoolEthereumType is mempool handle of EthereumType chains type MempoolEthereumType struct { BaseMempool - nextTimeoutRun time.Time + mempoolTimeoutTime time.Duration + queryBackendOnResync bool + nextTimeoutRun time.Time } // NewMempoolEthereumType creates new mempool handler. -func NewMempoolEthereumType(chain BlockChain) *MempoolEthereumType { +func NewMempoolEthereumType(chain BlockChain, mempoolTxTimeoutHours int, queryBackendOnResync bool) *MempoolEthereumType { + mempoolTimeoutTime := time.Duration(mempoolTxTimeoutHours) * time.Hour return &MempoolEthereumType{ BaseMempool: BaseMempool{ chain: chain, txEntries: make(map[string]txEntry), addrDescToTx: make(map[string][]Outpoint), }, - nextTimeoutRun: time.Now().Add(mempoolTimeoutTime), + mempoolTimeoutTime: mempoolTimeoutTime, + queryBackendOnResync: queryBackendOnResync, + nextTimeoutRun: time.Now().Add(mempoolTimeoutTime), } } @@ -90,11 +94,20 @@ func (m *MempoolEthereumType) createTxEntry(txid string, txTime uint32) (txEntry // Resync ethereum type removes timed out transactions and returns number of transactions in mempool. // Transactions are added/removed by AddTransactionToMempool/RemoveTransactionFromMempool methods func (m *MempoolEthereumType) Resync() (int, error) { + if m.queryBackendOnResync { + txs, err := m.chain.GetMempoolTransactions() + if err != nil { + return 0, err + } + for _, txid := range txs { + m.AddTransactionToMempool(txid) + } + } m.mux.Lock() entries := len(m.txEntries) now := time.Now() if m.nextTimeoutRun.Before(now) { - threshold := now.Add(-mempoolTimeoutTime) + threshold := now.Add(-m.mempoolTimeoutTime) for txid, entry := range m.txEntries { if time.Unix(int64(entry.time), 0).Before(threshold) { m.removeEntryFromMempool(txid, entry) diff --git a/configs/coins/ethereum-classic.json b/configs/coins/ethereum-classic.json index 93e4268f..7889e415 100644 --- a/configs/coins/ethereum-classic.json +++ b/configs/coins/ethereum-classic.json @@ -1,9 +1,9 @@ { "coin": { - "name": "Ethereum Classic", - "shortcut": "ETC", - "label": "Ethereum Classic", - "alias": "ethereum-classic" + "name": "Ethereum Classic", + "shortcut": "ETC", + "label": "Ethereum Classic", + "alias": "ethereum-classic" }, "ports": { "backend_rpc": 8037, @@ -41,17 +41,20 @@ "internal_binding_template": ":{{.Ports.BlockbookInternal}}", "public_binding_template": ":{{.Ports.BlockbookPublic}}", "explorer_url": "", - "additional_params": "-resyncindexperiod=4441", + "additional_params": "-resyncindexperiod=4441 -resyncmempoolperiod=2011", "block_chain": { "parse": true, "mempool_workers": 8, "mempool_sub_workers": 2, "block_addresses_to_keep": 300, - "additional_params": {} + "additional_params": { + "mempoolTxTimeoutHours": 48, + "queryBackendOnMempoolResync": true + } } }, "meta": { "package_maintainer": "Petr Kracik", "package_maintainer_email": "petr.kracik@satoshilabs.com" } -} +} \ No newline at end of file diff --git a/configs/coins/ethereum.json b/configs/coins/ethereum.json index 75ca8012..ebf40a4a 100644 --- a/configs/coins/ethereum.json +++ b/configs/coins/ethereum.json @@ -1,9 +1,9 @@ { "coin": { - "name": "Ethereum", - "shortcut": "ETH", - "label": "Ethereum", - "alias": "ethereum" + "name": "Ethereum", + "shortcut": "ETH", + "label": "Ethereum", + "alias": "ethereum" }, "ports": { "backend_rpc": 8036, @@ -49,11 +49,14 @@ "mempool_workers": 8, "mempool_sub_workers": 2, "block_addresses_to_keep": 300, - "additional_params": {} + "additional_params": { + "mempoolTxTimeoutHours": 48, + "queryBackendOnMempoolResync": false + } } }, "meta": { "package_maintainer": "Petr Kracik", "package_maintainer_email": "petr.kracik@satoshilabs.com" } -} +} \ No newline at end of file diff --git a/configs/coins/ethereum_testnet_ropsten.json b/configs/coins/ethereum_testnet_ropsten.json index 1f8f603e..6c064490 100644 --- a/configs/coins/ethereum_testnet_ropsten.json +++ b/configs/coins/ethereum_testnet_ropsten.json @@ -1,9 +1,9 @@ { "coin": { - "name": "Ethereum Testnet Ropsten", - "shortcut": "tROP", - "label": "Ethereum Ropsten", - "alias": "ethereum_testnet_ropsten" + "name": "Ethereum Testnet Ropsten", + "shortcut": "tROP", + "label": "Ethereum Ropsten", + "alias": "ethereum_testnet_ropsten" }, "ports": { "backend_rpc": 18036, @@ -48,11 +48,14 @@ "mempool_workers": 8, "mempool_sub_workers": 2, "block_addresses_to_keep": 300, - "additional_params": {} + "additional_params": { + "mempoolTxTimeoutHours": 12, + "queryBackendOnMempoolResync": false + } } }, "meta": { "package_maintainer": "Petr Kracik", "package_maintainer_email": "petr.kracik@satoshilabs.com" } -} +} \ No newline at end of file