diff --git a/neo.UnitTests/UT_Consensus.cs b/neo.UnitTests/UT_Consensus.cs index 741241978d..b1608e1879 100644 --- a/neo.UnitTests/UT_Consensus.cs +++ b/neo.UnitTests/UT_Consensus.cs @@ -52,9 +52,8 @@ public void ConsensusService_Primary_Sends_PrepareRequest_After_OnStart() mockConsensusContext.SetupProperty(mr => mr.Nonce); mockConsensusContext.SetupProperty(mr => mr.NextConsensus); mockConsensusContext.Object.NextConsensus = UInt160.Zero; - mockConsensusContext.Setup(mr => mr.GetPrimaryIndex(It.IsAny())).Returns(2); - mockConsensusContext.SetupProperty(mr => mr.State); // allows get and set to update mock state on Initialize method - mockConsensusContext.Object.State = ConsensusState.Initial; + mockConsensusContext.SetupGet(mr => mr.PreparationPayloads).Returns(new ConsensusPayload[7]); + mockConsensusContext.SetupGet(mr => mr.CommitPayloads).Returns(new ConsensusPayload[7]); int timeIndex = 0; var timeValues = new[] { @@ -177,7 +176,6 @@ public void ConsensusService_Primary_Sends_PrepareRequest_After_OnStart() public void TestSerializeAndDeserializeConsensusContext() { var consensusContext = new ConsensusContext(null); - consensusContext.State = ConsensusState.CommitSent; consensusContext.PrevHash = UInt256.Parse("0xd42561e3d30e15be6400b6df2f328e02d2bf6354c41dce433bc57687c82144bf"); consensusContext.BlockIndex = 1; consensusContext.ViewNumber = 2; @@ -252,7 +250,6 @@ public void TestSerializeAndDeserializeConsensusContext() var copiedContext = TestUtils.CopyMsgBySerialization(consensusContext, new ConsensusContext(null)); - copiedContext.State.Should().Be(consensusContext.State); copiedContext.PrevHash.Should().Be(consensusContext.PrevHash); copiedContext.BlockIndex.Should().Be(consensusContext.BlockIndex); copiedContext.ViewNumber.Should().Be(consensusContext.ViewNumber); diff --git a/neo/Consensus/ConsensusContext.cs b/neo/Consensus/ConsensusContext.cs index 626a5b2931..eecd7caab7 100644 --- a/neo/Consensus/ConsensusContext.cs +++ b/neo/Consensus/ConsensusContext.cs @@ -32,14 +32,11 @@ internal class ConsensusContext : IConsensusContext public ConsensusPayload[] CommitPayloads { get; set; } public ConsensusPayload[] ChangeViewPayloads { get; set; } public ConsensusPayload[] LastChangeViewPayloads { get; set; } - public ConsensusState State { get; set; } + public Block Block { get; set; } public Snapshot Snapshot { get; private set; } private KeyPair keyPair; private readonly Wallet wallet; - public int F => (Validators.Length - 1) / 3; - public int M => Validators.Length - F; - public Header PrevHeader => Snapshot.GetHeader(PrevHash); public int Size => throw new NotImplementedException(); public ConsensusContext(Wallet wallet) @@ -49,19 +46,22 @@ public ConsensusContext(Wallet wallet) public Block CreateBlock() { - Block block = MakeHeader(); - if (block == null) return null; - Contract contract = Contract.CreateMultiSigContract(M, Validators); - ContractParametersContext sc = new ContractParametersContext(block); - for (int i = 0, j = 0; i < Validators.Length && j < M; i++) + if (Block is null) { - if (CommitPayloads[i] == null) continue; - sc.AddSignature(contract, Validators[i], CommitPayloads[i].GetDeserializedMessage().Signature); - j++; + Block = MakeHeader(); + if (Block == null) return null; + Contract contract = Contract.CreateMultiSigContract(this.M(), Validators); + ContractParametersContext sc = new ContractParametersContext(Block); + for (int i = 0, j = 0; i < Validators.Length && j < this.M(); i++) + { + if (CommitPayloads[i] == null) continue; + sc.AddSignature(contract, Validators[i], CommitPayloads[i].GetDeserializedMessage().Signature); + j++; + } + sc.Verifiable.Witnesses = sc.GetWitnesses(); + Block.Transactions = TransactionHashes.Select(p => Transactions[p]).ToArray(); } - sc.Verifiable.Witnesses = sc.GetWitnesses(); - block.Transactions = TransactionHashes.Select(p => Transactions[p]).ToArray(); - return block; + return Block; } public void Deserialize(BinaryReader reader) @@ -102,7 +102,6 @@ public void Deserialize(BinaryReader reader) LastChangeViewPayloads = new ConsensusPayload[reader.ReadVarInt()]; for (int i = 0; i < LastChangeViewPayloads.Length; i++) LastChangeViewPayloads[i] = reader.ReadBoolean() ? reader.ReadSerializable() : null; - State = (ConsensusState)reader.ReadByte(); } public void Dispose() @@ -110,12 +109,6 @@ public void Dispose() Snapshot?.Dispose(); } - public uint GetPrimaryIndex(byte viewNumber) - { - int p = ((int)BlockIndex - viewNumber) % Validators.Length; - return p >= 0 ? (uint)p : (uint)(p + Validators.Length); - } - public ConsensusPayload MakeChangeView(byte newViewNumber) { return ChangeViewPayloads[MyIndex] = MakeSignedPayload(new ChangeView @@ -188,7 +181,8 @@ private void SignPayload(ConsensusPayload payload) public ConsensusPayload MakePrepareRequest() { - return MakeSignedPayload(new PrepareRequest + Fill(); + return PreparationPayloads[MyIndex] = MakeSignedPayload(new PrepareRequest { Timestamp = Timestamp, Nonce = Nonce, @@ -215,12 +209,12 @@ public ConsensusPayload MakeRecoveryMessage() } return MakeSignedPayload(new RecoveryMessage() { - ChangeViewMessages = LastChangeViewPayloads.Where(p => p != null).Select(p => RecoveryMessage.ChangeViewPayloadCompact.FromPayload(p)).Take(M).ToDictionary(p => (int)p.ValidatorIndex), + 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().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 = State.HasFlag(ConsensusState.CommitSent) + CommitMessages = this.CommitSent() ? CommitPayloads.Where(p => p != null).Select(p => RecoveryMessage.CommitPayloadCompact.FromPayload(p)).ToDictionary(p => (int)p.ValidatorIndex) : new Dictionary() }); @@ -264,9 +258,8 @@ public void Reset(byte viewNumber) else LastChangeViewPayloads[i] = null; } - State = ConsensusState.Initial; ViewNumber = viewNumber; - PrimaryIndex = GetPrimaryIndex(viewNumber); + PrimaryIndex = this.GetPrimaryIndex(viewNumber); Timestamp = 0; TransactionHashes = null; PreparationPayloads = new ConsensusPayload[Validators.Length]; @@ -317,10 +310,9 @@ public void Serialize(BinaryWriter writer) if (!hasPayload) continue; writer.Write(payload); } - writer.Write((byte)State); } - public void Fill() + private void Fill() { IEnumerable memoryPoolTransactions = Blockchain.Singleton.MemPool.GetSortedVerifiedTransactions(); foreach (IPolicyPlugin plugin in Plugin.Policies) @@ -354,7 +346,7 @@ public void Fill() TransactionHashes = transactions.Select(p => p.Hash).ToArray(); Transactions = transactions.ToDictionary(p => p.Hash); NextConsensus = Blockchain.GetConsensusAddress(Snapshot.GetValidators(transactions).ToArray()); - Timestamp = Math.Max(TimeProvider.Current.UtcNow.ToTimestamp(), PrevHeader.Timestamp + 1); + Timestamp = Math.Max(TimeProvider.Current.UtcNow.ToTimestamp(), this.PrevHeader().Timestamp + 1); } private static ulong GetNonce() @@ -364,15 +356,5 @@ private static ulong GetNonce() rand.NextBytes(nonce); return nonce.ToUInt64(0); } - - public bool VerifyRequest() - { - if (!Blockchain.GetConsensusAddress(Snapshot.GetValidators(Transactions.Values).ToArray()).Equals(NextConsensus)) - return false; - Transaction minerTx = Transactions.Values.FirstOrDefault(p => p.Type == TransactionType.MinerTransaction); - Fixed8 amountNetFee = Block.CalculateNetFee(Transactions.Values); - if (minerTx?.Outputs.Sum(p => p.Value) != amountNetFee) return false; - return true; - } } } diff --git a/neo/Consensus/ConsensusService.cs b/neo/Consensus/ConsensusService.cs index ce8e3faa63..a8e23ec1bc 100644 --- a/neo/Consensus/ConsensusService.cs +++ b/neo/Consensus/ConsensusService.cs @@ -65,14 +65,13 @@ private bool AddTransaction(Transaction tx, bool verify) context.Transactions[tx.Hash] = tx; if (context.TransactionHashes.Length == context.Transactions.Count) { - if (context.VerifyRequest()) + if (VerifyRequest()) { // if we are the primary for this view, but acting as a backup because we recovered our own // previously sent prepare request, then we don't want to send a prepare response. if (context.MyIndex == context.PrimaryIndex) return true; Log($"send prepare response"); - context.State |= ConsensusState.ResponseSent; localNode.Tell(new LocalNode.SendDirectly { Inventory = context.MakePrepareResponse() }); CheckPreparations(); } @@ -97,19 +96,18 @@ private void ChangeTimer(TimeSpan delay) private void CheckCommits() { - if (context.CommitPayloads.Count(p => p != null) >= context.M && context.TransactionHashes.All(p => context.Transactions.ContainsKey(p))) + if (context.CommitPayloads.Count(p => p != null) >= context.M() && context.TransactionHashes.All(p => context.Transactions.ContainsKey(p))) { Block block = context.CreateBlock(); Log($"relay block: {block.Hash}"); localNode.Tell(new LocalNode.Relay { Inventory = block }); - context.State |= ConsensusState.BlockSent; } } private void CheckExpectedView(byte viewNumber) { if (context.ViewNumber == viewNumber) return; - if (context.ChangeViewPayloads.Count(p => p != null && p.GetDeserializedMessage().NewViewNumber == viewNumber) >= context.M) + if (context.ChangeViewPayloads.Count(p => p != null && p.GetDeserializedMessage().NewViewNumber == viewNumber) >= context.M()) { ChangeView message = context.ChangeViewPayloads[context.MyIndex]?.GetDeserializedMessage(); if (message is null || message.NewViewNumber < viewNumber) @@ -120,11 +118,10 @@ private void CheckExpectedView(byte viewNumber) private void CheckPreparations() { - if (context.PreparationPayloads.Count(p => p != null) >= context.M && context.TransactionHashes.All(p => context.Transactions.ContainsKey(p))) + if (context.PreparationPayloads.Count(p => p != null) >= context.M() && context.TransactionHashes.All(p => context.Transactions.ContainsKey(p))) { ConsensusPayload payload = context.MakeCommit(); Log($"send commit"); - context.State |= ConsensusState.CommitSent; context.Save(store); localNode.Tell(new LocalNode.SendDirectly { Inventory = payload }); // Set timer, so we will resend the commit in case of a networking issue @@ -148,10 +145,9 @@ private void InitializeConsensus(byte viewNumber) if (context.MyIndex < 0) return; if (viewNumber > 0) Log($"changeview: view={viewNumber} primary={context.Validators[context.GetPrimaryIndex((byte)(viewNumber - 1u))]}", LogLevel.Warning); - Log($"initialize: height={context.BlockIndex} view={viewNumber} index={context.MyIndex} role={(context.MyIndex == context.PrimaryIndex ? ConsensusState.Primary : ConsensusState.Backup)}"); - if (context.MyIndex == context.PrimaryIndex) + Log($"initialize: height={context.BlockIndex} view={viewNumber} index={context.MyIndex} role={(context.IsPrimary() ? "Primary" : "Backup")}"); + if (context.IsPrimary()) { - context.State |= ConsensusState.Primary; if (isRecovering) { ChangeTimer(TimeSpan.FromSeconds(Blockchain.SecondsPerBlock << (viewNumber + 1))); @@ -167,7 +163,6 @@ private void InitializeConsensus(byte viewNumber) } else { - context.State = ConsensusState.Backup; ChangeTimer(TimeSpan.FromSeconds(Blockchain.SecondsPerBlock << (viewNumber + 1))); } } @@ -190,7 +185,7 @@ private void OnChangeViewReceived(ConsensusPayload payload, ChangeView message) { bool shouldSendRecovery = false; // Limit recovery to sending from `f` nodes when the request is from a lower view number. - int allowedRecoveryNodeCount = context.F; + int allowedRecoveryNodeCount = context.F(); for (int i = 0; i < allowedRecoveryNodeCount; i++) { var eligibleResponders = context.Validators.Length - 1; @@ -234,7 +229,7 @@ private void OnCommitReceived(ConsensusPayload payload, Commit commit) private void OnConsensusPayload(ConsensusPayload payload) { - if (context.State.HasFlag(ConsensusState.BlockSent)) return; + if (context.BlockSent()) return; if (payload.Version != ConsensusContext.Version) return; if (payload.PrevHash != context.PrevHash || payload.BlockIndex != context.BlockIndex) { @@ -286,21 +281,20 @@ private void OnRecoveryMessageReceived(ConsensusPayload payload, RecoveryMessage { if (message.ViewNumber > context.ViewNumber) { - if (context.State.HasFlag(ConsensusState.CommitSent)) - return; + if (context.CommitSent()) return; ConsensusPayload[] changeViewPayloads = message.GetChangeViewPayloads(context, payload); foreach (ConsensusPayload changeViewPayload in changeViewPayloads) ReverifyAndProcessPayload(changeViewPayload); } if (message.ViewNumber != context.ViewNumber) return; - if (!context.State.HasFlag(ConsensusState.CommitSent)) + if (!context.CommitSent()) { - if (!context.State.HasFlag(ConsensusState.RequestSent) && !context.State.HasFlag(ConsensusState.RequestReceived)) + if (!context.RequestSentOrReceived()) { ConsensusPayload prepareRequestPayload = message.GetPrepareRequestPayload(context, payload); if (prepareRequestPayload != null) ReverifyAndProcessPayload(prepareRequestPayload); - else if (context.State.HasFlag(ConsensusState.Primary)) + else if (context.IsPrimary()) SendPrepareRequest(); } ConsensusPayload[] prepareResponsePayloads = message.GetPrepareResponsePayloads(context, payload); @@ -319,11 +313,10 @@ private void OnRecoveryMessageReceived(ConsensusPayload payload, RecoveryMessage private void OnPrepareRequestReceived(ConsensusPayload payload, PrepareRequest message) { - if (context.State.HasFlag(ConsensusState.RequestSent) || context.State.HasFlag(ConsensusState.RequestReceived)) - return; + if (context.RequestSentOrReceived()) return; if (payload.ValidatorIndex != context.PrimaryIndex) return; Log($"{nameof(OnPrepareRequestReceived)}: height={payload.BlockIndex} view={message.ViewNumber} index={payload.ValidatorIndex} tx={message.TransactionHashes.Length}"); - if (message.Timestamp <= context.PrevHeader.Timestamp || message.Timestamp > TimeProvider.Current.UtcNow.AddMinutes(10).ToTimestamp()) + if (message.Timestamp <= context.PrevHeader().Timestamp || message.Timestamp > TimeProvider.Current.UtcNow.AddMinutes(10).ToTimestamp()) { Log($"Timestamp incorrect: {message.Timestamp}", LogLevel.Warning); return; @@ -333,9 +326,6 @@ private void OnPrepareRequestReceived(ConsensusPayload payload, PrepareRequest m Log($"Invalid request: transaction already exists", LogLevel.Warning); return; } - context.State |= context.State.HasFlag(ConsensusState.Primary) - ? ConsensusState.RequestSent - : ConsensusState.RequestReceived; context.Timestamp = message.Timestamp; context.Nonce = message.Nonce; context.NextConsensus = message.NextConsensus; @@ -388,10 +378,8 @@ private void OnPrepareResponseReceived(ConsensusPayload payload, PrepareResponse return; Log($"{nameof(OnPrepareResponseReceived)}: height={payload.BlockIndex} view={message.ViewNumber} index={payload.ValidatorIndex}"); context.PreparationPayloads[payload.ValidatorIndex] = payload; - if (payload.ValidatorIndex == context.MyIndex) - context.State |= ConsensusState.ResponseSent; - if (context.State.HasFlag(ConsensusState.CommitSent)) return; - if (context.State.HasFlag(ConsensusState.RequestSent) || context.State.HasFlag(ConsensusState.RequestReceived)) + if (context.CommitSent()) return; + if (context.RequestSentOrReceived()) CheckPreparations(); } @@ -439,7 +427,7 @@ private void OnStart(Start options) Transactions = context.Transactions.Values }).Wait(); } - if (context.State.HasFlag(ConsensusState.CommitSent)) + if (context.CommitSent()) { CheckPreparations(); return; @@ -453,16 +441,16 @@ private void OnStart(Start options) private void OnTimer(Timer timer) { - if (context.State.HasFlag(ConsensusState.BlockSent)) return; + if (context.BlockSent()) return; if (timer.Height != context.BlockIndex || timer.ViewNumber != context.ViewNumber) return; - Log($"timeout: height={timer.Height} view={timer.ViewNumber} state={context.State}"); - if (context.State.HasFlag(ConsensusState.Primary) && !context.State.HasFlag(ConsensusState.RequestSent)) + Log($"timeout: height={timer.Height} view={timer.ViewNumber}"); + if (context.IsPrimary() && !context.RequestSentOrReceived()) { SendPrepareRequest(); } - else if ((context.State.HasFlag(ConsensusState.Primary) && context.State.HasFlag(ConsensusState.RequestSent)) || context.State.HasFlag(ConsensusState.Backup)) + else if ((context.IsPrimary() && context.RequestSentOrReceived()) || context.IsBackup()) { - if (context.State.HasFlag(ConsensusState.CommitSent)) + if (context.CommitSent()) { // Re-send commit periodically by sending recover message in case of a network issue. Log($"send recovery to resend commit"); @@ -479,12 +467,12 @@ private void OnTimer(Timer timer) private void OnTransaction(Transaction transaction) { if (transaction.Type == TransactionType.MinerTransaction) return; - if (!context.State.HasFlag(ConsensusState.Backup) || !context.State.HasFlag(ConsensusState.RequestReceived) || context.State.HasFlag(ConsensusState.ResponseSent) || context.State.HasFlag(ConsensusState.BlockSent)) + if (!context.IsBackup() || !context.RequestSentOrReceived() || context.ResponseSent() || context.BlockSent()) return; // If we are changing view but we already have enough preparation payloads to commit in the current view, // we must keep on accepting transactions in the current view to be able to create the block. - if (context.State.HasFlag(ConsensusState.ViewChanging) && - context.PreparationPayloads.Count(p => p != null) < context.M) return; + if (context.ViewChanging() && + context.PreparationPayloads.Count(p => p != null) < context.M()) return; if (context.Transactions.ContainsKey(transaction.Hash)) return; if (!context.TransactionHashes.Contains(transaction.Hash)) return; AddTransaction(transaction, true); @@ -505,11 +493,10 @@ public static Props Props(IActorRef localNode, IActorRef taskManager, Store stor private void RequestChangeView() { - context.State |= ConsensusState.ViewChanging; byte expectedView = context.ChangeViewPayloads[context.MyIndex]?.GetDeserializedMessage().NewViewNumber ?? 0; if (expectedView < context.ViewNumber) expectedView = context.ViewNumber; expectedView++; - Log($"request change view: height={context.BlockIndex} view={context.ViewNumber} nv={expectedView} state={context.State}"); + Log($"request change view: height={context.BlockIndex} view={context.ViewNumber} nv={expectedView}"); ChangeTimer(TimeSpan.FromSeconds(Blockchain.SecondsPerBlock << (expectedView + 1))); localNode.Tell(new LocalNode.SendDirectly { Inventory = context.MakeChangeView(expectedView) }); CheckExpectedView(expectedView); @@ -524,11 +511,7 @@ private void ReverifyAndProcessPayload(ConsensusPayload payload) private void SendPrepareRequest() { Log($"send prepare request: height={context.BlockIndex} view={context.ViewNumber}"); - context.Fill(); - ConsensusPayload prepareRequestPayload = context.MakePrepareRequest(); - localNode.Tell(new LocalNode.SendDirectly { Inventory = prepareRequestPayload }); - context.State |= ConsensusState.RequestSent; - context.PreparationPayloads[context.MyIndex] = prepareRequestPayload; + localNode.Tell(new LocalNode.SendDirectly { Inventory = context.MakePrepareRequest() }); if (context.TransactionHashes.Length > 1) { @@ -537,6 +520,16 @@ private void SendPrepareRequest() } ChangeTimer(TimeSpan.FromSeconds(Blockchain.SecondsPerBlock << (context.ViewNumber + 1))); } + + private bool VerifyRequest() + { + if (!Blockchain.GetConsensusAddress(context.Snapshot.GetValidators(context.Transactions.Values).ToArray()).Equals(context.NextConsensus)) + return false; + Transaction minerTx = context.Transactions.Values.FirstOrDefault(p => p.Type == TransactionType.MinerTransaction); + Fixed8 amountNetFee = Block.CalculateNetFee(context.Transactions.Values); + if (minerTx?.Outputs.Sum(p => p.Value) != amountNetFee) return false; + return true; + } } internal class ConsensusServiceMailbox : PriorityMailbox diff --git a/neo/Consensus/ConsensusState.cs b/neo/Consensus/ConsensusState.cs deleted file mode 100644 index 989822c299..0000000000 --- a/neo/Consensus/ConsensusState.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; - -namespace Neo.Consensus -{ - [Flags] - public enum ConsensusState : byte - { - Initial = 0x00, - Primary = 0x01, - Backup = 0x02, - RequestSent = 0x04, - RequestReceived = 0x08, - ResponseSent = 0x10, - CommitSent = 0x20, - BlockSent = 0x40, - ViewChanging = 0x80, - } -} diff --git a/neo/Consensus/Helper.cs b/neo/Consensus/Helper.cs index 9a5df8fe9f..450a579d68 100644 --- a/neo/Consensus/Helper.cs +++ b/neo/Consensus/Helper.cs @@ -1,4 +1,5 @@ using Neo.IO; +using Neo.Network.P2P.Payloads; using Neo.Persistence; using System.IO; @@ -11,6 +12,23 @@ internal static class Helper /// public const byte CN_Context = 0xf4; + public static int F(this IConsensusContext context) => (context.Validators.Length - 1) / 3; + public static int M(this IConsensusContext context) => context.Validators.Length - context.F(); + public static bool IsPrimary(this IConsensusContext context) => context.MyIndex == context.PrimaryIndex; + public static bool IsBackup(this IConsensusContext context) => context.MyIndex >= 0 && context.MyIndex != context.PrimaryIndex; + public static Header PrevHeader(this IConsensusContext context) => context.Snapshot.GetHeader(context.PrevHash); + public static bool RequestSentOrReceived(this IConsensusContext context) => context.PreparationPayloads[context.PrimaryIndex] != null; + public static bool ResponseSent(this IConsensusContext context) => context.PreparationPayloads[context.MyIndex] != null; + public static bool CommitSent(this IConsensusContext context) => context.CommitPayloads[context.MyIndex] != null; + public static bool BlockSent(this IConsensusContext context) => context.Block != null; + public static bool ViewChanging(this IConsensusContext context) => context.ChangeViewPayloads[context.MyIndex]?.GetDeserializedMessage().NewViewNumber > context.ViewNumber; + + public static uint GetPrimaryIndex(this IConsensusContext context, byte viewNumber) + { + int p = ((int)context.BlockIndex - viewNumber) % context.Validators.Length; + return p >= 0 ? (uint)p : (uint)(p + context.Validators.Length); + } + public static void Save(this IConsensusContext context, Store store) { store.PutSync(CN_Context, new byte[0], context.ToArray()); diff --git a/neo/Consensus/IConsensusContext.cs b/neo/Consensus/IConsensusContext.cs index 3a99d33d61..5ce891e715 100644 --- a/neo/Consensus/IConsensusContext.cs +++ b/neo/Consensus/IConsensusContext.cs @@ -10,7 +10,6 @@ namespace Neo.Consensus public interface IConsensusContext : IDisposable, ISerializable { //public const uint Version = 0; - ConsensusState State { get; set; } UInt256 PrevHash { get; } uint BlockIndex { get; } byte ViewNumber { get; } @@ -25,19 +24,13 @@ public interface IConsensusContext : IDisposable, ISerializable ConsensusPayload[] PreparationPayloads { get; set; } ConsensusPayload[] CommitPayloads { get; set; } ConsensusPayload[] ChangeViewPayloads { get; set; } + Block Block { get; set; } Snapshot Snapshot { get; } - int F { get; } - int M { get; } - - Header PrevHeader { get; } - Block CreateBlock(); //void Dispose(); - uint GetPrimaryIndex(byte viewNumber); - ConsensusPayload MakeChangeView(byte newViewNumber); ConsensusPayload MakeCommit(); @@ -51,9 +44,5 @@ public interface IConsensusContext : IDisposable, ISerializable ConsensusPayload MakePrepareResponse(); void Reset(byte viewNumber); - - void Fill(); - - bool VerifyRequest(); } }