Skip to content

Commit

Permalink
733 catch up response receiving (#745)
Browse files Browse the repository at this point in the history
# Description

- Implemented handling of catch-up responses
- Made changes to the previous logic for collecting preVotes and
preCommits on initiating catch-up response
- Placed "Todo" comments in handling catch-up response, describing what
should be added as logic, to help those who implement play-grandpa-round
and finalizing preVote stage.

Fixes #733 >

---------

Co-authored-by: Hristiyan Mitov <[email protected]>
  • Loading branch information
hMitov and Hristiyan Mitov authored Feb 6, 2025
1 parent 5193c2b commit d03d9f0
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/limechain/grandpa/GrandpaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private boolean isFinalizable(GrandpaRound grandpaRound) {
*
* @return if the current round is completable
*/
private boolean isCompletable(GrandpaRound grandpaRound) {
public boolean isCompletable(GrandpaRound grandpaRound) {

Map<Vote, Long> votes = getDirectVotes(grandpaRound, SubRound.PRE_COMMIT);
long votesCount = votes.values().stream()
Expand Down Expand Up @@ -157,7 +157,7 @@ private boolean isCompletable(GrandpaRound grandpaRound) {
*
* @return the best final candidate block
*/
private BlockHeader findBestFinalCandidate(GrandpaRound grandpaRound) {
public BlockHeader findBestFinalCandidate(GrandpaRound grandpaRound) {
GrandpaSetState grandpaSetState = stateManager.getGrandpaSetState();
BlockState blockState = stateManager.getBlockState();

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/limechain/grandpa/round/GrandpaRound.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;

Expand Down Expand Up @@ -77,8 +76,8 @@ public class GrandpaRound implements Serializable {
private Map<Hash256, SignedVote> preCommits = new ConcurrentHashMap<>();
private SignedVote primaryVote;

private final Map<Hash256, Set<SignedVote>> pvEquivocations = new ConcurrentHashMap<>();
private final Map<Hash256, Set<SignedVote>> pcEquivocations = new ConcurrentHashMap<>();
private Map<Hash256, List<SignedVote>> pvEquivocations = new ConcurrentHashMap<>();
private Map<Hash256, List<SignedVote>> pcEquivocations = new ConcurrentHashMap<>();

private final transient List<CommitMessage> commitMessagesArchive = new ArrayList<>();

Expand Down Expand Up @@ -109,13 +108,13 @@ public Vote getPreCommitChoice() {

public long getPvEquivocationsCount() {
return this.pvEquivocations.values().stream()
.mapToLong(Set::size)
.mapToLong(List::size)
.sum();
}

public long getPcEquivocationsCount() {
return this.pcEquivocations.values().stream()
.mapToInt(Set::size)
.mapToInt(List::size)
.sum();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,11 @@ private void handleCatchupRequestMessage(byte[] message, PeerId peerId) {
private void handleCatchupResponseMessage(byte[] message, PeerId peerId) {
ScaleCodecReader reader = new ScaleCodecReader(message);
CatchUpResMessage catchUpResMessage = reader.read(CatchUpResMessageScaleReader.getInstance());
//todo: handle catchup res message (authoring node responsibility)
log.log(Level.INFO, "Received catch up response message from Peer " + peerId + "\n" + catchUpResMessage);

if (AbstractState.isActiveAuthority() && connectionManager.checkIfPeerIsAuthorNode(peerId)) {
grandpaMessageHandler.handleCatchUpResponse(peerId, catchUpResMessage, connectionManager::getPeerIds);
}
}

/**
Expand Down
Loading

0 comments on commit d03d9f0

Please sign in to comment.