Skip to content

feat(argus): internal interfaces and shared memory model #2682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 13, 2025

Conversation

tejasbadadare
Copy link
Contributor

@tejasbadadare tejasbadadare commented May 12, 2025

Summary

Skeleton for Argus. Defines code organization, internal interfaces, and sets up a services + shared memory model.
Previously I had explored implementing Argus with an actor model (#2659 ), but after useful feedback, it feels more straightforward to go with a more standard shared memory approach.

We still keep the isolation and separation of concerns from the actor model, but without the message-box concept for IPC.
I also considered implementing the trait system from Hermes to gate access to certain State objects behind traits, but found it didn't add much value here.

Services

Services are long-running processes (tokio tasks) responsible for executing business logic and keeping relevant States up-to-date (e.g. via polling or subscribing to data sources via Adapters.)

  • For example, the ControllerService reads from SubscriptionState, PythPriceState, and ChainPriceState to determine whether or not to trigger an update. The SubscriptionService writes to SubscriptionState as it tracks changes to on-chain subscription metadata.

State

The State objects hold the state for Argus for a specific blockchain and expose them to Services via read/write APIs, wrapping the underlying data structure with synchronization primitives like RwLock and DashMap.

Adapters

Interactions with external services like Hermes and the blockchain are modeled by the traits in adapters/types.rs. These traits are used by the actors, and are implemented by hermes.rs, contract.rs, etc.

  • For example, the SubscriptionService expects an implementor of ReadChainSubscriptions. This trait specifies get_active_subscriptions() and subscribe_to_subscription_events(), which are impl'd by PythPulse in contract.rs.

How has this been tested?

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

Not tested yet. Next up is wiring up the Controller's main update loop to mock implementations, and ensuring the actor communication works. Then, we will implement individual actor logic, and eventually wire it up to the blockchain instead of mock adapters.

Copy link

vercel bot commented May 12, 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 13, 2025 9:21pm
component-library ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 9:21pm
entropy-debugger ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 9:21pm
entropy-explorer ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 9:21pm
insights ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 9:21pm
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 9:21pm
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 9:21pm

Copy link
Collaborator

@ali-behjati ali-behjati left a comment

Choose a reason for hiding this comment

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

Nice!

async fn subscribe_to_price_updates(&self, feed_ids: &[PriceId]) -> Result<()>; // TODO: return a stream
}

// TODO: find a different home for these (public SDK)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep! will use the types in there

pyth_price_client: Arc<dyn ReadPythPrices + Send + Sync>,
backoff_policy: ExponentialBackoff,
request_rx: Mutex<Option<mpsc::Receiver<PushRequest>>>,
request_tx: mpsc::Sender<PushRequest>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

how are you going to share it with others?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will be shared with other services' new() functions. Only the Controller uses it right now, so we could have just returned a reference to this service directly, but the channel is helpful to decouple the two imo.

Comment on lines +34 to +36
subscription_state: Arc<SubscriptionState>,
pyth_price_state: Arc<PythPriceState>,
chain_price_state: Arc<ChainPriceState>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah so instead of relying on the magic of type inferences you decided to literally pass the states around. good idea!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's less robust isolation, but a lot simpler to implement and reason about 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

i recommend moving some of these in to the files to reduce indirection if they are only used in one place.

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.

yeah this is better than the actors for sure

) -> Result<()> {
tracing::info!("Starting keeper for chain {}", chain_name);

// TODO: create a contract with a WS provider if geth_rpc_wss was provided
Copy link
Contributor

Choose a reason for hiding this comment

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

you probably don't have to worry about the wss feature -- we don't even use this in fortuna. you can probably delete this feature entirely

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah okay cool. Figured it would be nice to primarily stream in price updates and only poll as a backup, but I can imagine wss support/reliability is spotty with RPCs.

let state = Arc::new(ArgusState::new());

let hermes_client = Arc::new(HermesClient);
let subscription_poll_interval = Duration::from_secs(60);
Copy link
Contributor

Choose a reason for hiding this comment

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

in the future: please make these configurable from the config file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep definitely

state.chain_price_state.clone(),
);

let pyth_price_service = PythPriceService::new(
Copy link
Contributor

Choose a reason for hiding this comment

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

do you really want to instantiate a separate one of these per chain? I think you could probably run a single thread that listens to the hermes websocket and streams the prices to check across all chains.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeahh i had the same thought, this was the path of least resistance since we can just replace the tracked feed ID set per chain. Later I'll extract this out to be a single thread with redundant connections and the like.

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