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

fix: [resharding] fix gas and balance redistribution during resharding #9449

Merged
merged 5 commits into from
Aug 24, 2023

Conversation

wacban
Copy link
Contributor

@wacban wacban commented Aug 17, 2023

During resharding we need to redistribute the gas and balance to the children shards.

The old implementation relied on the fact that the split shards and indexed from 0. In the future reshardings this may not be the case, for example when splitting shard 3, the split shard ids will be 3 & 4.

The principle idea of the distribution remains the same. Both quantities are distributed evenly across the children shards. If there is any remainder := quantity % num_split_shards, then we assign 1 extra unit to each of the first remainder children shards.

e.g. splitting shard 3 -> 3' & 4'
there is 5 gas to redistribute to children
shard 3' will get 3 units of gas
shard 4' will get 2 units of gas

the old implementation relied on a math trick to do that, the new one takes a more engineering leaning approach

@wacban
Copy link
Contributor Author

wacban commented Aug 17, 2023

This no-op PR seems to be breaking a few tests 💀 but sharing for a sneak peak.

@wacban wacban marked this pull request as ready for review August 17, 2023 15:31
@wacban wacban requested a review from a team as a code owner August 17, 2023 15:31
Copy link
Collaborator

@akhi3030 akhi3030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I suppose Shreyan will also review. Some minor feedback.

chain/chain/src/chain.rs Show resolved Hide resolved
chain/chain/src/chain.rs Outdated Show resolved Hide resolved
chain/chain/src/chain.rs Outdated Show resolved Hide resolved
@@ -89,7 +89,11 @@ pub struct ApplySplitStateResult {
// otherwise, it simply returns the state changes needed to be applied to split states
#[derive(Debug)]
pub enum ApplySplitStateResultOrStateChanges {
/// Immediately apply the split state result.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@near-bulldozer near-bulldozer bot merged commit fff5fd2 into master Aug 24, 2023
@near-bulldozer near-bulldozer bot deleted the waclaw-resharding-gas branch August 24, 2023 09:01
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Aug 24, 2023
near#9449)

During resharding we need to redistribute the gas and balance to the children shards. 

The old implementation relied on the fact that the split shards and indexed from 0. In the future reshardings this may not be the case, for example when splitting shard 3, the split shard ids will be 3 & 4. 

The principle idea of the distribution remains the same. Both quantities are distributed evenly across the children shards. If there is any remainder := quantity % num_split_shards, then we assign 1 extra unit to each of the first `remainder` children shards. 

e.g. splitting shard 3 -> 3' & 4'
there is 5 gas to redistribute to children
shard 3' will get 3 units of gas
shard 4' will get 2 units of gas

the old implementation relied on a math trick to do that, the new one takes a more engineering leaning approach
nikurt pushed a commit that referenced this pull request Aug 28, 2023
#9449)

During resharding we need to redistribute the gas and balance to the children shards. 

The old implementation relied on the fact that the split shards and indexed from 0. In the future reshardings this may not be the case, for example when splitting shard 3, the split shard ids will be 3 & 4. 

The principle idea of the distribution remains the same. Both quantities are distributed evenly across the children shards. If there is any remainder := quantity % num_split_shards, then we assign 1 extra unit to each of the first `remainder` children shards. 

e.g. splitting shard 3 -> 3' & 4'
there is 5 gas to redistribute to children
shard 3' will get 3 units of gas
shard 4' will get 2 units of gas

the old implementation relied on a math trick to do that, the new one takes a more engineering leaning approach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants