Skip to content

Commit

Permalink
Parameterize leader id in config
Browse files Browse the repository at this point in the history
  • Loading branch information
koirikivi committed Feb 15, 2024
1 parent dc7a4e2 commit f5004a4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion bridge_node/bridge/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
class Config:
node_id = environ.var()
hostname = environ.var(socket.gethostname())
leader_node_id = environ.var()
port = environ.var(5000, converter=int)
peers = environ.var(converter=lambda s: [x.split("@") for x in s.split(",")])

evm_bridge_contract_address = environ.var()
evm_rpc_url = environ.var()
evm_block_safety_margin = environ.var(converter=int, default=5)
evm_start_block = environ.var(converter=int, default=1)
peers = environ.var(converter=lambda s: [x.split("@") for x in s.split(",")])


btc_network: Literal["mainnet", "testnet", "signet", "regtest"] = environ.var()

tap_host = environ.var()
Expand Down
2 changes: 1 addition & 1 deletion bridge_node/bridge/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _handle_transfers_to_tap(self, transfers: list[TransferToTap]):
transfer,
)

# TODO: vpsbt shenanigans
# TODO: proper VPSBT handling with proof transfers
ret = self.tap_client.send_assets(
*[
t.recipient_tap_address
Expand Down
7 changes: 5 additions & 2 deletions bridge_node/bridge/p2p/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ def __init__(
peers,
context_cls: SecureContext = None,
privkey=None,
leader_node_id=None,
):
self.host = host
self.port = port
self.node_id = node_id
self.leader_node_id = leader_node_id
self.context = None
self.privkey = privkey

Expand Down Expand Up @@ -94,8 +96,8 @@ def create_daemon(self, context_cls: SecureContext | Any = None):
self.uri = self.daemon.register(self, self.node_id)

def is_leader(self) -> bool:
# TODO: temporary implementation
return self.node_id == "node-1"
# Leader is hardcoded in config
return self.node_id == self.leader_node_id

def ask(self, question: str, **kwargs: Any):
logger.debug(
Expand Down Expand Up @@ -225,6 +227,7 @@ def create_pyro_network(container: Container):
peers=config.peers,
context_cls=PyroSecureContext,
privkey=config.evm_private_key,
leader_node_id=config.leader_node_id,
)

# TODO: VERY UGLY! But we don't want to crash on startup if network not started
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ services:
# NOTE: the private keys and other secrets are supposed to be here -- they are not used in the real world, only regtest. Don't report them.
- BRIDGE_NODE_ID=node-1
- BRIDGE_HOSTNAME=bridge-node-1
- BRIDGE_LEADER_NODE_ID=node-1
- BRIDGE_DB_URL=postgresql://bridge1:a5f83ab52f2c6c8d0a31e99c@postgres:5432/bridge1
- LOG_LEVEL=DEBUG
- BRIDGE_EVM_PRIVATE_KEY=0x9a9a640da1fc0181e43a9ea00b81878f26e1678e3e246b25bd2835783f2be181
Expand Down Expand Up @@ -92,6 +93,7 @@ services:
# NOTE: the private keys and other secrets are supposed to be here -- they are not used in the real world, only regtest. Don't report them.
- BRIDGE_NODE_ID=node-2
- BRIDGE_HOSTNAME=bridge-node-2
- BRIDGE_LEADER_NODE_ID=node-1
- BRIDGE_DB_URL=postgresql://bridge2:b2a8658e648ddc59b5172dfe@postgres:5432/bridge2
- LOG_LEVEL=DEBUG
- BRIDGE_EVM_PRIVATE_KEY=0x034262349de8b7bb1d8fdd7a9b6096aae0906a8f3b58ecc31af58b9f9a30e567
Expand Down

0 comments on commit f5004a4

Please sign in to comment.