From 398a5bef30a7f41781dbaafff2467fc3689192ad Mon Sep 17 00:00:00 2001 From: Qiao Jin <43407364+Qiao-Jin@users.noreply.github.com> Date: Tue, 27 Oct 2020 20:32:25 +0800 Subject: [PATCH] Optimize NextConsensus (#2015) --- src/neo/Consensus/ConsensusContext.cs | 5 ++++- src/neo/SmartContract/Native/Tokens/NeoToken.cs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/neo/Consensus/ConsensusContext.cs b/src/neo/Consensus/ConsensusContext.cs index f711268fea..b1ac6b33f5 100644 --- a/src/neo/Consensus/ConsensusContext.cs +++ b/src/neo/Consensus/ConsensusContext.cs @@ -377,7 +377,10 @@ public void Reset(byte viewNumber) { PrevHash = Snapshot.CurrentBlockHash, Index = Snapshot.Height + 1, - NextConsensus = Blockchain.GetConsensusAddress(NativeContract.NEO.ComputeNextBlockValidators(Snapshot)) + NextConsensus = Blockchain.GetConsensusAddress( + NativeContract.NEO.ShouldRefreshCommittee(Snapshot.Height + 1) ? + NativeContract.NEO.ComputeNextBlockValidators(Snapshot) : + NativeContract.NEO.GetNextBlockValidators(Snapshot)) }; var pv = Validators; Validators = NativeContract.NEO.GetNextBlockValidators(Snapshot); diff --git a/src/neo/SmartContract/Native/Tokens/NeoToken.cs b/src/neo/SmartContract/Native/Tokens/NeoToken.cs index c831ca3ff8..3ba7408c17 100644 --- a/src/neo/SmartContract/Native/Tokens/NeoToken.cs +++ b/src/neo/SmartContract/Native/Tokens/NeoToken.cs @@ -94,7 +94,7 @@ private static void CheckCandidate(StoreView snapshot, StorageKey key, Candidate snapshot.Storages.Delete(key); } - private bool ShouldRefreshCommittee(uint height) => height % (ProtocolSettings.Default.CommitteeMembersCount + ProtocolSettings.Default.ValidatorsCount) == 0; + public bool ShouldRefreshCommittee(uint height) => height % (ProtocolSettings.Default.CommitteeMembersCount + ProtocolSettings.Default.ValidatorsCount) == 0; internal override void Initialize(ApplicationEngine engine) {