Skip to content

Commit

Permalink
Merge branch 'axay/feat/backing/statement-table/import-statement' int…
Browse files Browse the repository at this point in the history
…o axay/feat/backing/statement-table/drain-misbehaviours
  • Loading branch information
axaysagathiya authored Jun 7, 2024
2 parents 3146c6c + 19b1ec3 commit 88dbe83
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
1 change: 1 addition & 0 deletions dot/parachain/backing/candidate_backing.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type tableContext struct {
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 {
indexes, ok := tc.groups[paraID]
if !ok {
Expand Down
24 changes: 10 additions & 14 deletions dot/parachain/backing/per_relay_parent_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/ChainSafe/gossamer/lib/common"
)

var errNilPersistedValidationData = errors.New("persisted validation data is nil")

// PerRelayParentState represents the state information for a relay-parent in the subsystem.
type perRelayParentState struct {
prospectiveParachainsMode parachaintypes.ProspectiveParachainsMode
Expand Down Expand Up @@ -51,13 +53,13 @@ func (rpState *perRelayParentState) importStatement(
return nil, fmt.Errorf("getting value from statementVDT: %w", err)
}

if statementVDT.Index() == 2 { // Valid
if statementVDT.Index() != 1 { // Not Seconded
return rpState.table.importStatement(&rpState.tableContext, signedStatementWithPVD.SignedFullStatement)
}

// PersistedValidationData should not be nil if the statementVDT is Seconded.
if signedStatementWithPVD.PersistedValidationData == nil {
return nil, fmt.Errorf("persisted validation data is nil")
return nil, errNilPersistedValidationData
}

statementVDTSeconded := statementVDT.(parachaintypes.Seconded)
Expand Down Expand Up @@ -114,9 +116,10 @@ func (rpState *perRelayParentState) importStatement(
// postImportStatement handles a summary received from importStatement func and dispatches `Backed` notifications and
// misbehaviors as a result of importing a statement.
func (rpState *perRelayParentState) postImportStatement(subSystemToOverseer chan<- any, summary *Summary) {
// If the summary is nil, issue new misbehaviors and return.
defer issueNewMisbehaviors(subSystemToOverseer, rpState.relayParent, rpState.table)

// Return, If the summary is nil.
if summary == nil {
issueNewMisbehaviors(subSystemToOverseer, rpState.relayParent, rpState.table)
return
}

Expand All @@ -125,23 +128,19 @@ func (rpState *perRelayParentState) postImportStatement(subSystemToOverseer chan
logger.Error(err.Error())
}

// If the candidate is not attested, issue new misbehaviors and return.
// Return, If the candidate is not attested.
if attested == nil {
issueNewMisbehaviors(subSystemToOverseer, rpState.relayParent, rpState.table)
return
}

hash, err := attested.committedCandidateReceipt.Hash()
candidateHash, err := parachaintypes.GetCandidateHash(attested.committedCandidateReceipt)
if err != nil {
logger.Error(err.Error())
return
}

candidateHash := parachaintypes.CandidateHash{Value: hash}

// If the candidate is already backed, issue new misbehaviors and return.
// Return, If the candidate is already backed.
if rpState.backed[candidateHash] {
issueNewMisbehaviors(subSystemToOverseer, rpState.relayParent, rpState.table)
return
}

Expand All @@ -151,7 +150,6 @@ func (rpState *perRelayParentState) postImportStatement(subSystemToOverseer chan
// Convert the attested candidate to a backed candidate.
backedCandidate := attested.toBackedCandidate(&rpState.tableContext)
if backedCandidate == nil {
issueNewMisbehaviors(subSystemToOverseer, rpState.relayParent, rpState.table)
return
}

Expand Down Expand Up @@ -187,8 +185,6 @@ func (rpState *perRelayParentState) postImportStatement(subSystemToOverseer chan
ProvisionableData: parachaintypes.ProvisionableDataBackedCandidate(backedCandidate.Candidate.ToPlain()),
}
}

issueNewMisbehaviors(subSystemToOverseer, rpState.relayParent, rpState.table)
}

// issueNewMisbehaviors checks for new misbehaviors and sends necessary messages to the Overseer subsystem.
Expand Down
3 changes: 2 additions & 1 deletion dot/parachain/backing/statement_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (data *candidateData) getSummary(candidateHash parachaintypes.CandidateHash

// attested yields a full attestation for a candidate.
// If the candidate can be included, it will return attested candidate.
func (data candidateData) attested(validityThreshold uint) (*attestedCandidate, error) {
func (data *candidateData) attested(validityThreshold uint) (*attestedCandidate, error) {
numOfValidityVotes := uint(len(data.validityVotes))
if numOfValidityVotes < validityThreshold {
return nil, fmt.Errorf("%w: %d < %d", errNotEnoughValidityVotes, numOfValidityVotes, validityThreshold)
Expand Down Expand Up @@ -121,6 +121,7 @@ func (table *statementTable) getCommittedCandidateReceipt(candidateHash parachai
return data.candidate, nil
}

// importStatement imports a statement into the table.
func (table *statementTable) importStatement(
tableCtx *tableContext, signedStatement parachaintypes.SignedFullStatement,
) (*Summary, error) {
Expand Down

0 comments on commit 88dbe83

Please sign in to comment.