Skip to content

Commit

Permalink
reviews address
Browse files Browse the repository at this point in the history
  • Loading branch information
axaysagathiya committed Sep 15, 2024
1 parent 6f5d059 commit e917b5a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
6 changes: 3 additions & 3 deletions dot/parachain/backing/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1181,11 +1181,11 @@ func TestConflictingStatementIsMisbehavior(t *testing.T) {
}

require.Equal(t, relayParent, provisionerMessage.RelayParent)
misbehvaiorReport, ok := provisionerMessage.ProvisionableData.(parachaintypes.ProvisionableDataMisbehaviorReport)
misbehaviorReport, ok := provisionerMessage.ProvisionableData.(parachaintypes.ProvisionableDataMisbehaviorReport)
require.True(t, ok)

require.Equal(t, parachaintypes.ValidatorIndex(2), misbehvaiorReport.ValidatorIndex)
doubleVote, ok := misbehvaiorReport.Misbehaviour.(parachaintypes.ValidityDoubleVoteIssuedAndValidity)
require.Equal(t, parachaintypes.ValidatorIndex(2), misbehaviorReport.ValidatorIndex)
doubleVote, ok := misbehaviorReport.Misbehaviour.(parachaintypes.ValidityDoubleVoteIssuedAndValidity)
require.True(t, ok)

signForSeconded := doubleVote.CommittedCandidateReceiptAndSign.Signature
Expand Down
33 changes: 17 additions & 16 deletions dot/parachain/types/statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,27 @@ type Seconded CommittedCandidateReceipt
// Valid represents a statement that a validator has deemed a candidate valid.
type Valid CandidateHash

// statementVDTAndSigningContext is just a wrapper struct to hold both the statement and the signing context.
type statementVDTAndSigningContext struct {
Statement StatementVDT
Context SigningContext
}

func (s *StatementVDT) Sign(
keystore keystore.Keystore,
signingContext SigningContext,
key ValidatorID,
) (*ValidatorSignature, error) {
encodedData, err := scale.Marshal(*s)
if err != nil {
return nil, fmt.Errorf("marshalling payload: %w", err)
statementVDTAndSigningContext := statementVDTAndSigningContext{

Check failure on line 94 in dot/parachain/types/statement.go

View workflow job for this annotation

GitHub Actions / linting

shadow: declaration of "statementVDTAndSigningContext" shadows declaration at line 84 (govet)
Statement: *s,
Context: signingContext,
}

encodedSigningContext, err := scale.Marshal(signingContext)
encodedData, err := scale.Marshal(statementVDTAndSigningContext)
if err != nil {
return nil, fmt.Errorf("marshalling signing context: %w", err)
return nil, fmt.Errorf("marshalling statement and signing-context: %w", err)
}

encodedData = append(encodedData, encodedSigningContext...)

validatorPublicKey, err := sr25519.NewPublicKey(key[:])
if err != nil {
return nil, fmt.Errorf("getting public key: %w", err)
Expand All @@ -119,25 +123,22 @@ func (s *StatementVDT) VerifySignature(
signingContext SigningContext,
validatorSignature ValidatorSignature,
) (bool, error) {
encodedMsg, err := scale.Marshal(s)
if err != nil {
return false, fmt.Errorf("marshalling statementVDT: %w", err)
statementVDTAndSigningContext := statementVDTAndSigningContext{

Check failure on line 126 in dot/parachain/types/statement.go

View workflow job for this annotation

GitHub Actions / linting

shadow: declaration of "statementVDTAndSigningContext" shadows declaration at line 84 (govet)
Statement: *s,
Context: signingContext,
}

signingContextBytes, err := scale.Marshal(signingContext)
encodedMsg, err := scale.Marshal(statementVDTAndSigningContext)
if err != nil {
return false, fmt.Errorf("marshalling signing context: %w", err)
return false, fmt.Errorf("marshalling statement and signing-context: %w", err)
}

encodedMsg = append(encodedMsg, signingContextBytes...)

publicKey, err := sr25519.NewPublicKey(validator[:])
if err != nil {
return false, fmt.Errorf("getting public key: %w", err)
}

ok, err := publicKey.Verify(encodedMsg, validatorSignature[:])
return ok, err
return publicKey.Verify(encodedMsg, validatorSignature[:])
}

// UncheckedSignedFullStatement is a Variant of `SignedFullStatement` where the signature has not yet been verified.
Expand Down

0 comments on commit e917b5a

Please sign in to comment.