|
| 1 | +//! Acropolis indexer module for Caryatid |
| 2 | +mod configuration; |
| 3 | + |
| 4 | +use acropolis_common::{ |
| 5 | + commands::chain_sync::ChainSyncCommand, |
| 6 | + hash::Hash, |
| 7 | + messages::{Command, Message}, |
| 8 | +}; |
| 9 | +use anyhow::Result; |
| 10 | +use caryatid_sdk::{module, Context}; |
| 11 | +use config::Config; |
| 12 | +use std::{str::FromStr, sync::Arc}; |
| 13 | +use tracing::info; |
| 14 | + |
| 15 | +use crate::configuration::IndexerConfig; |
| 16 | + |
| 17 | +/// Indexer module |
| 18 | +#[module( |
| 19 | + message_type(Message), |
| 20 | + name = "indexer", |
| 21 | + description = "Core indexer module for indexer process" |
| 22 | +)] |
| 23 | +pub struct Indexer; |
| 24 | + |
| 25 | +impl Indexer { |
| 26 | + /// Async initialisation |
| 27 | + pub async fn init(&self, context: Arc<Context<Message>>, config: Arc<Config>) -> Result<()> { |
| 28 | + let cfg = IndexerConfig::try_load(&config)?; |
| 29 | + info!( |
| 30 | + "Creating sync command publisher on '{}'", |
| 31 | + cfg.sync_command_topic |
| 32 | + ); |
| 33 | + |
| 34 | + let ctx = context.clone(); |
| 35 | + |
| 36 | + // This is a placeholder to test dynamic sync |
| 37 | + context.run(async move { |
| 38 | + let example = ChainSyncCommand::FindIntersect { |
| 39 | + slot: 4492799, |
| 40 | + hash: Hash::from_str( |
| 41 | + "f8084c61b6a238acec985b59310b6ecec49c0ab8352249afd7268da5cff2a457", |
| 42 | + ) |
| 43 | + .expect("Valid hash"), |
| 44 | + }; |
| 45 | + |
| 46 | + // Initial sync message (This will be read from config for first sync and from DB on subsequent runs) |
| 47 | + ctx.message_bus |
| 48 | + .publish( |
| 49 | + &cfg.sync_command_topic, |
| 50 | + Arc::new(Message::Command(Command::ChainSync(example.clone()))), |
| 51 | + ) |
| 52 | + .await |
| 53 | + .unwrap(); |
| 54 | + |
| 55 | + // Simulate a later sync command to reset sync point to where we started |
| 56 | + |
| 57 | + ctx.message_bus |
| 58 | + .publish( |
| 59 | + &cfg.sync_command_topic, |
| 60 | + Arc::new(Message::Command(Command::ChainSync(example))), |
| 61 | + ) |
| 62 | + .await |
| 63 | + .unwrap(); |
| 64 | + }); |
| 65 | + Ok(()) |
| 66 | + } |
| 67 | +} |
0 commit comments