lightning: merge 81b6d657..c3f3843c

This commit is contained in:
Janus 2018-03-06 17:03:51 +01:00
parent 402ecf66d5
commit 7a113fb954
2 changed files with 24 additions and 11 deletions

View File

@ -40,9 +40,11 @@ import traceback
from . import util
from . import bitcoin
from .bitcoin import *
from . import constants
from .interface import Interface
from . import blockchain
from .version import ELECTRUM_VERSION, PROTOCOL_VERSION
from .i18n import _
NODES_RETRY_INTERVAL = 60
@ -63,7 +65,7 @@ def parse_servers(result):
for v in item[2]:
if re.match("[st]\d*", v):
protocol, port = v[0], v[1:]
if port == '': port = bitcoin.NetworkConstants.DEFAULT_PORTS[protocol]
if port == '': port = constants.net.DEFAULT_PORTS[protocol]
out[protocol] = port
elif re.match("v(.?)+", v):
version = v[1:]
@ -97,7 +99,7 @@ def filter_protocol(hostmap, protocol = 's'):
def pick_random_server(hostmap = None, protocol = 's', exclude_set = set()):
if hostmap is None:
hostmap = bitcoin.NetworkConstants.DEFAULT_SERVERS
hostmap = constants.net.DEFAULT_SERVERS
eligible = list(set(filter_protocol(hostmap, protocol)) - exclude_set)
return random.choice(eligible) if eligible else None
@ -326,8 +328,10 @@ class Network(util.DaemonThread):
await self.queue_request('blockchain.scripthash.subscribe', [h])
async def request_fee_estimates(self):
from .simple_config import FEE_ETA_TARGETS
self.config.requested_fee_estimates()
for i in bitcoin.FEE_TARGETS:
await self.queue_request("mempool.get_fee_histogram", [])
for i in FEE_ETA_TARGETS:
await self.queue_request('blockchain.estimatefee', [i])
def get_status_value(self, key):
@ -337,6 +341,8 @@ class Network(util.DaemonThread):
value = self.banner
elif key == 'fee':
value = self.config.fee_estimates
elif key == "fee_histogram":
value = self.config.mempool_fees
elif key == 'updated':
value = (self.get_local_height(), self.get_server_height())
elif key == 'servers':
@ -364,7 +370,7 @@ class Network(util.DaemonThread):
return list(self.interfaces.keys())
def get_servers(self):
out = bitcoin.NetworkConstants.DEFAULT_SERVERS
out = constants.net.DEFAULT_SERVERS
if self.irc_servers:
out.update(filter_version(self.irc_servers.copy()))
else:
@ -571,6 +577,11 @@ class Network(util.DaemonThread):
elif method == 'server.donation_address':
if error is None:
self.donation_address = result
elif method == "mempool.get_fee_histogram":
if error is None:
self.print_error("fee_histogram", result)
self.config.mempool_fees = result
self.notify("fee_histogram")
elif method == 'blockchain.estimatefee':
if error is None and result > 0:
i = params[0]
@ -771,21 +782,22 @@ class Network(util.DaemonThread):
error = response.get('error')
result = response.get('result')
params = response.get('params')
blockchain = interface.blockchain
if result is None or params is None or error is not None:
interface.print_error(error or 'bad response')
return
index = params[0]
connect = interface.blockchain.connect_chunk(index, result)
connect = blockchain.connect_chunk(index, result)
if not connect:
await self.connection_down(interface.server, "could not connect chunk")
return
# If not finished, get the next chunk
if interface.blockchain.height() < interface.tip:
if index >= len(blockchain.checkpoints) and interface.blockchain.height() < interface.tip:
await self.request_chunk(interface, index+1)
else:
interface.mode = 'default'
interface.print_error('catch up done', interface.blockchain.height())
interface.blockchain.catch_up = None
interface.print_error('catch up done', blockchain.height())
blockchain.catch_up = None
self.notify('updated')
async def request_header(self, interface, height):
@ -978,7 +990,7 @@ class Network(util.DaemonThread):
def init_headers_file(self):
b = self.blockchains[0]
filename = b.path()
length = 80 * len(bitcoin.NetworkConstants.CHECKPOINTS) * 2016
length = 80 * len(constants.net.CHECKPOINTS) * 2016
if not os.path.exists(filename) or os.path.getsize(filename) < length:
with open(filename, 'wb') as f:
if length>0:
@ -1243,7 +1255,7 @@ class Network(util.DaemonThread):
try:
r = q.get(True, timeout)
except queue.Empty:
raise BaseException('Server did not answer')
raise util.TimeoutException(_('Server did not answer'))
if r.get('error'):
raise BaseException(r.get('error'))
return r.get('result')
@ -1265,7 +1277,7 @@ class Network(util.DaemonThread):
f.write(json.dumps(cp, indent=4))
def max_checkpoint(self):
return max(0, len(bitcoin.NetworkConstants.CHECKPOINTS) * 2016 - 1)
return max(0, len(constants.net.CHECKPOINTS) * 2016 - 1)
async def send_async(self, messages, callback=None):
""" if callback is None, it returns the result """

View File

@ -29,6 +29,7 @@ import traceback
import urllib
import threading
import hmac
import asyncio
from .i18n import _