Skip to content

Shuffling for 32 bit platforms #7725

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

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions consensus/swap_or_not_shuffle/src/shuffle_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ pub fn shuffle_list(
loop {
buf.set_round(r);

let pivot = buf.raw_pivot() as usize % list_size;

let pivot = (buf.raw_pivot() % list_size as u64) as usize;
Copy link
Member

Choose a reason for hiding this comment

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

This looks good to me. It should allow us to support lists up to size 2**32 (4B) on 32-bit platforms.

let mirror = (pivot + 1) >> 1;

buf.mix_in_position(pivot >> 8);
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/subnet_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl SubnetId {

let node_id = U256::from_be_slice(&raw_node_id);
// calculate the prefixes used to compute the subnet and shuffling
let node_id_prefix = (node_id >> (NODE_ID_BITS - prefix_bits))
let node_id_prefix = (node_id >> (NODE_ID_BITS - prefix_bits) as u32)
Copy link
Member

Choose a reason for hiding this comment

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

Rather than casting between u64 I think we may as well just write everything in terms of u32s

diff --git a/consensus/types/src/subnet_id.rs b/consensus/types/src/subnet_id.rs
index 061b295276..5f93161f22 100644
--- a/consensus/types/src/subnet_id.rs
+++ b/consensus/types/src/subnet_id.rs
@@ -11,7 +11,7 @@ const MAX_SUBNET_ID: usize = 64;
 
 /// The number of bits in a Discovery `NodeId`. This is used for binary operations on the node-id
 /// data.
-const NODE_ID_BITS: u64 = 256;
+const NODE_ID_BITS: u32 = 256;
 
 static SUBNET_ID_TO_STRING: LazyLock<Vec<String>> = LazyLock::new(|| {
     let mut v = Vec::with_capacity(MAX_SUBNET_ID);
@@ -101,11 +101,11 @@ impl SubnetId {
         spec: &ChainSpec,
     ) -> impl Iterator<Item = SubnetId> {
         // The bits of the node-id we are using to define the subnets.
-        let prefix_bits = spec.attestation_subnet_prefix_bits as u64;
+        let prefix_bits = spec.attestation_subnet_prefix_bits as u32;
 
         let node_id = U256::from_be_slice(&raw_node_id);
         // calculate the prefixes used to compute the subnet and shuffling
-        let node_id_prefix = (node_id >> (NODE_ID_BITS - prefix_bits) as u32)
+        let node_id_prefix = (node_id >> (NODE_ID_BITS - prefix_bits))
             .as_le_slice()
             .get_u64_le();

.as_le_slice()
.get_u64_le();

Expand Down