Skip to content

Commit

Permalink
chore: apply suggestions from the code review
Browse files Browse the repository at this point in the history
  • Loading branch information
limebell committed Jun 27, 2023
1 parent 4a653de commit c9089ae
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ To be released.
- Added `IAccountStateDeltaView.GetValidatorSet()` interface method.
[[#3247]]
- Added `IAccountStateDelta.SetValidator()` interface method. [[#3247]]
- `Vote.BlockHash` property became `BlockHash` type. (was `BlockHash?`)
[[#3249]]
- `VoteMetadata(long, int, BlockHash?, DateTimeOffset, PublicKey, VoteFlag)`
constructor became
`VoteMetadata(long, int, BlockHash, DateTimeOffset, PublicKey, VoteFlag)`
[[#3249]]
- (Libplanet.Net) Renamed `Step` enum to `ConsensusStep`
to remove ambiguity. [[#3249]]
- (Libplanet.Net) `ConsensusProposalMsg`, `ConsensusPreVoteMsg` and
`ConsensusPreCommitMsg` became to inherit `ConsensusVoteMsg`. [[#3249]]
- (Libplanet.Net) Removed `ConsensusMsg.BlockHash` property. [[#3249]]

### Backward-incompatible network protocol changes

Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Net/Consensus/Context.Mutate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private void ProcessGenericUponRules()
BroadcastMessage(
new ConsensusPreCommitMsg(MakeVote(Round, default, VoteFlag.PreCommit)));
}
else if (!(Proposal is null) && !hash3.Equals(Proposal.BlockHash))
else if (Proposal is { } proposal && !proposal.BlockHash.Equals(hash3))
{
// +2/3 votes were collected and is not equal to proposal's,
// remove invalid proposal.
Expand Down
10 changes: 5 additions & 5 deletions Libplanet.Net/Consensus/HeightVoteSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void AddVote(Vote vote)
}
}

voteSet.AddVerifiedVote(vote);
voteSet.AddVote(vote);
}
}

Expand Down Expand Up @@ -230,12 +230,12 @@ public VoteSet PreCommits(int round)
/// <exception cref="ArgumentException">Thrown when given <paramref name="voteFlag"/>
/// is not either <see cref="VoteFlag.PreVote"/> or <see cref="VoteFlag.PreCommit"/>.
/// </exception>
/// <exception cref="KeyNotFoundException">Thrown when there's no <see cref="RoundVoteSet"/>
/// exists for given <paramref name="round"/>.
/// </exception>
public VoteSet GetVoteSet(int round, VoteFlag voteFlag)
{
RoundVoteSet roundVoteSet;

// TODO: Check if try-catch is needed for KeyNotFoundException.
roundVoteSet = _roundVoteSets[round];
RoundVoteSet roundVoteSet = _roundVoteSets[round];
return voteFlag switch
{
VoteFlag.PreVote => roundVoteSet.PreVotes,
Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Net/Consensus/VoteSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public bool TwoThirdsMajority(out BlockHash blockHash)
_height, _round, _maj23!.Value, MappedList().ToImmutableArray());
}

internal void AddVerifiedVote(Vote vote)
internal void AddVote(Vote vote)
{
if (vote.Round != _round ||
vote.Flag != _voteType)
Expand All @@ -283,7 +283,7 @@ internal void AddVerifiedVote(Vote vote)
if (existing.BlockHash.Equals(vote.BlockHash))
{
throw new InvalidVoteException(
$"{nameof(AddVerifiedVote)}() does not expect duplicate votes",
$"{nameof(AddVote)}() does not expect duplicate votes",
vote);
}
else
Expand Down

0 comments on commit c9089ae

Please sign in to comment.