Compare commits

..
10 changed files with 28 additions and 108 deletions

No files matched your search

+5 -3
View File
@@ -128,11 +128,13 @@ class WalletComponent(Component):
if self.wallet_manager.ledger.network.remote_height:
local_height = self.wallet_manager.ledger.local_height_including_downloaded_height
disk_height = len(self.wallet_manager.ledger.headers)
download_height = local_height - disk_height if disk_height != local_height else local_height
remote_height = self.wallet_manager.ledger.network.remote_height
target_height = remote_height - disk_height if disk_height != local_height else remote_height
best_hash = self.wallet_manager.get_best_blockhash()
if disk_height != local_height != remote_height:
download_height, target_height = local_height - disk_height, remote_height - disk_height
else:
download_height, target_height = local_height, remote_height
progress = min(max(math.ceil(float(download_height) / float(target_height) * 100), 0), 100)
best_hash = self.wallet_manager.get_best_blockhash()
result.update({
'headers_synchronization_progress': progress,
'blocks': max(local_height, 0),
+4 -4
View File
@@ -718,8 +718,6 @@ class SQLDB:
claim_hash = output.claim_hash
update_claims.append(output)
recalculate_claim_hashes.add(claim_hash)
delete_claim_hashes.discard(claim_hash)
update_claim_hashes.add(claim_hash)
body_timer.stop()
skip_update_claim_timer = timer.add_timer('skip update of abandoned claims')
@@ -727,8 +725,10 @@ class SQLDB:
for updated_claim in list(update_claims):
if updated_claim.ref.hash in delete_others:
update_claims.remove(updated_claim)
delete_claim_hashes.add(updated_claim.claim_hash)
update_claim_hashes.discard(updated_claim.claim_hash)
for updated_claim in update_claims:
claim_hash = updated_claim.claim_hash
delete_claim_hashes.discard(claim_hash)
update_claim_hashes.add(claim_hash)
skip_update_claim_timer.stop()
skip_insert_claim_timer = timer.add_timer('skip insertion of abandoned claims')
-51
View File
@@ -1,51 +0,0 @@
import asyncio
import logging
from torba.client.wallet import Wallet
from lbry.wallet.ledger import MainNetLedger
from lbry.wallet.dewies import lbc_to_dewies
from lbry.wallet.transaction import Output, Transaction
log = logging.getLogger(__name__)
class WalletServerPayer:
def __init__(self, ledger: MainNetLedger, wallet: Wallet):
self.ledger = ledger
self.wallet = wallet
self.running = False
self.task = None
async def pay(self):
while self.running:
await asyncio.sleep(24 * 60 * 60)
features = await self.ledger.network.get_server_features()
address = features['payment_address']
if not self.ledger.is_valid_address(address):
raise Exception(f"Invalid address: {address}")
if self.wallet.is_locked:
raise Exception("Cannot spend funds with locked wallet")
amount = lbc_to_dewies(features['daily_fee']) # check that this is in lbc and not dewies
# todo: check that amount is less than our max
tx = await Transaction.create([],
[Output.pay_pubkey_hash(amount, self.ledger.address_to_hash160(address))],
self.wallet.get_accounts_or_all(None),
self.wallet.get_account_or_default(None))
await self.ledger.broadcast(tx)
await self.analytics_manager.send_credits_sent()
async def start(self):
self.running = True
self.task = asyncio.ensure_future(self.pay())
self.task.add_done_callback(lambda _: log.info("Stopping wallet server payments."))
async def stop(self):
if self.running:
self.running = False
self.task.cancel()
@@ -4,8 +4,6 @@ import lbry.wallet
from lbry import __version__ as sdk_version
from torba.client.basenetwork import ClientSession
from torba.testcase import IntegrationTestCase
from torba.orchstr8.node import SPVNode
from lbry.testcase import CommandTestCase
class TestSessions(IntegrationTestCase):
@@ -51,40 +49,3 @@ class TestSegwitServer(IntegrationTestCase):
async def test_at_least_it_starts(self):
await asyncio.wait_for(self.ledger.network.get_headers(0, 1), 1.0)
class TestUsagePayment(CommandTestCase):
async def test_single_server_payment(self):
# create wallet server
# set payment address and fee rate on server
# connect to server
# fast forward 24 hours
# check that payment was sent to server
address = (await self.account.receiving.get_addresses(limit=1, only_usable=True))[0]
node = SPVNode(self.conductor.spv_module, node_number=2)
await node.start(self.blockchain, extraconf={"PAYMENT_ADDRESS": address, "DAILY_FEE": "1"})
self.ledger.network.config['default_servers'] = [(node.hostname, node.port)]
await self.ledger.stop()
await self.ledger.start()
features = await self.ledger.network.get_server_features()
pass
# async def test_daily_payment(self):
# node2 = SPVNode(self.conductor.spv_module, node_number=2)
# self.ledger.network.config['default_servers'].append((node2.hostname, node2.port))
# await asyncio.wait_for(self.ledger.stop(), timeout=1)
# await asyncio.wait_for(self.ledger.start(), timeout=1)
# self.ledger.network.session_pool.new_connection_event.clear()
# await node2.start(self.blockchain)
# # this is only to speed up the test as retrying would take 4+ seconds
# for session in self.ledger.network.session_pool.sessions:
# session.trigger_urgent_reconnect.set()
# await asyncio.wait_for(self.ledger.network.session_pool.new_connection_event.wait(), timeout=1)
@@ -321,6 +321,14 @@ class TestClaimtrie(TestSQLDB):
advance(10, [stream, self.get_stream_update(stream, 11*COIN)])
self.assertTrue(reader._search())
def test_double_updates_in_same_block(self):
advance, state = self.advance, self.state
stream = self.get_stream('Claim A', 10*COIN)
advance(10, [stream])
update = self.get_stream_update(stream, 11*COIN)
advance(20, [update, self.get_stream_update(update, 9*COIN)])
self.assertTrue(reader._search())
def test_create_and_abandon_in_same_block(self):
advance, state = self.advance, self.state
stream = self.get_stream('Claim A', 10*COIN)
@@ -33,7 +33,7 @@ class NetworkTests(IntegrationTestCase):
address = (await self.account.get_addresses(limit=1))[0]
os.environ.update({
'DESCRIPTION': 'Fastest server in the west.',
'PAYMENT_ADDRESS': address,
'DONATION_ADDRESS': address,
'DAILY_FEE': '42'})
await self.conductor.spv_node.start(self.conductor.blockchain_node)
await self.ledger.network.on_connected.first
@@ -180,7 +180,7 @@ class TestQueryBuilder(unittest.TestCase):
a__not='b', b__in='select * from blah where c=:$c',
d__any={'one__like': 'o', 'two': 2},
a0=3, a00=1, a00a=2, a00aa=4, # <-- breaks without correct interpolation key order
ahash=memoryview(sha256(b'hello world')),
ahash=sha256(b'hello world'),
limit=10, order_by='b', **{'$c': 3})
),
"select * from foo WHERE a != 'b' AND "
+2 -2
View File
@@ -199,8 +199,8 @@ def query(select, **constraints) -> Tuple[str, Dict[str, Any]]:
def interpolate(sql, values):
for k in sorted(values.keys(), reverse=True):
value = values[k]
if isinstance(value, memoryview):
value = f"X'{hexlify(bytes(value)).decode()}'"
if isinstance(value, bytes):
value = f"X'{hexlify(value).decode()}'"
elif isinstance(value, str):
value = f"'{value}'"
else:
+1 -1
View File
@@ -71,7 +71,7 @@ class Env:
self.tor_proxy_host = self.default('TOR_PROXY_HOST', 'localhost')
self.tor_proxy_port = self.integer('TOR_PROXY_PORT', None)
# The electrum client takes the empty string as unspecified
self.payment_address = self.default('PAYMENT_ADDRESS', '')
self.donation_address = self.default('DONATION_ADDRESS', '')
# Server limits to help prevent DoS
self.max_send = self.integer('MAX_SEND', 1000000)
self.max_subs = self.integer('MAX_SUBS', 250000)
+6 -6
View File
@@ -751,7 +751,7 @@ class ElectrumX(SessionBase):
'protocol_max': max_str,
'genesis_hash': env.coin.GENESIS_HASH,
'description': env.description,
'payment_address': env.payment_address,
'payment_address': env.donation_address,
'daily_fee': env.daily_fee,
'hash_function': 'sha256',
}
@@ -1073,14 +1073,14 @@ class ElectrumX(SessionBase):
('$SERVER_VERSION', self.version),
('$DAEMON_VERSION', daemon_version),
('$DAEMON_SUBVERSION', network_info['subversion']),
('$PAYMENT_ADDRESS', self.env.payment_address),
('$DONATION_ADDRESS', self.env.donation_address),
]:
banner = banner.replace(*pair)
return banner
async def payment_address(self):
"""Return the payment address as a string, empty if there is none."""
return self.env.payment_address
async def donation_address(self):
"""Return the donation address as a string, empty if there is none."""
return self.env.donation_address
async def banner(self):
"""Return the server banner text."""
@@ -1265,7 +1265,7 @@ class ElectrumX(SessionBase):
'blockchain.transaction.get_merkle': self.transaction_merkle,
'server.add_peer': self.add_peer,
'server.banner': self.banner,
'server.payment_address': self.payment_address,
'server.donation_address': self.donation_address,
'server.features': self.server_features_async,
'server.peers.subscribe': self.peers_subscribe,
'server.version': self.server_version,