def _rpc_sign_callback(self, ctx, stub, rpc_future): try: response = rpc_future.result() if response.status.code != 0: raise RuntimeError("Failed to call rpc for psi sign, "\ "error code: {}, error message: {}".format( response.status.code, response.status.error_message)) ctx.trigger_rpc_finished() self._add_sign_stats(ctx.rpc_sign_duration(), ctx.rpc_pending_duration(), ctx.retry_cnt) self._revert_stub(stub, False) signed_blinded_hashed_ids = [bytes2int(item) for item in response.signed_ids] assert len(ctx.raw_id_batch) == len(signed_blinded_hashed_ids) self._deblind_signed_id_func(ctx.raw_id_batch, ctx.blind_numbers, signed_blinded_hashed_ids, ctx.notify_future) next_ctxs = [] with self._lock: assert self._flying_rpc_num > 0 self._flying_rpc_num -= 1 req_num = self._flying_sign_rpc_threshold - self._flying_rpc_num if req_num > 0: next_ctxs = self._pending_rpc_sign_ctx[:req_num] self._pending_rpc_sign_ctx = \ self._pending_rpc_sign_ctx[req_num:] for nctx in next_ctxs: self._rpc_sign_func(nctx) except Exception as e: # pylint: disable=broad-except self._revert_stub(stub, True) begin_index = ctx.raw_id_batch.begin_index end_index = begin_index + len(ctx.raw_id_batch) logging.warning("psi signer batch[%d, %d) sign "\ "failed for %d times, reson:%s. "\ "retry again", begin_index, end_index, ctx.retry_cnt, e) with self._lock: assert self._flying_rpc_num > 0 self._flying_rpc_num -= 1 ctx.trigger_retry() self._rpc_sign_func(ctx)
def _psi_sign_impl(items, d, n): byte_len = n.bit_length() // 8 return [ int2bytes(powmod(bytes2int(item), d, n).digits(), byte_len) for item in items ]