From 9ac15da7d3fc743aff23e10687c4b20bdcc61de5 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Mon, 13 May 2024 12:53:14 +0900 Subject: [PATCH] increase incentive tx size --- mixnet/v2/sim/node.py | 7 +++++-- mixnet/v2/sim/p2p.py | 2 +- mixnet/v2/sim/sphinx.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mixnet/v2/sim/node.py b/mixnet/v2/sim/node.py index 7e8b0e9..fd77b4c 100644 --- a/mixnet/v2/sim/node.py +++ b/mixnet/v2/sim/node.py @@ -12,6 +12,7 @@ class Node: N_MIXES_IN_PATH = 2 REAL_PAYLOAD = b"BLOCK" COVER_PAYLOAD = b"COVER" + INCENTIVE_TX_SIZE = 512 def __init__(self, id: int, env: simpy.Environment, p2p: P2p): self.id = id @@ -67,10 +68,12 @@ class Node: else: self.log("Received original message: %s" % msg) + # TODO: This is a dummy logic @classmethod def create_incentive_tx(cls, mix_public_key: X25519PublicKey) -> Attachment: - return Attachment( - mix_public_key.public_bytes(encoding=serialization.Encoding.Raw, format=serialization.PublicFormat.Raw)) + public_key = mix_public_key.public_bytes(encoding=serialization.Encoding.Raw, format=serialization.PublicFormat.Raw) + public_key += bytes(cls.INCENTIVE_TX_SIZE - len(public_key)) + return Attachment(public_key) def is_my_incentive_tx(self, tx: Attachment) -> bool: return tx == Node.create_incentive_tx(self.public_key) diff --git a/mixnet/v2/sim/p2p.py b/mixnet/v2/sim/p2p.py index 409bcc0..4f5244e 100644 --- a/mixnet/v2/sim/p2p.py +++ b/mixnet/v2/sim/p2p.py @@ -15,7 +15,7 @@ class P2p: # TODO: This should accept only bytes, but SphinxPacket is also accepted until we implement the Sphinx serde def broadcast(self, msg: SphinxPacket | bytes): - self.log("Broadcasting a msg") + self.log("Broadcasting a msg: %d bytes" % len(msg)) yield self.env.timeout(1) # TODO: gossipsub or something similar for node in self.nodes: diff --git a/mixnet/v2/sim/sphinx.py b/mixnet/v2/sim/sphinx.py index dafe75c..6a343e9 100644 --- a/mixnet/v2/sim/sphinx.py +++ b/mixnet/v2/sim/sphinx.py @@ -18,7 +18,7 @@ class SphinxPacket: def __bytes__(self): return bytes(self.header) + self.payload - def size(self) -> int: + def __len__(self): return len(bytes(self)) def unwrap(self, private_key: X25519PrivateKey) -> tuple[SphinxPacket, Attachment]: