From 1cf8c088d3c564080c3cd0acc893eb158de90586 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Thu, 13 Jun 2024 12:58:57 +0900 Subject: [PATCH] Added some clarifications --- Libplanet.Net/Consensus/ConsensusContext.cs | 40 ++++++++++++++------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/Libplanet.Net/Consensus/ConsensusContext.cs b/Libplanet.Net/Consensus/ConsensusContext.cs index 49eff93798e..cb70301f067 100644 --- a/Libplanet.Net/Consensus/ConsensusContext.cs +++ b/Libplanet.Net/Consensus/ConsensusContext.cs @@ -14,8 +14,18 @@ namespace Libplanet.Net.Consensus { /// - /// A class that maintains the states of a for block - /// indices now in consensus. + /// + /// A class that maintains a collection of s. + /// + /// + /// Internally, multiple s may be managed at any given time. + /// In particular, a with its that + /// is greater than may be created preemptively to hold + /// s to be processed at later time. Furthermore, + /// it is guaranteed that no with its + /// less than , as any such is disposed + /// when is updated. + /// /// public partial class ConsensusContext : IDisposable { @@ -75,12 +85,19 @@ public ConsensusContext( } /// - /// The index of block that is watching. The value can be - /// changed by starting a consensus or appending a block. + /// + /// The height of the current running . + /// + /// + /// This is initially set to -1, representing that there is no running + /// , when a is created. + /// This value can only be increased by calling . + /// /// - /// /// If or is called /// before, returns current working height, otherwise returns -1. + /// + /// public long Height { get; private set; } /// @@ -176,16 +193,16 @@ public void NewHeight(long height) ? _contexts[height - 1].GetBlockCommit() : null; _logger.Debug( - "LastCommit of height #{Height} is: {LastCommit}", + "LastCommit of height #{Height} is {LastCommit}", Height, lastCommit); - if (lastCommit == null) + if (lastCommit is null) { BlockCommit? storedCommit = _blockChain.GetBlockCommit(height - 1); - if (storedCommit != null) + if (storedCommit is { } commit) { - lastCommit = storedCommit; + lastCommit = commit; _logger.Debug( "Found cached LastCommit of Height #{Height} " + "and Round #{Round}", @@ -195,11 +212,10 @@ public void NewHeight(long height) } } - Height = height; - _logger.Information("Start consensus for height #{Height}", Height); lock (_contextLock) { + Height = height; if (!_contexts.ContainsKey(height)) { _contexts[height] = CreateContext(height); @@ -391,7 +407,7 @@ public override string ToString() /// The event arguments given by /// as a tuple of the old tip and the new tip. /// - private void OnTipChanged(object? sender, (Block OldTip, Block NewTip) e) + private void OnTipChanged(object? sender, (Block _, Block NewTip) e) { // TODO: Should set delay by using GST. _newHeightCts?.Cancel();