Skip to content

Commit

Permalink
wip - fix quick test
Browse files Browse the repository at this point in the history
  • Loading branch information
glevco committed Oct 16, 2024
1 parent c08bd33 commit df2f44e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions hathor/builder/cli_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
if self._args.allow_mining_without_peers:
self.manager.allow_mining_without_peers()

if self._args.x_localhost_only:
self.manager.p2p_manager.enable_localhost_only()
# if self._args.x_localhost_only:
# self.manager.p2p_manager.enable_localhost_only()

dns_hosts = []
if settings.BOOTSTRAP_DNS:
Expand Down
6 changes: 3 additions & 3 deletions hathor/cli/quick_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, vertex_handler, manager, n_blocks):
self._manager = manager
self._n_blocks = n_blocks

def on_new_vertex(self, *, vertex: Vertex, fails_silently: bool) -> bool:
def on_new_vertex(self, vertex: Vertex, *, fails_silently: bool) -> bool:
from hathor.transaction import Block
from hathor.transaction.base_transaction import GenericVertex

Expand All @@ -56,7 +56,7 @@ def on_new_vertex(self, *, vertex: Vertex, fails_silently: bool) -> bool:
if should_quit:
assert msg is not None
self.log.info(f'successfully {msg}, exit now')
self._manager.connections.disconnect_all_peers(force=True)
# self._manager.connections.disconnect_all_peers(force=True)
self._manager.reactor.fireSystemEvent('shutdown')
os._exit(0)
return res
Expand All @@ -76,7 +76,7 @@ def prepare(self, *, register_resources: bool = True) -> None:
self._no_wait = self._args.no_wait

self.log.info('patching vertex_handler.on_new_vertex to quit on success')
self.manager.vertex_handler = VertexHandlerWrapper(
self.manager.p2p_manager.vertex_handler = VertexHandlerWrapper(
self.manager.vertex_handler,
self.manager,
self._args.quit_after_n_blocks,
Expand Down
4 changes: 2 additions & 2 deletions hathor/multiprocess/multiprocess_p2p_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from twisted.internet.interfaces import IProcessTransport
from twisted.protocols import amp

from hathor.multiprocess.node_ipc_server import NodeIpcServerFactor
from hathor.multiprocess.node_ipc_server import NodeIpcServerFactory
from hathor.multiprocess.p2p_ipc_main import P2P_IPC_MAIN
from hathor.multiprocess.p2p_ipc_server import Start
from hathor.p2p.factory import HathorClientFactory, HathorServerFactory
Expand Down Expand Up @@ -59,7 +59,7 @@ async def start(self) -> None:
outbound_socket = os.path.join(self._tmp_dir.name, 'out.sock')
inbound_socket = os.path.join(self._tmp_dir.name, 'in.sock')

server_factory = NodeIpcServerFactor(vertex_parser=self.vertex_parser, vertex_handler=self.vertex_handler, tx_storage=self.tx_storage)
server_factory = NodeIpcServerFactory(vertex_parser=self.vertex_parser, vertex_handler=self.vertex_handler, tx_storage=self.tx_storage)
server_endpoint = UNIXServerEndpoint(reactor=self.reactor, address=outbound_socket)
server_endpoint.listen(server_factory)

Expand Down
2 changes: 1 addition & 1 deletion hathor/multiprocess/node_ipc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_vertex(self, vertex_id: VertexId) -> dict[str, Any]:
return dict(vertex_bytes=[bytes(vertex), vertex.static_metadata.json_dumpb()])


class NodeIpcServerFactor(ServerFactory):
class NodeIpcServerFactory(ServerFactory):
__slots__ = ('vertex_parser', 'vertex_handler', 'tx_storage')

def __init__(self, *, vertex_parser: VertexParser, vertex_handler: VertexHandler, tx_storage: TransactionStorage) -> None:
Expand Down
5 changes: 3 additions & 2 deletions hathor/multiprocess/p2p_ipc_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ async def main(reactor: ReactorProtocol, settings: HathorSettings, inbound_socke
),
hostname=None,
)

# TODO: Hardcoded configs
p2p_manager.add_peer_discovery(DNSPeerDiscovery(settings.BOOTSTRAP_DNS))
p2p_manager.localhost_only = True

server_factory = P2PIpcServerFactory(p2p_manager=p2p_manager)
server_endpoint = UNIXServerEndpoint(reactor=reactor, address=outbound_socket)
server_endpoint.listen(server_factory)

if __name__ == '__main__':
# import pydevd_pycharm
# pydevd_pycharm.settrace('localhost', port=8090, stdoutToServer=True, stderrToServer=True)
_, inbound_socket, outbound_socket = sys.argv
reactor = initialize_global_reactor()
settings = get_global_settings()
Expand Down
2 changes: 1 addition & 1 deletion hathor/storage/rocksdb_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, path: str = './', cache_capacity: Optional[int] = None, *, op
column_families = {cf: rocksdb.ColumnFamilyOptions() for cf in cf_names}

# finally, open the database
self._db = rocksdb.DB(db_path, options, column_families=column_families, secondary_path=secondary_path)
self._db = rocksdb.DB(db_path, options, column_families=column_families)
self.log.debug('open db', cf_list=[cf.name.decode('ascii') for cf in self._db.column_families])

def get_db(self) -> 'rocksdb.DB':
Expand Down

0 comments on commit df2f44e

Please sign in to comment.