Skip to content

Commit a7cfb00

Browse files
committed
Delete unused byte_array module and remove associated references for cleanup. Refactor POOL_KEY_LENGTH to POOL_ID_LENGTH
1 parent 41681ea commit a7cfb00

File tree

6 files changed

+21
-114
lines changed

6 files changed

+21
-114
lines changed

common/src/byte_array.rs

Lines changed: 0 additions & 89 deletions
This file was deleted.

common/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Acropolis common library - main library exports
22

33
pub mod address;
4-
pub mod byte_array;
54
pub mod calculations;
65
pub mod cip19;
76
pub mod commands;

modules/accounts_state/src/rewards.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use crate::snapshot::{Snapshot, SnapshotSPO};
44
use acropolis_common::{
5-
protocol_params::ShelleyParams, rational_number::RationalNumber, Lovelace, PoolId,
6-
SPORewards, StakeAddress,
5+
protocol_params::ShelleyParams, rational_number::RationalNumber, Lovelace, PoolId, SPORewards,
6+
StakeAddress,
77
};
88
use anyhow::{bail, Result};
99
use bigdecimal::{BigDecimal, One, ToPrimitive, Zero};

modules/accounts_state/src/snapshot.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
33
use crate::state::{Pots, RegistrationChange};
44
use acropolis_common::{
5-
stake_addresses::StakeAddressMap, Lovelace, PoolId, PoolRegistration, Ratio,
6-
StakeAddress,
5+
stake_addresses::StakeAddressMap, Lovelace, PoolId, PoolRegistration, Ratio, StakeAddress,
76
};
87
use imbl::OrdMap;
98
use std::collections::HashMap;

modules/accounts_state/src/spo_distribution_store.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,36 @@ use acropolis_common::PoolId;
55
use anyhow::Result;
66
use fjall::{Config, Keyspace, PartitionCreateOptions};
77

8-
const POOL_KEY_LENGTH: usize = 28;
8+
const POOL_ID_LENGTH: usize = 28;
99
const STAKE_KEY_LEN: usize = 28;
1010
const EPOCH_LEN: usize = 8;
11-
const TOTAL_KEY_LEN: usize = EPOCH_LEN + POOL_KEY_LENGTH + STAKE_KEY_LEN;
11+
const TOTAL_KEY_LEN: usize = EPOCH_LEN + POOL_ID_LENGTH + STAKE_KEY_LEN;
1212

1313
// Batch size balances commit overhead vs memory usage
1414
// ~720KB per batch (72 bytes × 10,000)
1515
// ~130 commits for typical epoch (~1.3M delegations)
1616
const BATCH_SIZE: usize = 10_000;
1717

18-
fn encode_key(epoch: u64, pool_key: &PoolId, stake_key: &AddrKeyhash) -> Vec<u8> {
18+
fn encode_key(epoch: u64, pool_id: &PoolId, stake_key: &AddrKeyhash) -> Vec<u8> {
1919
let mut key = Vec::with_capacity(TOTAL_KEY_LEN);
2020
key.extend_from_slice(&epoch.to_be_bytes());
21-
key.extend_from_slice(pool_key.as_ref());
21+
key.extend_from_slice(pool_id.as_ref());
2222
key.extend_from_slice(stake_key.as_ref());
2323
key
2424
}
2525

26-
fn encode_epoch_pool_prefix(epoch: u64, pool_key: &PoolId) -> Vec<u8> {
27-
let mut prefix = Vec::with_capacity(EPOCH_LEN + POOL_KEY_LENGTH);
26+
fn encode_epoch_pool_prefix(epoch: u64, pool_id: &PoolId) -> Vec<u8> {
27+
let mut prefix = Vec::with_capacity(EPOCH_LEN + POOL_ID_LENGTH);
2828
prefix.extend_from_slice(&epoch.to_be_bytes());
29-
prefix.extend_from_slice(pool_key.as_ref());
29+
prefix.extend_from_slice(pool_id.as_ref());
3030
prefix
3131
}
3232

3333
fn decode_key(key: &[u8]) -> Result<(u64, PoolId, AddrKeyhash)> {
3434
let epoch = u64::from_be_bytes(key[..EPOCH_LEN].try_into()?);
35-
let pool_key: PoolId = key[EPOCH_LEN..EPOCH_LEN + POOL_KEY_LENGTH].try_into()?;
36-
let stake_key: AddrKeyhash = key[EPOCH_LEN + POOL_KEY_LENGTH..].try_into()?;
37-
Ok((epoch, pool_key, stake_key))
35+
let pool_id: PoolId = key[EPOCH_LEN..EPOCH_LEN + POOL_ID_LENGTH].try_into()?;
36+
let stake_key: AddrKeyhash = key[EPOCH_LEN + POOL_ID_LENGTH..].try_into()?;
37+
Ok((epoch, pool_id, stake_key))
3838
}
3939

4040
/// Encode epoch completion marker key
@@ -45,7 +45,7 @@ fn encode_epoch_marker(epoch: u64) -> Vec<u8> {
4545
pub struct SPDDStore {
4646
keyspace: Keyspace,
4747
/// Partition for all SPDD data
48-
/// Key format: epoch(8 bytes) + pool_key + stake_key
48+
/// Key format: epoch(8 bytes) + pool_id + stake_key
4949
/// Value: amount(8 bytes)
5050
spdd: fjall::PartitionHandle,
5151
/// Partition for epoch completion markers
@@ -110,9 +110,9 @@ impl SPDDStore {
110110

111111
let mut batch = self.keyspace.batch();
112112
let mut count = 0;
113-
for (pool_key, delegations) in spdd_state {
113+
for (pool_id, delegations) in spdd_state {
114114
for (stake_key, amount) in delegations {
115-
let key = encode_key(epoch, &pool_key, &stake_key);
115+
let key = encode_key(epoch, &pool_id, &stake_key);
116116
let value = amount.to_be_bytes();
117117
batch.insert(&self.spdd, key, value);
118118

@@ -192,23 +192,23 @@ impl SPDDStore {
192192
let mut result = Vec::new();
193193
for item in self.spdd.prefix(prefix) {
194194
let (key, value) = item?;
195-
let (_, pool_key, stake_key) = decode_key(&key)?;
195+
let (_, pool_id, stake_key) = decode_key(&key)?;
196196
let amount = u64::from_be_bytes(value.as_ref().try_into()?);
197-
result.push((pool_key, stake_key, amount));
197+
result.push((pool_id, stake_key, amount));
198198
}
199199
Ok(result)
200200
}
201201

202202
pub fn query_by_epoch_and_pool(
203203
&self,
204204
epoch: u64,
205-
pool_key: &PoolId,
205+
pool_id: &PoolId,
206206
) -> Result<Vec<(AddrKeyhash, u64)>> {
207207
if !self.is_epoch_complete(epoch)? {
208208
return Err(anyhow::anyhow!("Epoch SPDD Data is not complete"));
209209
}
210210

211-
let prefix = encode_epoch_pool_prefix(epoch, pool_key);
211+
let prefix = encode_epoch_pool_prefix(epoch, pool_id);
212212
let mut result = Vec::new();
213213
for item in self.spdd.prefix(prefix) {
214214
let (key, value) = item?;
@@ -224,13 +224,11 @@ impl SPDDStore {
224224
mod tests {
225225
use super::*;
226226
use acropolis_common::crypto::keyhash_224;
227-
// ADDED
228227
use acropolis_common::hash::AddrKeyhash;
229228
use acropolis_common::PoolId;
230229

231230
const DB_PATH: &str = "spdd_db";
232231

233-
// ADDED: Helper to create test hashes
234232
fn test_pool_hash(byte: u8) -> PoolId {
235233
PoolId::new(keyhash_224(&vec![byte]))
236234
}

modules/spdd_state/src/rest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::state::State;
2-
use acropolis_common::serialization::{Bech32Conversion};
2+
use acropolis_common::serialization::Bech32Conversion;
33
use acropolis_common::DelegatedStake;
44
use acropolis_common::{extract_strict_query_params, messages::RESTResponse};
55
use anyhow::Result;

0 commit comments

Comments
 (0)