Skip to content

Conversation

@lowhung
Copy link
Collaborator

@lowhung lowhung commented Oct 22, 2025

Description

Resolves issue #163

This adds NetworkId into the BlockInfo struct via the Mithril and Upstream fetchers, and introduces the identifier into the account state, drep state, epochs state and rest_blockfrost as these all rely on querying the StakeAddressMap which has had it's API updated to require StakeAddress structs as its key.

@lowhung lowhung changed the base branch from main to lowhung/163-replace-reward-account-with-stake-address October 22, 2025 04:46
Resolves issue #163

This adds `NetworkId` into the `BlockInfo` struct, and introduces this identifier into the account state, drep state, epochs state and rest_blockfrost as these all rely on querying the `StakeAddressMap`.
@lowhung lowhung force-pushed the lowhung/163-replace-reward-account-with-stake-address-block-info-network-id branch from 1bfa43a to fe8c1c9 Compare October 22, 2025 04:54
Copy link
Collaborator

@sandtreader sandtreader left a comment

Choose a reason for hiding this comment

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

Main issue is not to store networkId in state - there's no need, and no sensible place to capture it (first message? Any message?). It should always be available in BlockInfo except for things that create blocks where it's configured (as you have done).

To avoid having to pass it around I've suggested changing parameters to be full StakeAddresses, so the caller (which is usually a message handler) can do the conversion. Even better, the messages should have StakeAddresses instead of StakeCredentials (which may fall away altogether), so it's things like TxUnpacker which do the conversion based on the NetworkID they get in their BlockInfo.

If we apply the same change to the REST query responses I think we can avoid having to configure network in RESTBlockfrost too.

/// List of SPOs (by operator ID) retiring in the current epoch
retiring_spos: Vec<KeyHash>,

/// Network ID
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need to store this (and it there's no obvious place to capture it anyway) - get it from BlockInfo in the message handlers and pass it down to things that need it, or convert to StakeAddress before calling them.

pub struct State {
pub config: DRepStorageConfig,
pub dreps: HashMap<DRepCredential, DRepRecord>,
pub network_id: NetworkId,
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to store, as above

let stake_keys: Vec<KeyHash> = delegators.iter().map(|(sc, _)| sc.get_hash()).collect();
// TODO: USE NETWORK ID
let stake_addresses: Vec<StakeAddress> = delegators.iter().map(|(k, _) | k.to_stake_address(None) ).collect();
let stake_addresses: Vec<StakeAddress> = delegators.iter().map(|(k, _) | k.to_stake_address(self.network_id.clone().into()) ).collect();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd make delegators a Vec<(&StakeAddress, &DRepChoice)> which will push the need for networkId out to the caller and make it easier to replace StakeCredential entirely if required.

.get_string("network-id")
.unwrap_or(DEFAULT_NETWORK_ID.to_string()),
);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes great

pub parameters_query_topic: String,
pub external_api_timeout: u64,
pub offchain_token_registry_url: String,
pub network_id: NetworkId,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, shame we have to configure this here... Can we change the queries so the data comes back as StakeAddresses so we don't need to? With the pool owners I think we talked about doing that anyway...


epoch: u64,

network_id: NetworkId,
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to store, as above

};
let mut stake_addresses = stake_addresses.lock().unwrap();
stake_addresses.register_stake_address(&credential.to_stake_address(None));
stake_addresses
Copy link
Collaborator

Choose a reason for hiding this comment

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

As above, change parameter to StakeAddress and make the caller do the conversion so we don't need the networkID here.

[module.block-unpacker]

[module.rest-blockfrost]
network = "mainnet"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hopefully we can lose this one. The others make perfect sense.

…ddress` handling in tx_unpacker.rs

- Removed `NetworkId` from structures and functions across modules.
- Replaced `KeyHash` and `Credential` usage with `StakeAddress` for consistency.
@lowhung lowhung force-pushed the lowhung/163-replace-reward-account-with-stake-address-block-info-network-id branch from b876970 to b166d93 Compare October 22, 2025 20:02
@lowhung lowhung force-pushed the lowhung/163-replace-reward-account-with-stake-address-block-info-network-id branch from b166d93 to de08f0a Compare October 22, 2025 20:07
@lowhung lowhung merged commit 2faea48 into lowhung/163-replace-reward-account-with-stake-address Oct 22, 2025
@SupernaviX SupernaviX deleted the lowhung/163-replace-reward-account-with-stake-address-block-info-network-id branch October 28, 2025 17: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