Skip to content

Commit

Permalink
refactor: apply suggestions from the review
Browse files Browse the repository at this point in the history
  • Loading branch information
limebell committed Dec 12, 2024
1 parent 1f4e1c9 commit c1a205d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/Libplanet.Net/Consensus/Context.Mutate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -341,7 +341,7 @@ private void ProcessGenericUponRules()
Round,
hash3,
ToString());
SetProposal(null);
Proposal = null;
PublishMessage(
new ConsensusProposalClaimMsg(
new ProposalClaimMetadata(
Expand Down
38 changes: 19 additions & 19 deletions src/Libplanet.Net/Consensus/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private readonly EvidenceExceptionCollector _evidenceCollector
private readonly ILogger _logger;
private readonly LRUCache<BlockHash, bool> _blockValidationCache;

private Proposal? _proposal;
private Block? _proposalBlock;
private Block? _lockedValue;
private int _lockedRound;
Expand Down Expand Up @@ -219,7 +220,24 @@ private Context(
/// </summary>
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;
}
}
}

/// <inheritdoc cref="IDisposable.Dispose()"/>
public void Dispose()
Expand Down Expand Up @@ -589,24 +607,6 @@ private Maj23 MakeMaj23(int round, BlockHash hash, VoteFlag flag)
flag).Sign(_privateKey);
}

/// <summary>
/// Sets the proposal for the round.
/// </summary>
private void SetProposal(Proposal? proposal)
{
if (proposal is { } p)
{
Proposal = proposal;
_proposalBlock =
BlockMarshaler.UnmarshalBlock((Dictionary)_codec.Decode(p.MarshaledBlock));
}
else
{
Proposal = null;
_proposalBlock = null;
}
}

/// <summary>
/// Gets the proposed block and valid round of the given round.
/// </summary>
Expand Down

0 comments on commit c1a205d

Please sign in to comment.