Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardmack committed Jun 16, 2023
1 parent b27875c commit 76b946a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ func (rvd RelayVRFDelay) Index() uint {
return 1
}

// VrfSignature VRF signature data
// VrfSignature represents VRF signature, which itself consists of a VRF pre-output and DLEQ proof
type VrfSignature struct {
// Output VRF output
Output [sr25519.VRFOutputLength]byte `scale:"1"`
// Proof VRF proof
Proof [sr25519.VRFProofLength]byte `scale:"2"`
}

// AssignmentCert a certification of assignment
// AssignmentCert is a certification of assignment
type AssignmentCert struct {
// Kind the criterion which is claimed to be met by this cert.
Kind AssignmentCertKind `scale:"1"`
// Vrf the VRF signature showing the criterion is met.
Vrf VrfSignature `scale:"2"`
}

// IndirectAssignmentCert an assignment criterion which refers to the candidate under which the assignment is
// IndirectAssignmentCert is an assignment criterion which refers to the candidate under which the assignment is
// relevant by block hash.
type IndirectAssignmentCert struct {
// BlockHash a block hash where the canidate appears.
Expand All @@ -109,7 +109,7 @@ type IndirectAssignmentCert struct {
Cert AssignmentCert `scale:"3"`
}

// CandidateIndex the index of the candidate in the list of candidates fully included as-of the block.
// CandidateIndex represents the index of the candidate in the list of candidates fully included as-of the block.
type CandidateIndex uint32

// Assignment holds indirect assignment cert and candidate index
Expand All @@ -119,9 +119,7 @@ type Assignment struct {
}

// Assignments for candidates in recent, unfinalized blocks.
type Assignments struct {
Assignments []Assignment
}
type Assignments []Assignment

// Index returns varying data type index
func (a Assignments) Index() uint {
Expand All @@ -131,10 +129,7 @@ func (a Assignments) Index() uint {
// ValidatorSignature with which parachain validators sign blocks.
type ValidatorSignature [sr25519.SignatureLength]byte

// IndirectSignedApprovalVote A signed approval vote which references the candidate indirectly via the block.
//
// In practice, we have a look-up from block hash and candidate index to candidate hash,
// so this can be transformed into a `SignedApprovalVote`.
// IndirectSignedApprovalVote represents a signed approval vote which references the candidate indirectly via the block.
type IndirectSignedApprovalVote struct {
// BlockHash a block hash where the candidate appears.
BlockHash common.Hash `scale:"1"`
Expand All @@ -147,12 +142,10 @@ type IndirectSignedApprovalVote struct {
}

// Approvals for candidates in some recent, unfinalized block.
type Approvals struct {
Approvals []IndirectSignedApprovalVote
}
type Approvals []IndirectSignedApprovalVote

// Index returns varying data type index
func (ms Approvals) Index() uint {
func (ap Approvals) Index() uint {
return 1
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
"github.com/stretchr/testify/require"
)

var hash = common.Hash{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}
var hash = common.MustHexToHash("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")

func TestEncodeApprovalDistributionMessageAssignmentModulo(t *testing.T) {
approvalDistributionMessage := NewApprovalDistributionMessageVDT()
Expand All @@ -36,10 +35,10 @@ func TestEncodeApprovalDistributionMessageAssignmentModulo(t *testing.T) {
58, 59, 60, 61, 62, 63, 64, 4, 0, 0, 0}

approvalDistributionMessage.Set(Assignments{
Assignments: []Assignment{{
Assignment{
IndirectAssignmentCert: fakeAssignmentCert(hash, ValidatorIndex(1), false),
CandidateIndex: 4,
}},
},
})

encodedMessage, err := scale.Marshal(approvalDistributionMessage)
Expand All @@ -63,10 +62,10 @@ func TestEncodeApprovalDistributionMessageAssignmentDelay(t *testing.T) {
59, 60, 61, 62, 63, 64, 2, 0, 0, 0}

approvalDistributionMessage.Set(Assignments{
Assignments: []Assignment{{
Assignment{
IndirectAssignmentCert: fakeAssignmentCert(hash, ValidatorIndex(2), true),
CandidateIndex: 2,
}},
},
})

encodedMessage, err := scale.Marshal(approvalDistributionMessage)
Expand Down Expand Up @@ -112,14 +111,14 @@ func TestEncodeApprovalDistributionMessageApprovals(t *testing.T) {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}

approvalDistributionMessage.Set(Approvals{
Approvals: []IndirectSignedApprovalVote{{
IndirectSignedApprovalVote{
BlockHash: hash,
CandidateIndex: CandidateIndex(2),
ValidatorIndex: ValidatorIndex(3),
Signature: ValidatorSignature{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1},
}},
},
})

encodedMessage, err := scale.Marshal(approvalDistributionMessage)
Expand All @@ -140,10 +139,10 @@ func TestDecodeApprovalDistributionMessageAssignmentModulo(t *testing.T) {

expectedApprovalDistributionMessage := NewApprovalDistributionMessageVDT()
expectedApprovalDistributionMessage.Set(Assignments{
Assignments: []Assignment{{
Assignment{
IndirectAssignmentCert: fakeAssignmentCert(hash, ValidatorIndex(2), false),
CandidateIndex: 4,
}},
},
})

approvalValue, err := approvalDistributionMessage.Value()
Expand All @@ -160,14 +159,14 @@ func TestDecodeApprovalDistributionMessageApprovals(t *testing.T) {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
expectedApprovalDistributionMessage := NewApprovalDistributionMessageVDT()
expectedApprovalDistributionMessage.Set(Approvals{
Approvals: []IndirectSignedApprovalVote{{
IndirectSignedApprovalVote{
BlockHash: hash,
CandidateIndex: CandidateIndex(2),
ValidatorIndex: ValidatorIndex(3),
Signature: ValidatorSignature{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1},
}},
},
})

approvalDistributionMessage := NewApprovalDistributionMessageVDT()
Expand Down

0 comments on commit 76b946a

Please sign in to comment.