public ConsensusPayload MakeRecoveryMessage() { PrepareRequest prepareRequestMessage = null; if (TransactionHashes != null) { prepareRequestMessage = new PrepareRequest { ViewNumber = ViewNumber, TransactionHashes = TransactionHashes, Nonce = Nonce, NextConsensus = NextConsensus, MinerTransaction = (MinerTransaction)Transactions[TransactionHashes[0]], Timestamp = Timestamp }; } return(MakeSignedPayload(new RecoveryMessage() { ChangeViewMessages = LastChangeViewPayloads.Where(p => p != null).Select(p => RecoveryMessage.ChangeViewPayloadCompact.FromPayload(p)).Take(this.M()).ToDictionary(p => (int)p.ValidatorIndex), PrepareRequestMessage = prepareRequestMessage, // We only need a PreparationHash set if we don't have the PrepareRequest information. PreparationHash = TransactionHashes == null ? PreparationPayloads.Where(p => p != null).GroupBy(p => p.GetDeserializedMessage <PrepareResponse>().PreparationHash, (k, g) => new { Hash = k, Count = g.Count() }).OrderByDescending(p => p.Count).Select(p => p.Hash).FirstOrDefault() : null, PreparationMessages = PreparationPayloads.Where(p => p != null).Select(p => RecoveryMessage.PreparationPayloadCompact.FromPayload(p)).ToDictionary(p => (int)p.ValidatorIndex), CommitMessages = this.CommitSent() ? CommitPayloads.Where(p => p != null).Select(p => RecoveryMessage.CommitPayloadCompact.FromPayload(p)).ToDictionary(p => (int)p.ValidatorIndex) : new Dictionary <int, RecoveryMessage.CommitPayloadCompact>() })); }
public override void Deserialize(BinaryReader reader) { base.Deserialize(reader); ChangeViewMessages = reader.ReadSerializableArray <ChangeViewPayloadCompact>(Blockchain.MaxValidators).ToDictionary(p => (int)p.ValidatorIndex); if (reader.ReadBoolean()) { PrepareRequestMessage = reader.ReadSerializable <PrepareRequest>(); } else { int preparationHashSize = UInt256.Zero.Size; if (preparationHashSize == (int)reader.ReadVarInt((ulong)preparationHashSize)) { PreparationHash = new UInt256(reader.ReadBytes(preparationHashSize)); } } PreparationMessages = reader.ReadSerializableArray <PreparationPayloadCompact>(Blockchain.MaxValidators).ToDictionary(p => (int)p.ValidatorIndex); CommitMessages = reader.ReadSerializableArray <CommitPayloadCompact>(Blockchain.MaxValidators).ToDictionary(p => (int)p.ValidatorIndex); }