Skip to content

Commit 8d1abce

Browse files
authored
Bump SSZ version for larger bitfield SmallVec (#6915)
NA Bumps the `ethereum_ssz` version, along with other crates that share the dep. Primarily, this give us bitfields which can store 128 bytes on the stack before allocating, rather than 32 bytes (sigp/ethereum_ssz#38). The validator count has increase massively since we set it at 32 bytes, so aggregation bitfields (et al) now require a heap allocation. This new value of 128 should get us to ~2m active validators.
1 parent b4e79ed commit 8d1abce

File tree

13 files changed

+192
-62
lines changed

13 files changed

+192
-62
lines changed

Cargo.lock

Lines changed: 52 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ discv5 = { version = "0.9", features = ["libp2p"] }
137137
env_logger = "0.9"
138138
ethereum_hashing = "0.7.0"
139139
ethereum_serde_utils = "0.7"
140-
ethereum_ssz = "0.7"
141-
ethereum_ssz_derive = "0.7"
140+
ethereum_ssz = "0.8.2"
141+
ethereum_ssz_derive = "0.8.2"
142142
ethers-core = "1"
143143
ethers-providers = { version = "1", default-features = false }
144144
exit-future = "0.2"
@@ -154,7 +154,7 @@ libsecp256k1 = "0.7"
154154
log = "0.4"
155155
lru = "0.12"
156156
maplit = "1"
157-
milhouse = "0.3"
157+
milhouse = "0.5"
158158
mockito = "1.5.0"
159159
num_cpus = "1"
160160
parking_lot = "0.12"
@@ -192,7 +192,7 @@ slog-term = "2"
192192
sloggers = { version = "2", features = ["json"] }
193193
smallvec = { version = "1.11.2", features = ["arbitrary"] }
194194
snap = "1"
195-
ssz_types = "0.8"
195+
ssz_types = "0.10"
196196
strum = { version = "0.24", features = ["derive"] }
197197
superstruct = "0.8"
198198
syn = "1"
@@ -211,8 +211,8 @@ tracing-appender = "0.2"
211211
tracing-core = "0.1"
212212
tracing-log = "0.2"
213213
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
214-
tree_hash = "0.8"
215-
tree_hash_derive = "0.8"
214+
tree_hash = "0.9"
215+
tree_hash_derive = "0.9"
216216
url = "2"
217217
uuid = { version = "0.8", features = ["serde", "v4"] }
218218
warp = { version = "0.3.7", default-features = false, features = ["tls"] }

beacon_node/beacon_chain/src/test_utils.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,16 +2713,16 @@ where
27132713
let mut block_hash_from_slot: HashMap<Slot, SignedBeaconBlockHash> = HashMap::new();
27142714
let mut state_hash_from_slot: HashMap<Slot, BeaconStateHash> = HashMap::new();
27152715
for slot in slots {
2716-
let (block_hash, new_state) = self
2717-
.add_attested_block_at_slot_with_sync(
2718-
*slot,
2719-
state,
2720-
state_root,
2721-
validators,
2722-
sync_committee_strategy,
2723-
)
2724-
.await
2725-
.unwrap();
2716+
// Using a `Box::pin` to reduce the stack size. Clippy was raising a lints.
2717+
let (block_hash, new_state) = Box::pin(self.add_attested_block_at_slot_with_sync(
2718+
*slot,
2719+
state,
2720+
state_root,
2721+
validators,
2722+
sync_committee_strategy,
2723+
))
2724+
.await
2725+
.unwrap();
27262726

27272727
state = new_state;
27282728

beacon_node/beacon_chain/tests/rewards.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ async fn test_rewards_base_multi_inclusion() {
328328
.extend_slots(E::slots_per_epoch() as usize * 2 - 4)
329329
.await;
330330

331-
// pin to reduce stack size for clippy
332-
Box::pin(check_all_base_rewards(&harness, initial_balances)).await;
331+
check_all_base_rewards(&harness, initial_balances).await;
333332
}
334333

335334
#[tokio::test]
@@ -692,7 +691,8 @@ async fn check_all_base_rewards(
692691
harness: &BeaconChainHarness<EphemeralHarnessType<E>>,
693692
balances: Vec<u64>,
694693
) {
695-
check_all_base_rewards_for_subset(harness, balances, vec![]).await;
694+
// The box reduces the size on the stack for a clippy lint.
695+
Box::pin(check_all_base_rewards_for_subset(harness, balances, vec![])).await;
696696
}
697697

698698
async fn check_all_base_rewards_for_subset(

beacon_node/lighthouse_network/src/rpc/codec.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,8 @@ fn handle_rpc_response<E: EthSpec>(
765765
SupportedProtocol::PingV1 => Ok(Some(RpcSuccessResponse::Pong(Ping {
766766
data: u64::from_ssz_bytes(decoded_buffer)?,
767767
}))),
768-
SupportedProtocol::MetaDataV1 => Ok(Some(RpcSuccessResponse::MetaData(MetaData::V1(
769-
MetaDataV1::from_ssz_bytes(decoded_buffer)?,
768+
SupportedProtocol::MetaDataV1 => Ok(Some(RpcSuccessResponse::MetaData(Arc::new(
769+
MetaData::V1(MetaDataV1::from_ssz_bytes(decoded_buffer)?),
770770
)))),
771771
SupportedProtocol::LightClientBootstrapV1 => match fork_name {
772772
Some(fork_name) => Ok(Some(RpcSuccessResponse::LightClientBootstrap(Arc::new(
@@ -826,11 +826,11 @@ fn handle_rpc_response<E: EthSpec>(
826826
)),
827827
},
828828
// MetaData V2/V3 responses have no context bytes, so behave similarly to V1 responses
829-
SupportedProtocol::MetaDataV3 => Ok(Some(RpcSuccessResponse::MetaData(MetaData::V3(
830-
MetaDataV3::from_ssz_bytes(decoded_buffer)?,
829+
SupportedProtocol::MetaDataV3 => Ok(Some(RpcSuccessResponse::MetaData(Arc::new(
830+
MetaData::V3(MetaDataV3::from_ssz_bytes(decoded_buffer)?),
831831
)))),
832-
SupportedProtocol::MetaDataV2 => Ok(Some(RpcSuccessResponse::MetaData(MetaData::V2(
833-
MetaDataV2::from_ssz_bytes(decoded_buffer)?,
832+
SupportedProtocol::MetaDataV2 => Ok(Some(RpcSuccessResponse::MetaData(Arc::new(
833+
MetaData::V2(MetaDataV2::from_ssz_bytes(decoded_buffer)?),
834834
)))),
835835
SupportedProtocol::BlocksByRangeV2 => match fork_name {
836836
Some(ForkName::Altair) => Ok(Some(RpcSuccessResponse::BlocksByRange(Arc::new(
@@ -1008,6 +1008,7 @@ mod tests {
10081008
) -> SignedBeaconBlock<Spec> {
10091009
let mut block: BeaconBlockBellatrix<_, FullPayload<Spec>> =
10101010
BeaconBlockBellatrix::empty(&Spec::default_spec());
1011+
10111012
let tx = VariableList::from(vec![0; 1024]);
10121013
let txs = VariableList::from(std::iter::repeat(tx).take(5000).collect::<Vec<_>>());
10131014

@@ -1027,6 +1028,7 @@ mod tests {
10271028
) -> SignedBeaconBlock<Spec> {
10281029
let mut block: BeaconBlockBellatrix<_, FullPayload<Spec>> =
10291030
BeaconBlockBellatrix::empty(&Spec::default_spec());
1031+
10301032
let tx = VariableList::from(vec![0; 1024]);
10311033
let txs = VariableList::from(std::iter::repeat(tx).take(100000).collect::<Vec<_>>());
10321034

@@ -1105,28 +1107,31 @@ mod tests {
11051107
Ping { data: 1 }
11061108
}
11071109

1108-
fn metadata() -> MetaData<Spec> {
1110+
fn metadata() -> Arc<MetaData<Spec>> {
11091111
MetaData::V1(MetaDataV1 {
11101112
seq_number: 1,
11111113
attnets: EnrAttestationBitfield::<Spec>::default(),
11121114
})
1115+
.into()
11131116
}
11141117

1115-
fn metadata_v2() -> MetaData<Spec> {
1118+
fn metadata_v2() -> Arc<MetaData<Spec>> {
11161119
MetaData::V2(MetaDataV2 {
11171120
seq_number: 1,
11181121
attnets: EnrAttestationBitfield::<Spec>::default(),
11191122
syncnets: EnrSyncCommitteeBitfield::<Spec>::default(),
11201123
})
1124+
.into()
11211125
}
11221126

1123-
fn metadata_v3() -> MetaData<Spec> {
1127+
fn metadata_v3() -> Arc<MetaData<Spec>> {
11241128
MetaData::V3(MetaDataV3 {
11251129
seq_number: 1,
11261130
attnets: EnrAttestationBitfield::<Spec>::default(),
11271131
syncnets: EnrSyncCommitteeBitfield::<Spec>::default(),
11281132
custody_group_count: 1,
11291133
})
1134+
.into()
11301135
}
11311136

11321137
/// Encodes the given protocol response as bytes.

beacon_node/lighthouse_network/src/rpc/methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ pub enum RpcSuccessResponse<E: EthSpec> {
578578
Pong(Ping),
579579

580580
/// A response to a META_DATA request.
581-
MetaData(MetaData<E>),
581+
MetaData(Arc<MetaData<E>>),
582582
}
583583

584584
/// Indicates which response is being terminated by a stream termination response.

beacon_node/lighthouse_network/src/service/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ impl<E: EthSpec> Network<E> {
11901190
) {
11911191
let metadata = self.network_globals.local_metadata.read().clone();
11921192
// The encoder is responsible for sending the negotiated version of the metadata
1193-
let event = RpcResponse::Success(RpcSuccessResponse::MetaData(metadata));
1193+
let event = RpcResponse::Success(RpcSuccessResponse::MetaData(Arc::new(metadata)));
11941194
self.eth2_rpc_mut()
11951195
.send_response(peer_id, id, request_id, event);
11961196
}
@@ -1605,7 +1605,7 @@ impl<E: EthSpec> Network<E> {
16051605
}
16061606
RpcSuccessResponse::MetaData(meta_data) => {
16071607
self.peer_manager_mut()
1608-
.meta_data_response(&peer_id, meta_data);
1608+
.meta_data_response(&peer_id, meta_data.as_ref().clone());
16091609
None
16101610
}
16111611
/* Network propagated protocols */

0 commit comments

Comments
 (0)