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

feat(dot/parachain/backing): Import statement into statement table #3966

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
13a7ed2
implement a func to get attested candidate
axaysagathiya May 4, 2024
6e3460c
unit tests
axaysagathiya May 8, 2024
471605d
Merge branch 'feat/parachain'
axaysagathiya May 15, 2024
276b6e0
remove scale tags and unexport struct
axaysagathiya May 15, 2024
d2855d7
use slices.SortFunc to sort validity attestations
axaysagathiya May 15, 2024
f8f9f6d
implement import statement
axaysagathiya May 21, 2024
9bfdfc6
change interface method argument
axaysagathiya May 21, 2024
aae30b4
add nil check in availabilty store test
edwardmack May 21, 2024
c5b1422
implement isMemberOf method of table context
axaysagathiya May 21, 2024
769fa5e
newTable func + lint
axaysagathiya May 21, 2024
c85c3a3
assign process functions before sending request message to avoid empt…
edwardmack May 21, 2024
125f81a
improve import candidate method
axaysagathiya May 21, 2024
19d2f4d
address reviews
axaysagathiya May 22, 2024
7778110
Merge branch 'axay/feat/backing/statement-table/attested-candidate' o…
axaysagathiya May 22, 2024
f7c3361
Merge branch 'axay/feat/backing/statement-table/attested-candidate' i…
axaysagathiya May 22, 2024
b085602
improve
axaysagathiya May 22, 2024
d565b67
unit test(WIP)
axaysagathiya May 22, 2024
ad766c3
unit test for import statement method
axaysagathiya May 23, 2024
fae1814
unit test importCandidate (WIP)
axaysagathiya May 24, 2024
3062620
unit tests
axaysagathiya May 29, 2024
e640b3e
Merge branch 'feat/parachain' into axay/feat/backing/statement-table/…
axaysagathiya May 29, 2024
289ae56
Merge branch 'feat/parachain' into axay/feat/backing/statement-table/…
axaysagathiya May 29, 2024
ad9d533
address reviews
axaysagathiya Jun 3, 2024
d0c6a98
Merge branch 'axay/feat/backing/statement-table/import-statement' of …
axaysagathiya Jun 3, 2024
19b1ec3
improve
axaysagathiya Jun 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dot/parachain/backing/active_leaves_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func constructPerRelayParentState(
}
}

