Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GRANDPA equivocation #747

Merged
merged 2 commits into from
Feb 6, 2025
Merged

Conversation

osrib
Copy link
Collaborator

@osrib osrib commented Feb 6, 2025

Implement GRANDPA equivocation

Checklist:

  • I have read the contributing guidelines.
  • My PR title matches the Conventional Commits spec.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@nistanimirov nistanimirov linked an issue Feb 6, 2025 that may be closed by this pull request

import java.math.BigInteger;

@Data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add lombok's builder annotation here. https://projectlombok.org/features/Builder

Runtime runtime = warpSyncState.getRuntime();
SignedVote firstSignedVote = votes.get(authorityPublicKey);

GrandpaEquivocation grandpaEquivocation = new GrandpaEquivocation();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use builder here.


if (votes.containsKey(authorityPublicKey)) {
equivocations.computeIfAbsent(authorityPublicKey, _ -> new HashSet<>()).add(signedVote);
Runtime runtime = warpSyncState.getRuntime();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Runtime runtime = warpSyncState.getRuntime();
BlockState blockState = stateManager.getBlockState();
Runtime runtime = bs.getRuntime(bs.getHighestFinalizedHash());

Optional<OpaqueKeyOwnershipProof> opaqueKeyOwnershipProof = runtime.generateGrandpaKeyOwnershipProof(voteMessageSetId, authorityPublicKey.getBytes());
opaqueKeyOwnershipProof.ifPresentOrElse(
key -> runtime.submitReportGrandpaEquivocationUnsignedExtrinsic(grandpaEquivocation, key.getProof()),
() -> log.warning(String.format(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If generateGrandpaKeyOwnershipProof() fails we'll log Failure to report Grandpa vote equivocation for authority: %s. and still return true.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah because equivocation is still exist we just can't report it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The outer log in GrandpaMessageHandler is a bit misleading then.
String.format("Reported vote equivocation for round %s, set %s, block hash %s, block number %s", voteMessageSetId, voteMessageSetId, signedMessage.getBlockHash(), signedMessage.getBlockNumber()));

@@ -91,6 +93,28 @@ public void submitReportEquivocationUnsignedExtrinsic(BlockEquivocationProof blo
}
}

@Override
public Optional<OpaqueKeyOwnershipProof> generateGrandpaKeyOwnershipProof(BigInteger authoritySetId,
byte[] authorityPublicKey) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is because of github's UI or the line is not formated.

@osrib osrib force-pushed the 649-Implement-GRANDPA-equivocation branch from 2109db3 to c07a806 Compare February 6, 2025 13:48
Copy link

sonarqubecloud bot commented Feb 6, 2025

@osrib osrib merged commit bc0e0e0 into dev Feb 6, 2025
3 checks passed
@osrib osrib deleted the 649-Implement-GRANDPA-equivocation branch February 6, 2025 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement GRANDPA equivocation
3 participants