Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6419f199c | ||
|
|
5a3cd577db | ||
|
|
f5ccb8efdc | ||
|
|
46ef6c8ab7 | ||
|
|
b09eabc478 | ||
|
|
e49fcea6e3 | ||
|
|
26964ecf0f |
No files matched your search
+14
-5
@@ -277,14 +277,23 @@ class Strings(ListSetting):
|
||||
class EnvironmentAccess:
|
||||
PREFIX = 'LBRY_'
|
||||
|
||||
def __init__(self, environ: dict):
|
||||
self.environ = environ
|
||||
def __init__(self, config: 'BaseConfig', environ: dict):
|
||||
self.configuration = config
|
||||
self.data = {}
|
||||
if environ:
|
||||
self.load(environ)
|
||||
|
||||
def load(self, environ):
|
||||
for setting in self.configuration.get_settings():
|
||||
value = environ.get(f'{self.PREFIX}{setting.name.upper()}', NOT_SET)
|
||||
if value != NOT_SET and not (isinstance(setting, ListSetting) and value is None):
|
||||
self.data[setting.name] = setting.deserialize(value)
|
||||
|
||||
def __contains__(self, item: str):
|
||||
return f'{self.PREFIX}{item.upper()}' in self.environ
|
||||
return item in self.data
|
||||
|
||||
def __getitem__(self, item: str):
|
||||
return self.environ[f'{self.PREFIX}{item.upper()}']
|
||||
return self.data[item]
|
||||
|
||||
|
||||
class ArgumentAccess:
|
||||
@@ -443,7 +452,7 @@ class BaseConfig:
|
||||
self.arguments = ArgumentAccess(self, args)
|
||||
|
||||
def set_environment(self, environ=None):
|
||||
self.environment = EnvironmentAccess(environ or os.environ)
|
||||
self.environment = EnvironmentAccess(self, environ or os.environ)
|
||||
|
||||
def set_persisted(self, config_file_path=None):
|
||||
if config_file_path is None:
|
||||
|
||||
@@ -483,6 +483,7 @@ class Ledger(metaclass=LedgerRegistry):
|
||||
|
||||
def process_status_update(self, update):
|
||||
address, remote_status = update
|
||||
log.info("Server sent update for %s, processing.", address)
|
||||
self._update_tasks.add(self.update_history(address, remote_status))
|
||||
|
||||
async def update_history(self, address, remote_status, address_manager: AddressManager = None):
|
||||
@@ -640,6 +641,7 @@ class Ledger(metaclass=LedgerRegistry):
|
||||
return self.network.broadcast(hexlify(tx.raw).decode())
|
||||
|
||||
async def wait(self, tx: Transaction, height=-1, timeout=1):
|
||||
log.info("waiting for tx %s with timeout %s seconds", tx.id, timeout)
|
||||
timeout = timeout or 600 # after 10 minutes there is almost 0 hope
|
||||
addresses = set()
|
||||
for txi in tx.inputs:
|
||||
@@ -653,6 +655,7 @@ class Ledger(metaclass=LedgerRegistry):
|
||||
start = int(time.perf_counter())
|
||||
while timeout and (int(time.perf_counter()) - start) <= timeout:
|
||||
if await self._wait_round(tx, height, addresses):
|
||||
log.info("got reply for tx %s with timeout %s seconds", tx.id, timeout)
|
||||
return
|
||||
raise asyncio.TimeoutError('Timed out waiting for transaction.')
|
||||
|
||||
@@ -675,7 +678,9 @@ class Ledger(metaclass=LedgerRegistry):
|
||||
if txid == tx.id and local_height >= height:
|
||||
found = True
|
||||
if not found:
|
||||
log.debug("timeout: %s, %s, %s", record['history'], addresses, tx.id)
|
||||
log.info('forcing update on %s', record['address'])
|
||||
self._update_tasks.add(self.update_history(record['address'], 'force'))
|
||||
log.info("timeout: %s, %s, %s", record['history'], addresses, tx.id)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
@@ -298,7 +298,9 @@ class WalletManager:
|
||||
|
||||
async def broadcast_or_release(self, tx, blocking=False):
|
||||
try:
|
||||
log.info("broadcasting %s", tx.id)
|
||||
await self.ledger.broadcast(tx)
|
||||
log.info("broadcasted %s", tx.id)
|
||||
if blocking:
|
||||
await self.ledger.wait(tx, timeout=None)
|
||||
except:
|
||||
|
||||
@@ -3,6 +3,7 @@ import os
|
||||
import asyncio
|
||||
import socket
|
||||
import ipaddress
|
||||
import lbry.wallet
|
||||
from lbry.conf import Config
|
||||
from lbry.extras.daemon.storage import SQLiteStorage
|
||||
from lbry.blob.blob_manager import BlobManager
|
||||
|
||||
@@ -90,10 +90,15 @@ class ConfigurationTests(unittest.TestCase):
|
||||
|
||||
def test_environment(self):
|
||||
c = TestConfig()
|
||||
|
||||
self.assertEqual(c.test_str, 'the default')
|
||||
c.set_environment({'LBRY_TEST_STR': 'from environ'})
|
||||
self.assertEqual(c.test_str, 'from environ')
|
||||
|
||||
self.assertEqual(c.test_int, 9)
|
||||
c.set_environment({'LBRY_TEST_INT': '1'})
|
||||
self.assertEqual(c.test_int, 1)
|
||||
|
||||
def test_persisted(self):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
|
||||
|
||||
Reference in new issue
Block a user