From e794c4d438e213b0d178c45579c5f11343ea2d1c Mon Sep 17 00:00:00 2001 From: grimadas Date: Wed, 20 Sep 2023 01:34:06 +0200 Subject: [PATCH] Improve implementation of broadcast community: - Add latency simulation between peers - Separate client and full node --- src/bami/broadcast/community.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bami/broadcast/community.py b/src/bami/broadcast/community.py index dc5da5f..34a79fe 100644 --- a/src/bami/broadcast/community.py +++ b/src/bami/broadcast/community.py @@ -21,7 +21,7 @@ class MempoolBroadcastCommunity(Community): def __init__(self, *args, **kwargs) -> None: self.settings = kwargs.pop("settings", MempoolBroadcastSettings()) - super().__init__(*args, **kwargs) + super().__init__(*args, max_peers=1000, **kwargs) self.latency_sim = self.settings.simulate_network_latency self.pending_transactions = [] @@ -64,7 +64,6 @@ def ez_send(self, peer: Peer, *payloads: AnyPayload, **kwargs) -> None: # peer, payloads # delay=latency) - def create_introduction_request(self, socket_address, extra_bytes=b'', new_style=False, prefix=None): extra_bytes = self.is_transaction_creator.to_bytes(1, 'big') return super().create_introduction_request(socket_address, extra_bytes, new_style, prefix) @@ -228,16 +227,17 @@ def on_transaction_finalized(self, tx: TransactionPayload): @lazy_wrapper(HeaderPayload) def receive_header(self, p: Peer, header: HeaderPayload): """Receive new header""" - missing_batches = [b_obj.batch_id for b_obj in header.batches if b_obj.batch_id not in self.batches] + missing_batches = [b_obj for b_obj in header.batches if b_obj.batch_id not in self.batches] if len(missing_batches) > 0: self.ez_send(p, BatchRequestPayload(missing_batches)) # Add time to the missing batches header_id = payload_hash(header) - for batch_id in missing_batches: + for batch_obj in missing_batches: + batch_id = batch_obj.batch_id self.pending_batch_requests[batch_id] = get_event_loop().time() self.batch_to_header[batch_id] = header_id - self.awaited_headers[header_id] = set(missing_batches) + self.awaited_headers[header_id] = set([b_obj.batch_id for b_obj in missing_batches]) self.pending_headers[header_id] = header else: # trigger on new header