private void CheckResult() { if (_requested != ResultStatus.Requested) { return; } var(bestRootCnt, bestRoot) = _readyMessages .Where(x => x != null) .GroupBy(x => x !.MerkleTreeRoot) .Select(m => (cnt: m.Count(), key: m.Key)) .OrderByDescending(x => x.cnt) .FirstOrDefault(); if (bestRootCnt < 2 * F + 1) { return; } var matchingEchos = _echoMessages .WithIndex() .Where(t => bestRoot.Equals(t.item?.MerkleTreeRoot)) .Select(t => (echo: t.item !, t.index)) .Take(N - 2 * F) .ToArray(); if (matchingEchos.Length < N - 2 * F) { return; } var restored = DecodeFromEchos(matchingEchos); var len = restored.AsReadOnlySpan().Slice(0, 4).ToInt32(); var result = EncryptedShare.FromBytes(restored.AsMemory().Slice(4, len)); _requested = ResultStatus.Sent; Broadcaster.InternalResponse(new ProtocolResult <ReliableBroadcastId, EncryptedShare>(_broadcastId, result)); }
private void CheckSignatures() { Logger.LogTrace("CheckSignatures"); if (_header is null || _receipts is null || _blockProducer is null || _signatures.Count == 0) { Logger.LogTrace($"Not ready yet: _header {_header is null}, _hashes {_receipts is null}, _blockProducer {_blockProducer is null}, _signatures {_signatures.Count}"); return; } var bestHeader = _signatures .GroupBy( tuple => tuple.Item1, tuple => 1 ) .Select(p => new KeyValuePair <BlockHeader, int>(p.Key, p.Count())) .Aggregate((x, y) => x.Value > y.Value ? x : y); Logger.LogTrace($"bestHeader.Value {bestHeader.Value} Wallet.N {Wallet.N} Wallet.F {Wallet.F}"); if (bestHeader.Value < Wallet.N - Wallet.F) { return; } Logger.LogTrace($"Received {bestHeader.Value} signatures for block header"); _multiSig = new MultiSig { Quorum = (uint)(Wallet.N - Wallet.F) }; _multiSig.Validators.AddRange(Wallet.EcdsaPublicKeySet); foreach (var(header, signature) in _signatures) { if (header.Equals(bestHeader.Key)) { _multiSig.Signatures.Add(signature); } else { Logger.LogWarning($"Validator {signature.Key.ToHex()} signed wrong block header: {header}"); } } try { _blockProducer.ProduceBlock(_receipts, _header, _multiSig); } catch (Exception e) { Logger.LogError($"Cannot produce block because of {e}"); Terminate(); Environment.Exit(1); return; } Broadcaster.InternalResponse(new ProtocolResult <RootProtocolId, object?>(_rootId, null)); }
private void CheckResult() { if (_result == null) { return; } if (_requested != ResultStatus.Requested) { return; } Broadcaster.InternalResponse(new ProtocolResult <CoinId, CoinResult>(_coinId, _result)); Logger.LogTrace($"Player {GetMyId()}: made coin by {_coinId} and sent."); _requested = ResultStatus.Sent; }
private void CheckResult() { if (!_result.HasValue) { return; } if (_requested != ResultStatus.Requested) { return; } Logger.LogTrace($"{_broadcastId}: made result {_result.Value.ToString()}"); Broadcaster.InternalResponse( new ProtocolResult <BinaryBroadcastId, BoolSet>(_broadcastId, _result.Value)); _requested = ResultStatus.Sent; }
private void CheckResult() { if (_result == null) { return; } if (_requested == ResultStatus.Requested) { Broadcaster.InternalResponse( new ProtocolResult <BinaryAgreementId, bool>(_agreementId, (bool)_result)); _requested = ResultStatus.Sent; SetResult(); Logger.LogTrace($"{_agreementId}: made result at Ep={_currentEpoch}"); } }
private void CheckResult() { if (_result == null) { return; } if (_requested != ResultStatus.Requested) { return; } Logger.LogTrace($"Full result decrypted!"); _requested = ResultStatus.Sent; Broadcaster.InternalResponse( new ProtocolResult <HoneyBadgerId, ISet <IRawShare> >(_honeyBadgerId, _result)); }
private void CheckResult() { if (_result == null) { return; } if (_requested != ResultStatus.Requested) { return; } _requested = ResultStatus.Sent; SetResult(); // Logger.LogDebug($"{GetMyId()} ACS terminated."); Broadcaster.InternalResponse( new ProtocolResult <CommonSubsetId, ISet <EncryptedShare> >(_commonSubsetId, _result)); }