Avoid resizing attn signature sets vec (#2184)
## Issue Addressed
NA
## Proposed Changes
Reduces allocations by initializing the `pubkeys` vec to its final size. I doubt this will make a substantial difference, but it's nice to do it this way.
Seeing as `indexed_attestation.attesting_indices` has a [fixed length](e4b62139d7/consensus/types/src/indexed_attestation.rs (L22)
), there's no real risk of a memory blow-up by pre-allocating the size of the `Vec`.
## Additional Info
NA
This commit is contained in:
parent
194609d210
commit
7c059117f4
@ -202,13 +202,12 @@ where
|
|||||||
T: EthSpec,
|
T: EthSpec,
|
||||||
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
|
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
|
||||||
{
|
{
|
||||||
let pubkeys = indexed_attestation
|
let mut pubkeys = Vec::with_capacity(indexed_attestation.attesting_indices.len());
|
||||||
.attesting_indices
|
for &validator_idx in &indexed_attestation.attesting_indices {
|
||||||
.into_iter()
|
pubkeys.push(
|
||||||
.map(|&validator_idx| {
|
get_pubkey(validator_idx as usize).ok_or(Error::ValidatorUnknown(validator_idx))?,
|
||||||
Ok(get_pubkey(validator_idx as usize).ok_or(Error::ValidatorUnknown(validator_idx))?)
|
);
|
||||||
})
|
}
|
||||||
.collect::<Result<_>>()?;
|
|
||||||
|
|
||||||
let domain = spec.get_domain(
|
let domain = spec.get_domain(
|
||||||
indexed_attestation.data.target.epoch,
|
indexed_attestation.data.target.epoch,
|
||||||
@ -236,13 +235,12 @@ where
|
|||||||
T: EthSpec,
|
T: EthSpec,
|
||||||
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
|
F: Fn(usize) -> Option<Cow<'a, PublicKey>>,
|
||||||
{
|
{
|
||||||
let pubkeys = indexed_attestation
|
let mut pubkeys = Vec::with_capacity(indexed_attestation.attesting_indices.len());
|
||||||
.attesting_indices
|
for &validator_idx in &indexed_attestation.attesting_indices {
|
||||||
.into_iter()
|
pubkeys.push(
|
||||||
.map(|&validator_idx| {
|
get_pubkey(validator_idx as usize).ok_or(Error::ValidatorUnknown(validator_idx))?,
|
||||||
Ok(get_pubkey(validator_idx as usize).ok_or(Error::ValidatorUnknown(validator_idx))?)
|
);
|
||||||
})
|
}
|
||||||
.collect::<Result<_>>()?;
|
|
||||||
|
|
||||||
let domain = spec.get_domain(
|
let domain = spec.get_domain(
|
||||||
indexed_attestation.data.target.epoch,
|
indexed_attestation.data.target.epoch,
|
||||||
|
Loading…
Reference in New Issue
Block a user