Move masternode cache.
It was mistakenly made a pylru cache... Don't force non-Dash coins to carry the cache.
This commit is contained in:
parent
9cf3b5358f
commit
22b01d4dfb
@ -6,18 +6,15 @@
|
|||||||
# and warranty status of this software.
|
# and warranty status of this software.
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import traceback
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
import pylru
|
from aiorpcx import TaskSet, _version as aiorpcx_version
|
||||||
|
|
||||||
from aiorpcx import RPCError, TaskSet, _version as aiorpcx_version
|
|
||||||
import electrumx
|
import electrumx
|
||||||
from electrumx.lib.server_base import ServerBase
|
from electrumx.lib.server_base import ServerBase
|
||||||
from electrumx.lib.util import version_string
|
from electrumx.lib.util import version_string
|
||||||
from electrumx.server.mempool import MemPool
|
from electrumx.server.mempool import MemPool
|
||||||
from electrumx.server.peers import PeerManager
|
from electrumx.server.peers import PeerManager
|
||||||
from electrumx.server.session import BAD_REQUEST, SessionManager
|
from electrumx.server.session import SessionManager
|
||||||
|
|
||||||
|
|
||||||
class Controller(ServerBase):
|
class Controller(ServerBase):
|
||||||
@ -45,8 +42,6 @@ class Controller(ServerBase):
|
|||||||
|
|
||||||
self.coin = env.coin
|
self.coin = env.coin
|
||||||
self.tasks = TaskSet()
|
self.tasks = TaskSet()
|
||||||
self.cache_mn_height = 0
|
|
||||||
self.mn_cache = pylru.lrucache(256)
|
|
||||||
env.max_send = max(350000, env.max_send)
|
env.max_send = max(350000, env.max_send)
|
||||||
|
|
||||||
self.loop = asyncio.get_event_loop()
|
self.loop = asyncio.get_event_loop()
|
||||||
|
|||||||
@ -115,6 +115,10 @@ class SessionManager(object):
|
|||||||
self.history_cache = pylru.lrucache(256)
|
self.history_cache = pylru.lrucache(256)
|
||||||
# Cache some idea of room to avoid recounting on each subscription
|
# Cache some idea of room to avoid recounting on each subscription
|
||||||
self.subs_room = 0
|
self.subs_room = 0
|
||||||
|
# Masternode stuff only for such coins
|
||||||
|
if issubclass(env.coin.SESSIONCLS, DashElectrumX):
|
||||||
|
self.mn_cache_height = 0
|
||||||
|
self.mn_cache = []
|
||||||
# Event triggered when electrumx is listening for incoming requests.
|
# Event triggered when electrumx is listening for incoming requests.
|
||||||
self.server_listening = asyncio.Event()
|
self.server_listening = asyncio.Event()
|
||||||
# Set up the RPC request handlers
|
# Set up the RPC request handlers
|
||||||
@ -1297,8 +1301,6 @@ class DashElectrumX(ElectrumX):
|
|||||||
if not isinstance(payees, list):
|
if not isinstance(payees, list):
|
||||||
raise RPCError(BAD_REQUEST, 'expected a list of payees')
|
raise RPCError(BAD_REQUEST, 'expected a list of payees')
|
||||||
|
|
||||||
result = []
|
|
||||||
|
|
||||||
def get_masternode_payment_queue(mns):
|
def get_masternode_payment_queue(mns):
|
||||||
'''Returns the calculated position in the payment queue for all the
|
'''Returns the calculated position in the payment queue for all the
|
||||||
valid masterernodes in the given mns list.
|
valid masterernodes in the given mns list.
|
||||||
@ -1346,10 +1348,8 @@ class DashElectrumX(ElectrumX):
|
|||||||
# Accordingly with the masternode payment queue, a custom list
|
# Accordingly with the masternode payment queue, a custom list
|
||||||
# with the masternode information including the payment
|
# with the masternode information including the payment
|
||||||
# position is returned.
|
# position is returned.
|
||||||
if (self.controller.cache_mn_height != self.height()
|
cache = self.session_mgr.mn_cache
|
||||||
or not self.controller.mn_cache):
|
if not cache or self.session_mgr.mn_cache_height != self.height():
|
||||||
self.controller.cache_mn_height = self.height()
|
|
||||||
self.controller.mn_cache.clear()
|
|
||||||
full_mn_list = await self.daemon.masternode_list(['full'])
|
full_mn_list = await self.daemon.masternode_list(['full'])
|
||||||
mn_payment_queue = get_masternode_payment_queue(full_mn_list)
|
mn_payment_queue = get_masternode_payment_queue(full_mn_list)
|
||||||
mn_payment_count = len(mn_payment_queue)
|
mn_payment_count = len(mn_payment_queue)
|
||||||
@ -1374,13 +1374,12 @@ class DashElectrumX(ElectrumX):
|
|||||||
mn_info['balance'] = (sum(balance.values())
|
mn_info['balance'] = (sum(balance.values())
|
||||||
/ self.coin.VALUE_PER_COIN)
|
/ self.coin.VALUE_PER_COIN)
|
||||||
mn_list.append(mn_info)
|
mn_list.append(mn_info)
|
||||||
self.controller.mn_cache = mn_list
|
cache.clear()
|
||||||
|
cache.extend(mn_list)
|
||||||
|
self.session_mgr.mn_cache_height = self.height()
|
||||||
|
|
||||||
# If payees is an empty list the whole masternode list is returned
|
# If payees is an empty list the whole masternode list is returned
|
||||||
if payees:
|
if payees:
|
||||||
result = [mn for mn in self.controller.mn_cache
|
return [mn for mn in cache if mn['payee'] in payees]
|
||||||
for address in payees if mn['payee'] == address]
|
|
||||||
else:
|
else:
|
||||||
result = self.controller.mn_cache
|
return cache
|
||||||
|
|
||||||
return result
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user