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

Design Doc: support elastic scaling in candidate backing subsystem #4400

Merged
merged 15 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions docs/docs/design/candidate-backing-elastic-scaling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Candidate backing subsystem design update
> Update Candidate backing subsystem to support Async backing + Elastic scaling

## overview of changes
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved
### Remove use of ProspectiveParachainsMode
We currently have both legacy backing code and async backing code. Now that the async backing parameters runtime API is live on all networks, the backing subsystem code can be simplified. We can remove the use of `ProspectiveParachainsMode` and keep only the parts under `ProspectiveParachainsMode.Enabled`

### remove perLeaf field of CandidateBacking struct
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved
- Remove the perLeaf field of the `Candidatebacking` struct as it keeps track of which Active leaf has ProspectiveParachainMode Enabled.
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved
- if we need active leaf data, we can get it from backing implicit view which we store in `CandidateBacking`. (Yet to implement)

### change GroupID from paraID to CoreIndex
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved
Before elastic scaling, only a single group of validators was assigned to a parachain, so we assigned paraID to GroupID.
![single-group-assignment](../assets/img/single-group-assignment.png)

However, in elastic scaling, multiple groups of validators(core) will be assigned to a parachain. So now we have to change the type of GroupID from paraID to the `CoreIndex`, which is unique for assigned groups.
![multiple-group-assignment](../assets/img/multiple-group-assignment.png)


- Change the type of groupID from `paraID` to `CoreIndex` and check all the methods to see if any changes are needed.
- Structs containing groupID: `Summary`, `tableContext`, `attestedCandidate`, `candidateData`.
- change `assignment *parachaintypes.ParaID` field to `assignedCore *parachaintypes.CoreIndex` in perRelayParentState which represents the core index assigned to the local validator at this relay parent.

### Use fragment-chain
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved
Our async backing code uses `Fragment-tree`, which was introduced in Async backing and has now become `Fragment-chain`. So we need to update the code to use `Fragment-chain`.
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
- TODO: What/Where/How to update the code?
haikoschol marked this conversation as resolved.
Show resolved Hide resolved

## overseer messages

### ActiveLeavesUpdate
Remove all usage of ProspectiveParachainMode, perLeaf field of `CandidateBacking` struct.

Add new fields into `perRelayParentState` and modify the `constructPerRelayParentState` function logic to fill the values of new fields.

```
type perRelayParentState struct {
...

// claim queue stores the information of which parachain will be assigned to which core.
claimQueue map[CoreIndex][]Assignment

// injectCoreIndex is a flag to indicate if the core index should be injected
// in the BackedCandidate validator indices bitfield.
// set true if ElasticScalingMVP is enabled
injectCoreIndex bool

// Add extra fields if needed during implementation.
}
```

runtime methods we will need
- claim queue: ParachainHost_claim_queue
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved
- node features: ParachainHost_node_features
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved

### GetBackableCandidates

The current struct to request backable candidates from the candidate backing subsystem doesn't provide info on which candidate belongs to which parachain. Now we have to update this overseer message structure `GetBackableCandidates` to provide a record of the parachain ID and candidates belonging to them and relay the parents of each candidate.
```
type GetBackableCandidates struct {
Candidates map[parachaintypes.ParaID][]*CandidateHashAndRelayParent
ResCh chan map[parachaintypes.ParaID]*parachaintypes.BackedCandidate
}
```

`GetBackableCandidates` requests a set of backable candidates attested by the subsystem.

The order of candidates of the same parachain must be preserved in the response because candidates are supplied in dependency order. We must ensure that this dependency order is preserved.

So, If a backable candidate of a parachain cannot be retrieved, the response should not contain any candidates of the same parachain that follow it in the input slice.
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved

For example:
Candidates => [A, B, C, D, E, F, G, H]
If we are unable to retrieve backable candidate D, the Response should be [A, B, C]

### CanSecond
Now we have prospective-parachain subsystem skeleton, So use overseer messages declared in that subsystem and remove the old/unneccesary types.

Remove all usage of ProspectiveParachainMode, perLeaf field of `CandidateBacking` struct.

Logic of this function written in the context of fragment tree, need to remove this code. after removing this code we just need to perform seconding sanity check to find if it is possible to second a candidate.

update logic of seconding sanity check:
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved
- now as we don't want to use prospective parachain mode anymore. instead of iterating over `perLeaf`, iterate over leaves in the implicit view.
- get hypothetical membership of the candidates from prospective parachain[res: candidate and it's hypothetical membership(list of leaves where the candidate could be added)]
- for each active leaf, check if they are present in the hypothetical membership. if present it's possible to second the candidate at that leaf.
- return the list possible of active leaves where candidate can be seconded.(return type changed)
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved

If we don't find any leaf at which we can second the candidate, it is impossible to second the candidate

### Second
make sure local validator is not disabled before processing the candidate.

update ther logic to ensure the candidate is from our assignment
- using core index, validators can find parachains assigned to the core.(claim queue will provide this info)
- candidate's parachain id should be in the list of parachains we get from claim queue.

### Statement
Don't import statement if the sender is disabled.

in `kickOffValidationWork` method of `perRelayParentState`.
- Do nothing if the local validator is disabled or not a validator at all.

in `rpState.postImportStatement` method
- remove the code under the branch of prospective parachain mode disabled.
- in the code under the branch of prospective parachain mode enabled remove the code to send `collatorprotocolmessages.Backed` overseer message.

## Validated Candidate command
modification in `signImportAndDistributeStatement` function
- Need to provide core index as argument to `table.importStatement` method to use core index instead of paraID inside the method.

No changes are needed in the logic to process `Attest` and `AttestNoPov` commands.

changes we need in the logic to process `Second` command
- there is some code seems to be not required. So remove this code where we compare
persistedValidationData.ParentHead.Data hash with commitments.HeadData.Data hash.
- remove the code to update seconded depths in active leaves, which is related to fragment tree.
Loading