Skip to content

Conversation

m30m
Copy link
Contributor

@m30m m30m commented Apr 29, 2025

Summary

  • Each chain is started separately
  • Run block timestamp tracking only if chain is registered
  • Run hash generation in a blocking thread so that tokio can continue async operations
  • Retry chain startup on failure

Rationale

These changes improve the reliability of running fortuna in production.

How has this been tested?

  • Current tests cover my changes
  • Added new tests
  • Manually tested the code

@vercel
Copy link

vercel bot commented Apr 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2025 1:30am
component-library ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2025 1:30am
entropy-debugger ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2025 1:30am
insights ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2025 1:30am
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2025 1:30am
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2025 1:30am

#[derive(Clone)]
pub struct ApiState {
pub chains: Arc<HashMap<ChainId, BlockchainState>>,
pub chains: Arc<RwLock<HashMap<ChainId, BlockchainState>>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

you can use Dashmap for a concurrent hashmap https://docs.rs/dashmap/latest/dashmap/struct.DashMap.html

Copy link
Contributor

Choose a reason for hiding this comment

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

Also I think this should be a HashMap<ChainId, Option<BlockchainState>> so "chain is uninitialized" isn't conflated with "unknown chain id". You could make BlockchainState an enum or something as well to handle this.

chains.insert(chain_id.clone(), state);
match state {
Ok(state) => {
keeper_metrics.add_chain(chain_id.clone(), state.provider_address);
Copy link
Contributor

Choose a reason for hiding this comment

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

it's probably better to run this for every chain before it's set up (?) wondering how we will report metrics in the case where the chain never gets initialized.

}

pub fn from_config(
pub async fn from_config(
Copy link
Contributor

Choose a reason for hiding this comment

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

can i suggest making a separate constructor method that spawns the original from_config in a blocking thread? like from_config_async

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

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

nice

pub enum ApiBlockChainState {
Uninitialized,
Initialized(BlockchainState),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

}

#[allow(clippy::too_many_arguments)]
async fn setup_chain(
Copy link
Contributor

Choose a reason for hiding this comment

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

setup_chain_and_run_keeper ?

[[package]]
name = "fortuna"
version = "7.5.2"
version = "7.5.3"
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this here but not in Cargo.toml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

main branch didn't updated the Cargo.lock

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.

2 participants