update orchstr8

This commit is contained in:
Jack Robison 2022-03-04 10:37:01 -05:00
parent 973ee4f08c
commit 8faaf9f465
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
3 changed files with 22 additions and 25 deletions

View file

@ -16,25 +16,19 @@ from binascii import hexlify
from typing import Type, Optional from typing import Type, Optional
import urllib.request import urllib.request
from uuid import uuid4 from uuid import uuid4
import lbry import lbry
from lbry.wallet.server.env import Env
from lbry.wallet import Wallet, Ledger, RegTestLedger, WalletManager, Account, BlockHeightEvent from lbry.wallet import Wallet, Ledger, RegTestLedger, WalletManager, Account, BlockHeightEvent
from lbry.conf import KnownHubsList, Config from lbry.conf import KnownHubsList, Config
from lbry.wallet.orchstr8 import __hub_url__ from lbry.wallet.orchstr8 import __hub_url__
from lbry.wallet.server.block_processor import BlockProcessor
from lbry.wallet.server.chain_reader import BlockchainReaderServer from scribe.env import Env
from lbry.wallet.server.db.elasticsearch.sync import ElasticWriter from scribe.server.server import BlockchainReaderServer
from scribe.elasticsearch.sync import ElasticWriter
from scribe.writer.block_processor import BlockProcessor
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def get_spvserver_from_ledger(ledger_module):
spvserver_path, regtest_class_name = ledger_module.__spvserver__.rsplit('.', 1)
spvserver_module = importlib.import_module(spvserver_path)
return getattr(spvserver_module, regtest_class_name)
def get_lbcd_node_from_ledger(ledger_module): def get_lbcd_node_from_ledger(ledger_module):
return LBCDNode( return LBCDNode(
ledger_module.__lbcd_url__, ledger_module.__lbcd_url__,
@ -42,6 +36,7 @@ def get_lbcd_node_from_ledger(ledger_module):
ledger_module.__lbcctl__ ledger_module.__lbcctl__
) )
def get_lbcwallet_node_from_ledger(ledger_module): def get_lbcwallet_node_from_ledger(ledger_module):
return LBCWalletNode( return LBCWalletNode(
ledger_module.__lbcwallet_url__, ledger_module.__lbcwallet_url__,
@ -54,11 +49,9 @@ class Conductor:
def __init__(self, seed=None): def __init__(self, seed=None):
self.manager_module = WalletManager self.manager_module = WalletManager
self.spv_module = get_spvserver_from_ledger(lbry.wallet)
self.lbcd_node = get_lbcd_node_from_ledger(lbry.wallet) self.lbcd_node = get_lbcd_node_from_ledger(lbry.wallet)
self.lbcwallet_node = get_lbcwallet_node_from_ledger(lbry.wallet) self.lbcwallet_node = get_lbcwallet_node_from_ledger(lbry.wallet)
self.spv_node = SPVNode(self.spv_module) self.spv_node = SPVNode()
self.wallet_node = WalletNode( self.wallet_node = WalletNode(
self.manager_module, RegTestLedger, default_seed=seed self.manager_module, RegTestLedger, default_seed=seed
) )
@ -222,10 +215,8 @@ class WalletNode:
class SPVNode: class SPVNode:
def __init__(self, node_number=1):
def __init__(self, coin_class, node_number=1):
self.node_number = node_number self.node_number = node_number
self.coin_class = coin_class
self.controller = None self.controller = None
self.data_path = None self.data_path = None
self.server: Optional[BlockchainReaderServer] = None self.server: Optional[BlockchainReaderServer] = None
@ -244,6 +235,7 @@ class SPVNode:
if not self.stopped: if not self.stopped:
log.warning("spv node is already running") log.warning("spv node is already running")
return return
print("start spv node")
self.stopped = False self.stopped = False
try: try:
self.data_path = tempfile.mkdtemp() self.data_path = tempfile.mkdtemp()
@ -262,15 +254,18 @@ class SPVNode:
'session_timeout': self.session_timeout, 'session_timeout': self.session_timeout,
'max_query_workers': 0, 'max_query_workers': 0,
'es_index_prefix': self.index_name, 'es_index_prefix': self.index_name,
'chain': 'regtest'
} }
if extraconf: if extraconf:
conf.update(extraconf) conf.update(extraconf)
env = Env(self.coin_class, **conf) env = Env(**conf)
self.writer = BlockProcessor(env) self.writer = BlockProcessor(env)
self.server = BlockchainReaderServer(env) self.server = BlockchainReaderServer(env)
self.es_writer = ElasticWriter(env) self.es_writer = ElasticWriter(env)
await self.writer.open() await self.writer.open()
print("opened writer, starting")
await self.writer.start() await self.writer.start()
print("started writer")
await self.es_writer.start() await self.es_writer.start()
await self.server.start() await self.server.start()
except Exception as e: except Exception as e:

View file

@ -3,6 +3,8 @@ import asyncio
import lbry import lbry
from unittest.mock import Mock from unittest.mock import Mock
from lbry_schema.coin import LBCRegTest
from lbry.wallet.network import Network from lbry.wallet.network import Network
from lbry.wallet.orchstr8 import Conductor from lbry.wallet.orchstr8 import Conductor
from lbry.wallet.orchstr8.node import SPVNode from lbry.wallet.orchstr8.node import SPVNode
@ -22,7 +24,7 @@ class NetworkTests(IntegrationTestCase):
async def test_server_features(self): async def test_server_features(self):
self.assertDictEqual({ self.assertDictEqual({
'genesis_hash': self.conductor.spv_node.coin_class.GENESIS_HASH, 'genesis_hash': LBCRegTest.GENESIS_HASH,
'hash_function': 'sha256', 'hash_function': 'sha256',
'hosts': {}, 'hosts': {},
'protocol_max': '0.199.0', 'protocol_max': '0.199.0',
@ -53,7 +55,7 @@ class NetworkTests(IntegrationTestCase):
# await self.ledger.network.on_connected.first # await self.ledger.network.on_connected.first
self.assertDictEqual({ self.assertDictEqual({
'genesis_hash': self.conductor.spv_node.coin_class.GENESIS_HASH, 'genesis_hash': LBCRegTest.GENESIS_HASH,
'hash_function': 'sha256', 'hash_function': 'sha256',
'hosts': {}, 'hosts': {},
'protocol_max': '0.199.0', 'protocol_max': '0.199.0',
@ -79,7 +81,7 @@ class ReconnectTests(IntegrationTestCase):
async def test_multiple_servers(self): async def test_multiple_servers(self):
# we have a secondary node that connects later, so # we have a secondary node that connects later, so
node2 = SPVNode(self.conductor.spv_module, node_number=2) node2 = SPVNode(node_number=2)
await node2.start(self.blockchain) await node2.start(self.blockchain)
self.ledger.network.config['explicit_servers'].append((node2.hostname, node2.port)) self.ledger.network.config['explicit_servers'].append((node2.hostname, node2.port))

View file

@ -62,7 +62,7 @@ class TestUsagePayment(CommandTestCase):
_, history = await self.ledger.get_local_status_and_history(address) _, history = await self.ledger.get_local_status_and_history(address)
self.assertEqual(history, []) self.assertEqual(history, [])
node = SPVNode(self.conductor.spv_module, node_number=2) node = SPVNode(node_number=2)
await node.start(self.blockchain, extraconf={"payment_address": address, "daily_fee": "1.1"}) await node.start(self.blockchain, extraconf={"payment_address": address, "daily_fee": "1.1"})
self.addCleanup(node.stop) self.addCleanup(node.stop)
self.daemon.jsonrpc_settings_set('lbryum_servers', [f"{node.hostname}:{node.port}"]) self.daemon.jsonrpc_settings_set('lbryum_servers', [f"{node.hostname}:{node.port}"])
@ -146,17 +146,17 @@ class TestESSync(CommandTestCase):
class TestHubDiscovery(CommandTestCase): class TestHubDiscovery(CommandTestCase):
async def test_hub_discovery(self): async def test_hub_discovery(self):
us_final_node = SPVNode(self.conductor.spv_module, node_number=2) us_final_node = SPVNode(node_number=2)
await us_final_node.start(self.blockchain, extraconf={"country": "US"}) await us_final_node.start(self.blockchain, extraconf={"country": "US"})
self.addCleanup(us_final_node.stop) self.addCleanup(us_final_node.stop)
final_node_host = f"{us_final_node.hostname}:{us_final_node.port}" final_node_host = f"{us_final_node.hostname}:{us_final_node.port}"
kp_final_node = SPVNode(self.conductor.spv_module, node_number=3) kp_final_node = SPVNode(node_number=3)
await kp_final_node.start(self.blockchain, extraconf={"country": "KP"}) await kp_final_node.start(self.blockchain, extraconf={"country": "KP"})
self.addCleanup(kp_final_node.stop) self.addCleanup(kp_final_node.stop)
kp_final_node_host = f"{kp_final_node.hostname}:{kp_final_node.port}" kp_final_node_host = f"{kp_final_node.hostname}:{kp_final_node.port}"
relay_node = SPVNode(self.conductor.spv_module, node_number=4) relay_node = SPVNode(node_number=4)
await relay_node.start(self.blockchain, extraconf={ await relay_node.start(self.blockchain, extraconf={
"country": "FR", "country": "FR",
"peer_hubs": ",".join([kp_final_node_host, final_node_host]) "peer_hubs": ",".join([kp_final_node_host, final_node_host])