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): implement statement table method to drain missbehaviours #3996

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 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
778ba13
implement drain missbehaviours
axaysagathiya Jun 1, 2024
dc10b90
clean up
axaysagathiya Jun 1, 2024
3146c6c
Merge branch 'axay/feat/backing/statement-table/import-statement' int…
axaysagathiya Jun 1, 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
88dbe83
Merge branch 'axay/feat/backing/statement-table/import-statement' int…
axaysagathiya Jun 7, 2024
099cfe6
Merge branch 'feat/parachain' into axay/feat/backing/statement-table/…
axaysagathiya Jun 10, 2024
7750b7f
add comment
axaysagathiya Jun 10, 2024
e1c8ae5
Merge branch 'axay/feat/backing/statement-table/drain-misbehaviours' …
axaysagathiya Jun 10, 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
35 changes: 16 additions & 19 deletions dot/parachain/backing/candidate_backing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func rpStateWhenPpmDisabled(t *testing.T) perRelayParentState {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
Return(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(tableContext)),
Expand Down Expand Up @@ -475,11 +475,8 @@ func TestPostImportStatement(t *testing.T) {
ctrl := gomock.NewController(t)
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().drainMisbehaviors().Return([]parachaintypes.ProvisionableDataMisbehaviorReport{
{
ValidatorIndex: 1,
Misbehaviour: parachaintypes.MultipleCandidates{},
},
mockTable.EXPECT().drainMisbehaviors().Return(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{
1: {parachaintypes.MultipleCandidates{}},
})

return perRelayParentState{
Expand All @@ -495,7 +492,7 @@ func TestPostImportStatement(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
Return(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(tableContext)),
Expand All @@ -521,7 +518,7 @@ func TestPostImportStatement(t *testing.T) {
candidateHash := parachaintypes.CandidateHash{Value: hash}

mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
Return(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(tableContext)),
Expand All @@ -547,7 +544,7 @@ func TestPostImportStatement(t *testing.T) {
mockTable := NewMockTable(ctrl)

mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
Return(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(tableContext)),
Expand Down Expand Up @@ -913,7 +910,7 @@ func TestHandleStatementMessage(t *testing.T) {
gomock.AssignableToTypeOf(parachaintypes.SignedFullStatement{}),
).Return(nil, nil)
mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
Return(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{})

return map[common.Hash]*perRelayParentState{
relayParent: {
Expand Down Expand Up @@ -942,7 +939,7 @@ func TestHandleStatementMessage(t *testing.T) {
GroupID: 4,
}, nil)
mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
Return(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(tableContext)),
Expand Down Expand Up @@ -978,7 +975,7 @@ func TestHandleStatementMessage(t *testing.T) {
GroupID: 4,
}, nil)
mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
Return(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(tableContext)),
Expand Down Expand Up @@ -1016,7 +1013,7 @@ func TestHandleStatementMessage(t *testing.T) {
GroupID: 4,
}, nil)
mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
Return(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(tableContext)),
Expand Down Expand Up @@ -1057,7 +1054,7 @@ func TestHandleStatementMessage(t *testing.T) {
GroupID: 4,
}, nil)
mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
Return(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(tableContext)),
Expand Down Expand Up @@ -1101,7 +1098,7 @@ func TestHandleStatementMessage(t *testing.T) {
GroupID: 4,
}, nil)
mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
Return(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(tableContext)),
Expand Down Expand Up @@ -1152,13 +1149,13 @@ func TestHandleStatementMessage(t *testing.T) {
GroupID: 4,
}, nil)
mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
Return(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(new(attestedCandidate), nil)
mockTable.EXPECT().getCandidate(
mockTable.EXPECT().getCommittedCandidateReceipt(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
).Return(
parachaintypes.CommittedCandidateReceipt{},
Expand Down Expand Up @@ -1196,13 +1193,13 @@ func TestHandleStatementMessage(t *testing.T) {
GroupID: 4,
}, nil)
mockTable.EXPECT().drainMisbehaviors().
Return([]parachaintypes.ProvisionableDataMisbehaviorReport{})
Return(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{})
mockTable.EXPECT().attestedCandidate(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
gomock.AssignableToTypeOf(new(tableContext)),
gomock.AssignableToTypeOf(uint32(0)),
).Return(new(attestedCandidate), nil)
mockTable.EXPECT().getCandidate(
mockTable.EXPECT().getCommittedCandidateReceipt(
gomock.AssignableToTypeOf(parachaintypes.CandidateHash{}),
).Return(dummyCCR, nil)

Expand Down
12 changes: 6 additions & 6 deletions dot/parachain/backing/mocks_test.go

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

21 changes: 12 additions & 9 deletions dot/parachain/backing/per_relay_parent_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,24 +189,27 @@ func (rpState *perRelayParentState) postImportStatement(subSystemToOverseer chan

// issueNewMisbehaviors checks for new misbehaviors and sends necessary messages to the Overseer subsystem.
func issueNewMisbehaviors(subSystemToOverseer chan<- any, relayParent common.Hash, table Table) {
// collect the misbehaviors to avoid double mutable self borrow issues
misbehaviors := table.drainMisbehaviors()
// collect the validatorsToMisbehaviors to avoid double mutable self borrow issues
validatorsToMisbehaviors := table.drainMisbehaviors()

for _, m := range misbehaviors {
for validatorIndex, misbehaviours := range validatorsToMisbehaviors {
// TODO: figure out what this comment means by 'avoid cycles'.
//
// The provisioner waits on candidate-backing, which means
// that we need to send unbounded messages to avoid cycles.
//
// Misbehaviors are bounded by the number of validators and
// the block production protocol.
subSystemToOverseer <- parachaintypes.ProvisionerMessageProvisionableData{
RelayParent: relayParent,
ProvisionableData: parachaintypes.ProvisionableDataMisbehaviorReport{
ValidatorIndex: m.ValidatorIndex,
Misbehaviour: m.Misbehaviour,
},
for _, misbehaviour := range misbehaviours {
subSystemToOverseer <- parachaintypes.ProvisionerMessageProvisionableData{
RelayParent: relayParent,
ProvisionableData: parachaintypes.ProvisionableDataMisbehaviorReport{
ValidatorIndex: validatorIndex,
Misbehaviour: misbehaviour,
},
}
}

}
}

Expand Down
10 changes: 6 additions & 4 deletions dot/parachain/backing/statement_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,18 @@ func effectiveMinimumBackingVotes(groupLen uint, configuredMinimumBackingVotes u
return min(groupLen, uint(configuredMinimumBackingVotes))
}

func (statementTable) drainMisbehaviors() []parachaintypes.ProvisionableDataMisbehaviorReport {
// TODO: Implement this method
return nil
// drainMisbehaviors returns the current detected misbehaviors and resets the internal map.
func (table *statementTable) drainMisbehaviors() map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour {
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved
mapToReturn := table.detectedMisbehaviour
table.detectedMisbehaviour = make(map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour)
return mapToReturn
}

type Table interface {
getCommittedCandidateReceipt(parachaintypes.CandidateHash) (parachaintypes.CommittedCandidateReceipt, error)
importStatement(*tableContext, parachaintypes.SignedFullStatement) (*Summary, error)
attestedCandidate(parachaintypes.CandidateHash, *tableContext, uint32) (*attestedCandidate, error)
drainMisbehaviors() []parachaintypes.ProvisionableDataMisbehaviorReport
drainMisbehaviors() map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour
}

func newTable(config tableConfig) *statementTable {
Expand Down
44 changes: 44 additions & 0 deletions dot/parachain/backing/statement_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,47 @@ func TestStatementTable_validityVote(t *testing.T) {
})
}
}

func TestStatementTable_drainMisbehaviors(t *testing.T) {
t.Parallel()

committedCandidate := getDummyCommittedCandidateReceipt(t)

candidateHash, err := parachaintypes.GetCandidateHash(committedCandidate)
require.NoError(t, err)

var validatorSign parachaintypes.ValidatorSignature
var tempSignature = common.MustHexToBytes("0xc67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b86") //nolint:lll
copy(validatorSign[:], tempSignature)

oldSign := parachaintypes.ValidatorSignature{}

valToMic := map[parachaintypes.ValidatorIndex][]parachaintypes.Misbehaviour{
1: {
parachaintypes.ValidityDoubleVoteIssuedAndValidity{
CommittedCandidateReceiptAndSign: parachaintypes.CommittedCandidateReceiptAndSign{
CommittedCandidateReceipt: committedCandidate,
Signature: oldSign,
},
CandidateHashAndSign: parachaintypes.CandidateHashAndSign{
CandidateHash: candidateHash,
Signature: validatorSign,
},
},

parachaintypes.DoubleSignOnValidity{
CandidateHash: candidateHash,
Sign1: oldSign,
Sign2: validatorSign,
},
},
}

table := &statementTable{
detectedMisbehaviour: valToMic,
}

misbehaviours := table.drainMisbehaviors()
require.Equal(t, valToMic, misbehaviours)
require.Empty(t, table.detectedMisbehaviour)
}
Loading