Make ethereum type mempool parameters configurable
This commit is contained in:
parent
7ac877f160
commit
add504b57e
@ -31,11 +31,13 @@ const (
|
|||||||
|
|
||||||
// Configuration represents json config file
|
// Configuration represents json config file
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
CoinName string `json:"coin_name"`
|
CoinName string `json:"coin_name"`
|
||||||
CoinShortcut string `json:"coin_shortcut"`
|
CoinShortcut string `json:"coin_shortcut"`
|
||||||
RPCURL string `json:"rpc_url"`
|
RPCURL string `json:"rpc_url"`
|
||||||
RPCTimeout int `json:"rpc_timeout"`
|
RPCTimeout int `json:"rpc_timeout"`
|
||||||
BlockAddressesToKeep int `json:"block_addresses_to_keep"`
|
BlockAddressesToKeep int `json:"block_addresses_to_keep"`
|
||||||
|
MempoolTxTimeoutHours int `json:"mempoolTxTimeoutHours"`
|
||||||
|
QueryBackendOnMempoolResync bool `json:"queryBackendOnMempoolResync"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EthereumRPC is an interface to JSON-RPC eth service.
|
// 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
|
// CreateMempool creates mempool if not already created, however does not initialize it
|
||||||
func (b *EthereumRPC) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, error) {
|
func (b *EthereumRPC) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, error) {
|
||||||
if b.Mempool == nil {
|
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
|
return b.Mempool, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,24 +6,28 @@ import (
|
|||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
const mempoolTimeoutTime = 24 * time.Hour
|
|
||||||
const mempoolTimeoutRunPeriod = 10 * time.Minute
|
const mempoolTimeoutRunPeriod = 10 * time.Minute
|
||||||
|
|
||||||
// MempoolEthereumType is mempool handle of EthereumType chains
|
// MempoolEthereumType is mempool handle of EthereumType chains
|
||||||
type MempoolEthereumType struct {
|
type MempoolEthereumType struct {
|
||||||
BaseMempool
|
BaseMempool
|
||||||
nextTimeoutRun time.Time
|
mempoolTimeoutTime time.Duration
|
||||||
|
queryBackendOnResync bool
|
||||||
|
nextTimeoutRun time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMempoolEthereumType creates new mempool handler.
|
// 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{
|
return &MempoolEthereumType{
|
||||||
BaseMempool: BaseMempool{
|
BaseMempool: BaseMempool{
|
||||||
chain: chain,
|
chain: chain,
|
||||||
txEntries: make(map[string]txEntry),
|
txEntries: make(map[string]txEntry),
|
||||||
addrDescToTx: make(map[string][]Outpoint),
|
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.
|
// Resync ethereum type removes timed out transactions and returns number of transactions in mempool.
|
||||||
// Transactions are added/removed by AddTransactionToMempool/RemoveTransactionFromMempool methods
|
// Transactions are added/removed by AddTransactionToMempool/RemoveTransactionFromMempool methods
|
||||||
func (m *MempoolEthereumType) Resync() (int, error) {
|
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()
|
m.mux.Lock()
|
||||||
entries := len(m.txEntries)
|
entries := len(m.txEntries)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
if m.nextTimeoutRun.Before(now) {
|
if m.nextTimeoutRun.Before(now) {
|
||||||
threshold := now.Add(-mempoolTimeoutTime)
|
threshold := now.Add(-m.mempoolTimeoutTime)
|
||||||
for txid, entry := range m.txEntries {
|
for txid, entry := range m.txEntries {
|
||||||
if time.Unix(int64(entry.time), 0).Before(threshold) {
|
if time.Unix(int64(entry.time), 0).Before(threshold) {
|
||||||
m.removeEntryFromMempool(txid, entry)
|
m.removeEntryFromMempool(txid, entry)
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"coin": {
|
"coin": {
|
||||||
"name": "Ethereum Classic",
|
"name": "Ethereum Classic",
|
||||||
"shortcut": "ETC",
|
"shortcut": "ETC",
|
||||||
"label": "Ethereum Classic",
|
"label": "Ethereum Classic",
|
||||||
"alias": "ethereum-classic"
|
"alias": "ethereum-classic"
|
||||||
},
|
},
|
||||||
"ports": {
|
"ports": {
|
||||||
"backend_rpc": 8037,
|
"backend_rpc": 8037,
|
||||||
@ -41,13 +41,16 @@
|
|||||||
"internal_binding_template": ":{{.Ports.BlockbookInternal}}",
|
"internal_binding_template": ":{{.Ports.BlockbookInternal}}",
|
||||||
"public_binding_template": ":{{.Ports.BlockbookPublic}}",
|
"public_binding_template": ":{{.Ports.BlockbookPublic}}",
|
||||||
"explorer_url": "",
|
"explorer_url": "",
|
||||||
"additional_params": "-resyncindexperiod=4441",
|
"additional_params": "-resyncindexperiod=4441 -resyncmempoolperiod=2011",
|
||||||
"block_chain": {
|
"block_chain": {
|
||||||
"parse": true,
|
"parse": true,
|
||||||
"mempool_workers": 8,
|
"mempool_workers": 8,
|
||||||
"mempool_sub_workers": 2,
|
"mempool_sub_workers": 2,
|
||||||
"block_addresses_to_keep": 300,
|
"block_addresses_to_keep": 300,
|
||||||
"additional_params": {}
|
"additional_params": {
|
||||||
|
"mempoolTxTimeoutHours": 48,
|
||||||
|
"queryBackendOnMempoolResync": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"meta": {
|
"meta": {
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"coin": {
|
"coin": {
|
||||||
"name": "Ethereum",
|
"name": "Ethereum",
|
||||||
"shortcut": "ETH",
|
"shortcut": "ETH",
|
||||||
"label": "Ethereum",
|
"label": "Ethereum",
|
||||||
"alias": "ethereum"
|
"alias": "ethereum"
|
||||||
},
|
},
|
||||||
"ports": {
|
"ports": {
|
||||||
"backend_rpc": 8036,
|
"backend_rpc": 8036,
|
||||||
@ -49,7 +49,10 @@
|
|||||||
"mempool_workers": 8,
|
"mempool_workers": 8,
|
||||||
"mempool_sub_workers": 2,
|
"mempool_sub_workers": 2,
|
||||||
"block_addresses_to_keep": 300,
|
"block_addresses_to_keep": 300,
|
||||||
"additional_params": {}
|
"additional_params": {
|
||||||
|
"mempoolTxTimeoutHours": 48,
|
||||||
|
"queryBackendOnMempoolResync": false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"meta": {
|
"meta": {
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"coin": {
|
"coin": {
|
||||||
"name": "Ethereum Testnet Ropsten",
|
"name": "Ethereum Testnet Ropsten",
|
||||||
"shortcut": "tROP",
|
"shortcut": "tROP",
|
||||||
"label": "Ethereum Ropsten",
|
"label": "Ethereum Ropsten",
|
||||||
"alias": "ethereum_testnet_ropsten"
|
"alias": "ethereum_testnet_ropsten"
|
||||||
},
|
},
|
||||||
"ports": {
|
"ports": {
|
||||||
"backend_rpc": 18036,
|
"backend_rpc": 18036,
|
||||||
@ -48,7 +48,10 @@
|
|||||||
"mempool_workers": 8,
|
"mempool_workers": 8,
|
||||||
"mempool_sub_workers": 2,
|
"mempool_sub_workers": 2,
|
||||||
"block_addresses_to_keep": 300,
|
"block_addresses_to_keep": 300,
|
||||||
"additional_params": {}
|
"additional_params": {
|
||||||
|
"mempoolTxTimeoutHours": 12,
|
||||||
|
"queryBackendOnMempoolResync": false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"meta": {
|
"meta": {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user