Skip to content

Commit

Permalink
Fix asynchromix example
Browse files Browse the repository at this point in the history
* Catch web3 tx not found exception (API changed in versions > 5.0.0)
* Fix missing one_minus_ones elements
* Refresh the cache of preprocessed elements after the writing to file
  step is done. There was a line `pp_elements.init_mixins()` which looks
  like it was expected to do something similar but the method
  (`init_mixins()`) does not exist. Perhaps it can be implemented in the
  future.

Related to initc3#425
  • Loading branch information
sbellem committed Mar 4, 2020
1 parent b15b7fd commit 095cf04
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
37 changes: 30 additions & 7 deletions apps/asynchromix/asynchromix.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from web3 import HTTPProvider, Web3
from web3.contract import ConciseContract
from web3.exceptions import TransactionNotFound

from apps.asynchromix.butterfly_network import iterated_butterfly_network

Expand All @@ -36,7 +37,10 @@

async def wait_for_receipt(w3, tx_hash):
while True:
tx_receipt = w3.eth.getTransactionReceipt(tx_hash)
try:
tx_receipt = w3.eth.getTransactionReceipt(tx_hash)
except TransactionNotFound:
tx_receipt = None
if tx_receipt is not None:
break
await asyncio.sleep(5)
Expand Down Expand Up @@ -349,18 +353,28 @@ async def prog(ctx):
pp_elements._init_data_dir()

# Overwrite triples and one_minus_ones
for kind, elems in zip(("triples", "one_minus_one"), (triples, bits)):
logging.info("overwriting triples and one_minus_ones")
for kind, elems in zip(("triples", "one_minus_ones"), (triples, bits)):
if kind == "triples":
elems = flatten_lists(elems)
elems = [e.value for e in elems]

mixin = pp_elements.mixins[kind]
# mixin = pp_elements.mixins[kind]
mixin = getattr(pp_elements, f"_{kind}")
mixin_filename = mixin.build_filename(ctx.N, ctx.t, ctx.myid)
logging.info(
f"writing preprocessed {kind} to file {mixin_filename}"
)
logging.info(f"number of elements is: {len(elems)}")
mixin._write_preprocessing_file(
mixin_filename, ctx.t, ctx.myid, elems, append=False
)

pp_elements._init_mixins()
# FIXME Not sure what this is supposed to be ...
# the method does not exist.
# pp_elements._init_mixins()
pp_elements._triples._refresh_cache()
pp_elements._one_minus_ones._refresh_cache()

logging.info(f"[{ctx.myid}] Running permutation network")
inps = list(map(ctx.Share, inputs))
Expand Down Expand Up @@ -419,9 +433,17 @@ async def _mixing_initiate_loop(self):
await asyncio.sleep(5)

# Step 4.b. Call initiate mix
tx_hash = self.contract.functions.initiate_mix().transact(
{"from": self.w3.eth.accounts[0]}
)
try:
tx_hash = self.contract.functions.initiate_mix().transact(
{"from": self.w3.eth.accounts[0]}
)
except ValueError as err:
logging.info("\n")
logging.info(79 * "*")
logging.info(err)
logging.info(79 * "*")
logging.info("\n")
continue
tx_receipt = await wait_for_receipt(self.w3, tx_hash)
rich_logs = self.contract.events.MixingEpochInitiated().processReceipt(
tx_receipt
Expand Down Expand Up @@ -484,6 +506,7 @@ async def main_loop(w3):
]

# Step 3. Create the client
# TODO communicate with server instead of fetching from list of servers
async def req_mask(i, idx):
# client requests input mask {idx} from server {i}
return servers[i]._inputmasks[idx]
Expand Down
4 changes: 2 additions & 2 deletions honeybadgermpc/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PreProcessingConstants(Enum):
BITS = "bits"
POWERS = "powers"
SHARES = "share"
ONE_MINUS_ONE = "one_minus_one"
ONE_MINUS_ONES = "one_minus_ones"
DOUBLE_SHARES = "double_shares"
SHARE_BITS = "share_bits"

Expand Down Expand Up @@ -487,7 +487,7 @@ def _generate_polys(self, k, n, t):


class SignedBitPreProcessing(SimplePreProcessing):
preprocessing_name = PreProcessingConstants.ONE_MINUS_ONE.value
preprocessing_name = PreProcessingConstants.ONE_MINUS_ONES.value
_preprocessing_stride = 1

def _generate_polys(self, k, n, t):
Expand Down

0 comments on commit 095cf04

Please sign in to comment.