-
Notifications
You must be signed in to change notification settings - Fork 622
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: properly handle genesis as part of stateless validation #10633
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1081,33 +1081,37 @@ pub mod epoch_info { | |
} | ||
} | ||
|
||
pub fn sample_chunk_producer(&self, height: BlockHeight, shard_id: ShardId) -> ValidatorId { | ||
pub fn sample_chunk_producer( | ||
&self, | ||
height: BlockHeight, | ||
shard_id: ShardId, | ||
) -> Option<ValidatorId> { | ||
match &self { | ||
Self::V1(v1) => { | ||
let cp_settlement = &v1.chunk_producers_settlement; | ||
let shard_cps = &cp_settlement[shard_id as usize]; | ||
shard_cps[(height as u64 % (shard_cps.len() as u64)) as usize] | ||
let shard_cps = cp_settlement.get(shard_id as usize)?; | ||
shard_cps.get((height as u64 % (shard_cps.len() as u64)) as usize).copied() | ||
} | ||
Self::V2(v2) => { | ||
let cp_settlement = &v2.chunk_producers_settlement; | ||
let shard_cps = &cp_settlement[shard_id as usize]; | ||
shard_cps[(height as u64 % (shard_cps.len() as u64)) as usize] | ||
let shard_cps = cp_settlement.get(shard_id as usize)?; | ||
shard_cps.get((height as u64 % (shard_cps.len() as u64)) as usize).copied() | ||
} | ||
Self::V3(v3) => { | ||
let protocol_version = self.protocol_version(); | ||
let seed = | ||
Self::chunk_produce_seed(protocol_version, &v3.rng_seed, height, shard_id); | ||
let shard_id = shard_id as usize; | ||
let sample = v3.chunk_producers_sampler[shard_id].sample(seed); | ||
v3.chunk_producers_settlement[shard_id][sample] | ||
let sample = v3.chunk_producers_sampler.get(shard_id)?.sample(seed); | ||
v3.chunk_producers_settlement.get(shard_id)?.get(sample).copied() | ||
} | ||
Self::V4(v4) => { | ||
let protocol_version = self.protocol_version(); | ||
let seed = | ||
Self::chunk_produce_seed(protocol_version, &v4.rng_seed, height, shard_id); | ||
let shard_id = shard_id as usize; | ||
let sample = v4.chunk_producers_sampler[shard_id].sample(seed); | ||
v4.chunk_producers_settlement[shard_id][sample] | ||
let sample = v4.chunk_producers_sampler.get(shard_id)?.sample(seed); | ||
v4.chunk_producers_settlement.get(shard_id)?.get(sample).copied() | ||
} | ||
} | ||
} | ||
Comment on lines
+1113
to
1117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So IIUC we are now validating the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's another time that an invalid shard_id could cause a crash (#10621 ...), I think it would be good to go through the code and just remove all usages of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opened #10648 |
||
|
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.
Is it safe to
unwrap()
here? The function returns an Error, so maybe it would be better to return an error.(Also applies to other
unwraps()
on the newsample_chunk_producer
)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.
shard id should be valid here
let shard_ids = self.epoch_manager.shard_ids(&epoch_id)?
returning error requires a bit of refactoring here since it is part of
map
, so we cannot just add?
, so probably should be done in a separate PR