From c1a205dcda815dbc48f332674fd5610c1ca40e1b Mon Sep 17 00:00:00 2001 From: Chanhyuck Ko Date: Thu, 12 Dec 2024 19:35:52 +0900 Subject: [PATCH] refactor: apply suggestions from the review --- src/Libplanet.Net/Consensus/Context.Mutate.cs | 6 +-- src/Libplanet.Net/Consensus/Context.cs | 38 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Libplanet.Net/Consensus/Context.Mutate.cs b/src/Libplanet.Net/Consensus/Context.Mutate.cs index fa5b6892b2..6417befbe8 100644 --- a/src/Libplanet.Net/Consensus/Context.Mutate.cs +++ b/src/Libplanet.Net/Consensus/Context.Mutate.cs @@ -29,7 +29,7 @@ private void StartRound(int round) RoundStarted?.Invoke(this, Round); _heightVoteSet.SetRound(round); - SetProposal(null); + Proposal = null; Step = ConsensusStep.Propose; if (_validatorSet.GetProposer(Height, Round).PublicKey == _privateKey.PublicKey) { @@ -214,7 +214,7 @@ private void AddProposal(Proposal proposal) if (Proposal is null) { - SetProposal(proposal); + Proposal = proposal; _logger.Debug("Proposal {BlockHash} is set", proposal.BlockHash); } else @@ -341,7 +341,7 @@ private void ProcessGenericUponRules() Round, hash3, ToString()); - SetProposal(null); + Proposal = null; PublishMessage( new ConsensusProposalClaimMsg( new ProposalClaimMetadata( diff --git a/src/Libplanet.Net/Consensus/Context.cs b/src/Libplanet.Net/Consensus/Context.cs index 982ae153d7..daa7f0063e 100644 --- a/src/Libplanet.Net/Consensus/Context.cs +++ b/src/Libplanet.Net/Consensus/Context.cs @@ -100,6 +100,7 @@ private readonly EvidenceExceptionCollector _evidenceCollector private readonly ILogger _logger; private readonly LRUCache _blockValidationCache; + private Proposal? _proposal; private Block? _proposalBlock; private Block? _lockedValue; private int _lockedRound; @@ -219,7 +220,24 @@ private Context( /// public ConsensusStep Step { get; private set; } - public Proposal? Proposal { get; private set; } + public Proposal? Proposal + { + get => _proposal; + private set + { + if (value is { } p) + { + _proposal = p; + _proposalBlock = + BlockMarshaler.UnmarshalBlock((Dictionary)_codec.Decode(p.MarshaledBlock)); + } + else + { + _proposal = null; + _proposalBlock = null; + } + } + } /// public void Dispose() @@ -589,24 +607,6 @@ private Maj23 MakeMaj23(int round, BlockHash hash, VoteFlag flag) flag).Sign(_privateKey); } - /// - /// Sets the proposal for the round. - /// - private void SetProposal(Proposal? proposal) - { - if (proposal is { } p) - { - Proposal = proposal; - _proposalBlock = - BlockMarshaler.UnmarshalBlock((Dictionary)_codec.Decode(p.MarshaledBlock)); - } - else - { - Proposal = null; - _proposalBlock = null; - } - } - /// /// Gets the proposed block and valid round of the given round. ///