tableContext := TableContext{
tableContext := tableContext{
validator: localValidator,
groups: groups,
validators: validators,
Expand Down
17 changes: 14 additions & 3 deletions dot/parachain/backing/candidate_backing.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"context"
"errors"
"fmt"
"slices"
"sync"

parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
Expand Down Expand Up @@ -115,14 +116,24 @@ type attestingData struct {
backing []parachaintypes.ValidatorIndex
}

// TableContext represents the contextual information associated with a validator and groups
// tableContext represents the contextual information associated with a validator and groups
// for a table under a relay-parent.
type TableContext struct {
type tableContext struct {
validator *validator
groups map[parachaintypes.ParaID][]parachaintypes.ValidatorIndex
validators []parachaintypes.ValidatorID
}

// isMemberOf returns true if the validator is a member of the group of validators assigned to the parachain.
func (tc *tableContext) isMemberOf(validatorIndex parachaintypes.ValidatorIndex, paraID parachaintypes.ParaID) bool {
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved
indexes, ok := tc.groups[paraID]
if !ok {
return false
}

return slices.Contains(indexes, validatorIndex)
}

// validator represents local validator information.
// It can be created if the local node is a validator in the context of a particular relay chain block.
type validator struct {
Expand Down Expand Up @@ -307,7 +318,7 @@ func (cb *CandidateBacking) handleStatementMessage(
var attesting attestingData
switch statementVDT := statementVDT.(type) {
case parachaintypes.Seconded:
commitedCandidateReceipt, err := rpState.table.getCandidate(summary.Candidate)
commitedCandidateReceipt, err := rpState.table.getCommittedCandidateReceipt(summary.Candidate)
if err != nil {
return fmt.Errorf("getting candidate: %w", err)
}
Expand Down
74 changes: 37 additions & 37 deletions dot/parachain/backing/candidate_backing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ func TestImportStatement(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().importStatement(
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatementWithPVD{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatement{}),
).Return(new(Summary), nil)

return perRelayParentState{
Expand Down Expand Up @@ -259,8 +259,8 @@ func TestImportStatement(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().importStatement(
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatementWithPVD{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatement{}),
).Return(new(Summary), nil)

return perRelayParentState{
Expand Down Expand Up @@ -290,8 +290,8 @@ func TestImportStatement(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().importStatement(
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatementWithPVD{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatement{}),
).Return(new(Summary), nil)

return perRelayParentState{
Expand All @@ -310,8 +310,8 @@ func TestImportStatement(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().importStatement(
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatementWithPVD{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatement{}),
).Return(new(Summary), nil)

return perRelayParentState{
Expand Down Expand Up @@ -397,10 +397,10 @@ func dummyValidityAttestation(t *testing.T, value string) parachaintypes.Validit
return vdt
}

func dummyTableContext(t *testing.T) TableContext {
func dummyTableContext(t *testing.T) tableContext {
t.Helper()

return TableContext{
return tableContext{
validator: &validator{
index: 1,
},
Expand Down Expand Up @@ -447,7 +447,7 @@ func rpStateWhenPpmDisabled(t *testing.T) perRelayParentState {
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(&attestedToReturn, nil)

Expand Down Expand Up @@ -498,7 +498,7 @@ func TestPostImportStatement(t *testing.T) {
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(nil, errors.New("could not get attested candidate from table"))

Expand All @@ -524,7 +524,7 @@ func TestPostImportStatement(t *testing.T) {
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(&attestedCandidate{
groupID: 4,
Expand All @@ -550,7 +550,7 @@ func TestPostImportStatement(t *testing.T) {
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(&attestedCandidate{
groupID: 3,
Expand Down Expand Up @@ -909,8 +909,8 @@ func TestHandleStatementMessage(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().importStatement(
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatementWithPVD{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatement{}),
).Return(nil, nil)
mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
Expand All @@ -936,16 +936,16 @@ func TestHandleStatementMessage(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().importStatement(
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatementWithPVD{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatement{}),
).Return(&Summary{
GroupID: 4,
}, nil)
mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(nil, errors.New("could not get attested candidate from table"))

Expand All @@ -971,8 +971,8 @@ func TestHandleStatementMessage(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().importStatement(
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatementWithPVD{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatement{}),
).Return(&Summary{
Candidate: candidateHash,
GroupID: 4,
Expand All @@ -981,7 +981,7 @@ func TestHandleStatementMessage(t *testing.T) {
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(new(attestedCandidate), nil)

Expand Down Expand Up @@ -1009,8 +1009,8 @@ func TestHandleStatementMessage(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().importStatement(
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatementWithPVD{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatement{}),
).Return(&Summary{
Candidate: candidateHash,
GroupID: 4,
Expand All @@ -1019,7 +1019,7 @@ func TestHandleStatementMessage(t *testing.T) {
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(new(attestedCandidate), nil)

Expand Down Expand Up @@ -1050,8 +1050,8 @@ func TestHandleStatementMessage(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().importStatement(
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatementWithPVD{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatement{}),
).Return(&Summary{
Candidate: candidateHash,
GroupID: 4,
Expand All @@ -1060,7 +1060,7 @@ func TestHandleStatementMessage(t *testing.T) {
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(new(attestedCandidate), nil)

Expand Down Expand Up @@ -1094,8 +1094,8 @@ func TestHandleStatementMessage(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().importStatement(
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatementWithPVD{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatement{}),
).Return(&Summary{
Candidate: candidateHash,
GroupID: 4,
Expand All @@ -1104,7 +1104,7 @@ func TestHandleStatementMessage(t *testing.T) {
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(new(attestedCandidate), nil)

Expand Down Expand Up @@ -1145,8 +1145,8 @@ func TestHandleStatementMessage(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().importStatement(
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatementWithPVD{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatement{}),
).Return(&Summary{
Candidate: candidateHash,
GroupID: 4,
Expand All @@ -1155,7 +1155,7 @@ func TestHandleStatementMessage(t *testing.T) {
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(new(attestedCandidate), nil)
mockTable.EXPECT().getCandidate(
Expand Down Expand Up @@ -1189,8 +1189,8 @@ func TestHandleStatementMessage(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().importStatement(
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatementWithPVD{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatement{}),
).Return(&Summary{
Candidate: candidateHash,
GroupID: 4,
Expand All @@ -1199,7 +1199,7 @@ func TestHandleStatementMessage(t *testing.T) {
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(new(attestedCandidate), nil)
mockTable.EXPECT().getCandidate(
Expand Down
2 changes: 1 addition & 1 deletion dot/parachain/backing/get_backed_candidates.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (cb *CandidateBacking) handleGetBackedCandidatesMessage(requestedCandidates
continue
}

backed := attestedToBackedCandidate(*attested, &rpState.tableContext)
backed := attested.toBackedCandidate(&rpState.tableContext)
backedCandidates = append(backedCandidates, backed)
}

Expand Down
6 changes: 3 additions & 3 deletions dot/parachain/backing/get_backed_candidates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestHandleGetBackedCandidatesMessage(t *testing.T) {

mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(nil, errors.New("could not get attested candidate from table"))

Expand All @@ -60,7 +60,7 @@ func TestHandleGetBackedCandidatesMessage(t *testing.T) {

mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(nil, nil)

Expand All @@ -79,7 +79,7 @@ func TestHandleGetBackedCandidatesMessage(t *testing.T) {

mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(TableContext)),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(new(attestedCandidate), nil)

Expand Down
10 changes: 5 additions & 5 deletions dot/parachain/backing/mocks_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading