increase incentive tx size

This commit is contained in:
Youngjoon Lee 2024-05-13 12:53:14 +09:00
parent 610d95a6fa
commit 9ac15da7d3
No known key found for this signature in database
GPG Key ID: 09B750B5BD6F08A2
3 changed files with 7 additions and 4 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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]: