Skip to content

Conversation

@lowhung
Copy link
Collaborator

@lowhung lowhung commented Oct 30, 2025

What

  • Refactors the rest of the KeyHash -> StakeAddress where it made sense
  • Adds network + hash into key encoding for spo distribution, this allows me to get the actual StakeAddress struct when decoding the key
  • Adds tests + a tempfile path for each test so that the db directories clean up after the tests run

@lowhung lowhung marked this pull request as draft October 30, 2025 22:07
# Conflicts:
#	common/src/stake_addresses.rs
#	modules/rest_blockfrost/src/handlers/epochs.rs
#	modules/rest_blockfrost/src/handlers/pools.rs
#	modules/rest_blockfrost/src/types.rs
#	modules/tx_unpacker/src/tx_unpacker.rs
…s and use to_/from_binary to encode the entire stake address (network + hash) so we can retrieve the stake address out of it.
…s and use to_/from_binary to encode the entire stake address (network + hash) so we can retrieve the stake address out of it.
…oving `Result` return type and add back documentation for SPDDStore methods and fields
@lowhung lowhung marked this pull request as ready for review October 31, 2025 18:48
@lowhung lowhung force-pushed the lowhung/refactor-key-hash-to-stake-address branch from d6604ec to aeb3a09 Compare October 31, 2025 18:59
fn decode_key(key: &[u8]) -> Result<(u64, PoolId, StakeAddress)> {
let epoch_bytes: [u8; EPOCH_LEN] = key[..EPOCH_LEN]
.try_into()
.map_err(|_| anyhow!("Failed to extract epoch bytes (offset 0-{})", EPOCH_LEN))?;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How do we feel about error handling like this? I see a few different conventions and I'd be curious to better understand

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think let epoch_bytes: [u8; EPOCH_LEN] = key[..EPOCH_LEN].try_into()? is fine so that the try_into error bubbles up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call 👍 that appears to be how we've done things elsewhere in this file too so I'll stick with letting it bubble up.

6511204

hex = { workspace = true }
imbl = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These weren't being used

rayon = "1.10.0"
csv = "1.3.1"
itertools = "0.14.0"
tempfile = "3"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm adding this so that the directories we store the test spo data into is cleaned up post test run. It wasn't being cleaned up before.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This should go under [dev-dependencies] since it's only used for tests and shouldn't be included in production builds.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, good catch

6511204

@lowhung lowhung force-pushed the lowhung/refactor-key-hash-to-stake-address branch from f0bfcd1 to 4037f85 Compare October 31, 2025 19:58

match serde_json::to_string_pretty(&response) {
Ok(json) => Ok(RESTResponse::with_json(200, &json)),
&format!("Failed to serialize DRep delegators: {e}"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would recommend split-view for this diff

ShelleyAddressPaymentPart::ScriptHash(data) => (data, 1),
};

// TODO: MH - make delegation hash an Option<Hash<28>> type
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll do this in another PR!

Copy link
Collaborator

@whankinsiv whankinsiv left a comment

Choose a reason for hiding this comment

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

Great job! This is looking a lot cleaner and I'm glad we were able to reduce the number of queries for the epoch endpoints.

rayon = "1.10.0"
csv = "1.3.1"
itertools = "0.14.0"
tempfile = "3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should go under [dev-dependencies] since it's only used for tests and shouldn't be included in production builds.

fn decode_key(key: &[u8]) -> Result<(u64, PoolId, StakeAddress)> {
let epoch_bytes: [u8; EPOCH_LEN] = key[..EPOCH_LEN]
.try_into()
.map_err(|_| anyhow!("Failed to extract epoch bytes (offset 0-{})", EPOCH_LEN))?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think let epoch_bytes: [u8; EPOCH_LEN] = key[..EPOCH_LEN].try_into()? is fine so that the try_into error bubbles up.

…decode_key` in `spo_distribution_store.rs`, and add `tempfile` as a dev dependency
@lowhung lowhung merged commit f652276 into main Oct 31, 2025
2 checks passed
@lowhung lowhung deleted the lowhung/refactor-key-hash-to-stake-address branch October 31, 2025 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants