Skip to content

Commit d48eec5

Browse files
committed
fix: use Vec instead of HashSet for addresses field
Signed-off-by: William Hankins <[email protected]>
1 parent d364c32 commit d48eec5

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

modules/historical_accounts_state/src/immutable_historical_account_store.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl ImmutableHistoricalAccountStore {
316316
);
317317
Self::extend_opt_vec(&mut agg_entry.withdrawal_history, entry.withdrawal_history);
318318
Self::extend_opt_vec(&mut agg_entry.mir_history, entry.mir_history);
319-
Self::extend_opt_set(&mut agg_entry.addresses, entry.addresses);
319+
Self::extend_opt_vec_ordered(&mut agg_entry.addresses, entry.addresses);
320320
}
321321
acc
322322
})
@@ -378,13 +378,22 @@ impl ImmutableHistoricalAccountStore {
378378
}
379379
}
380380

381-
fn extend_opt_set<T>(target: &mut Option<HashSet<T>>, src: Option<HashSet<T>>)
381+
fn extend_opt_vec_ordered<T>(target: &mut Option<Vec<T>>, src: Option<Vec<T>>)
382382
where
383-
T: Eq + Hash,
383+
T: Eq + Hash + Clone,
384384
{
385-
if let Some(mut s) = src {
386-
if !s.is_empty() {
387-
target.get_or_insert_with(HashSet::new).extend(s.drain());
385+
if let Some(src_vec) = src {
386+
if src_vec.is_empty() {
387+
return;
388+
}
389+
390+
let target_vec = target.get_or_insert_with(Vec::new);
391+
let mut seen: HashSet<T> = target_vec.iter().cloned().collect();
392+
393+
for item in src_vec {
394+
if seen.insert(item.clone()) {
395+
target_vec.push(item);
396+
}
388397
}
389398
}
390399
}

modules/historical_accounts_state/src/state.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct AccountEntry {
3232
pub registration_history: Option<Vec<RegistrationUpdate>>,
3333
pub withdrawal_history: Option<Vec<AccountWithdrawal>>,
3434
pub mir_history: Option<Vec<AccountWithdrawal>>,
35-
pub addresses: Option<HashSet<ShelleyAddress>>,
35+
pub addresses: Option<Vec<ShelleyAddress>>,
3636
}
3737

3838
#[derive(Debug, Clone, minicbor::Decode, minicbor::Encode)]
@@ -232,7 +232,7 @@ impl State {
232232
.entry(delta.stake_address.clone())
233233
.or_default()
234234
.addresses
235-
.get_or_insert_with(HashSet::new)
235+
.get_or_insert_with(Vec::new)
236236
.extend(delta.addresses.clone());
237237
}
238238
}
@@ -358,10 +358,7 @@ impl State {
358358
&self,
359359
account: &StakeAddress,
360360
) -> Result<Option<Vec<ShelleyAddress>>> {
361-
let mut addresses = match self.immutable.get_addresses(account).await? {
362-
Some(list) => list,
363-
None => Vec::new(),
364-
};
361+
let mut addresses = self.immutable.get_addresses(account).await?.unwrap_or_default();
365362

366363
let mut seen: HashSet<ShelleyAddress> = addresses.iter().cloned().collect();
367364
for block_map in self.volatile.window.iter() {

processes/omnibus/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub async fn main() -> Result<()> {
118118
SPDDState::register(&mut process);
119119
DRDDState::register(&mut process);
120120
Consensus::register(&mut process);
121-
//ChainStore::register(&mut process);
121+
ChainStore::register(&mut process);
122122

123123
Clock::<Message>::register(&mut process);
124124
RESTServer::<Message>::register(&mut process);

0 commit comments

Comments
 (0)