-
Notifications
You must be signed in to change notification settings - Fork 55
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
Rewrite collator assignment to support parathreads #385
Conversation
And fix some bugs when there are not enough collators
Coverage Report@@ Coverage Diff @@
## master tomasz-assign-to-parathreads +/- ##
================================================================
+ Coverage 76.41% 76.92% +0.51%
+ Files 101 105 +4
+ Lines 25488 26036 +548
================================================================
+ Hits 19475 20026 +551
- Misses 6013 6010 -3
|
Edit: Removed all unwraps and panics, if you find one please add a comment |
available_collators -= cc.min_collators; | ||
container_chains_with_collators.push(*cc); | ||
} else { | ||
// Do not break here because we want to push all the remaining para_ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you mean parathreads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, clarified the comment
/// # Panics | ||
/// | ||
/// * If `container_chains` is empty, or if the first element of `container_chains` does not have `para_id == SelfParaId::get()`. | ||
pub fn prioritize_invulnerables( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this refactor BTW. Much cleaner than having it in the pallet
@@ -8,4 +8,4 @@ cd $(dirname $0)/.. | |||
|
|||
mkdir -p specs | |||
../target/release/container-chain-template-simple-node build-spec --disable-default-bootnode --add-bootnode "/ip4/127.0.0.1/tcp/33049/ws/p2p/12D3KooWHVMhQDHBpj9vQmssgyfspYecgV6e3hH1dQVDUkUbCYC9" --parachain-id 2000 --raw > specs/warp-sync-template-container-2000.json | |||
../target/release/tanssi-node build-spec --chain dancebox-local --parachain-id 1000 --add-container-chain specs/warp-sync-template-container-2000.json --invulnerable "Collator1000-01" --invulnerable "Collator1000-02" --invulnerable "Collator2000-01" --invulnerable "Collator2000-02" --invulnerable "Collator1000-03" > specs/warp-sync-tanssi-1000.json | |||
../target/release/tanssi-node build-spec --chain dancebox-local --parachain-id 1000 --add-container-chain specs/warp-sync-template-container-2000.json --invulnerable "Collator1000-01" --invulnerable "Collator1000-02" --invulnerable "Collator1000-03" --invulnerable "Collator2000-01" --invulnerable "Collator2000-02" > specs/warp-sync-tanssi-1000.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the reason for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentional, it's the order change mentioned in the description (see test assign_collators_set_zero_per_container
for an example)
@@ -10,4 +10,4 @@ mkdir -p specs | |||
../target/release/container-chain-template-simple-node build-spec --disable-default-bootnode --add-bootnode "/ip4/127.0.0.1/tcp/33049/ws/p2p/12D3KooWHVMhQDHBpj9vQmssgyfspYecgV6e3hH1dQVDUkUbCYC9" --parachain-id 2000 --raw > specs/template-container-2000.json | |||
../target/release/container-chain-template-frontier-node build-spec --disable-default-bootnode --add-bootnode "/ip4/127.0.0.1/tcp/33050/ws/p2p/12D3KooWFGaw1rxB6MSuN3ucuBm7hMq5pBFJbEoqTyth4cG483Cc" --parachain-id 2001 --raw > specs/template-container-2001.json | |||
../target/release/container-chain-template-simple-node build-spec --disable-default-bootnode --parachain-id 2002 --raw > specs/template-container-2002.json | |||
../target/release/tanssi-node build-spec --chain dancebox-local --parachain-id 1000 --add-container-chain specs/template-container-2000.json --add-container-chain specs/template-container-2001.json --invulnerable "Collator1000-01" --invulnerable "Collator1000-02" --invulnerable "Collator2000-01" --invulnerable "Collator2000-02" --invulnerable "Collator2001-01" --invulnerable "Collator2001-02" --invulnerable "Collator2002-01" --invulnerable "Collator2002-02" > specs/tanssi-1000.json | |||
../target/release/tanssi-node build-spec --chain dancebox-local --parachain-id 1000 --add-container-chain specs/template-container-2000.json --add-container-chain specs/template-container-2001.json --invulnerable "Collator1000-01" --invulnerable "Collator1000-02" --invulnerable "Collator2002-01" --invulnerable "Collator2002-02" --invulnerable "Collator2000-01" --invulnerable "Collator2000-02" --invulnerable "Collator2001-01" --invulnerable "Collator2001-02" > specs/tanssi-1000.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And for these, it only changes the order no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, to assign collators to the same chains as before the refactor
}]; | ||
let collators_per_container = | ||
T::HostConfiguration::collators_per_container(target_session_index); | ||
for para_id in &container_chain_ids { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put a TODO here indicating that this is provisional and that the order should be done based on tipping in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! I imagine that the priority will be done instead of shuffling here, so the rest of the algorithm should not change when we add tipping.
// Chains will not be assigned less than `min_collators`, except the orchestrator chain. | ||
// First all chains will be assigned `min_collators`, and then the first one will be assigned up to `max`, | ||
// then the second one, and so on. | ||
let mut container_chains = vec![ContainerChain { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not entirely sure I like calling this a containerChain when it really isnt :(. I would rather call it Chain, but I also dont like it too much, maybe we can have a dual enum here that for now have the same parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to ChainNumCollators
and added docs saying that this could be any kind of chain
LGTM! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The existing algorithm was getting too complex to support parathreads. This new algorithm will first calculate how many collators we need in total, removing some container chains if we don't have enough collators, and then assign collators giving priority to those that were already assigned to the same chains.
In most cases this will result in the same assignment, expect that now all the orchestrator collators will be added all at the same time instead of first min and then max (see test
assign_collators_set_zero_per_container
).Additionally, it allows each container chain to have a different number of collators, and even a min/max similar to the orchestrator chain. This is not used yet but it will be needed to support parathreads, which will have a different number of collators than container chains.
This fixes some bugs related to the case where there are not enough collators, see tests
assign_collators_remove_from_orchestator_when_all_assigned
andassign_collators_invulnerables_priority_orchestrator_reassigned
.This PR will not add parathread support, that will come in future PRs.