Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ I currently run the public instance at https://observer.fedimint.org using the f
FO_DATABASE = "postgresql:///fmo?user=fmo";
# Set to your admin password, used to add federations to be observed via curl
FO_ADMIN_AUTH = ;
# Seconds to wait between materialized view refreshes
FO_VIEW_REFRESH_INTERVAL_SECS = "60";
ALLOW_CONFIG_CORS = "true";
};
serviceConfig = {
Expand Down
74 changes: 22 additions & 52 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
wasm-pack
trunk
nodejs
nodePackages.tailwindcss
tailwindcss
];
};
targets = (pkgs.lib.getAttrs
Expand Down Expand Up @@ -130,7 +130,7 @@
wasm-pack
nodejs
binaryen
nodePackages.tailwindcss
tailwindcss
];

FMO_API_SERVER = api;
Expand Down
15 changes: 13 additions & 2 deletions fmo_server/src/federation/observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,21 @@ pub struct FederationObserver {
mempool_url: String,
task_group: TaskGroup,
consensus_meta_cache: ConsensusMetaCache,
view_refresh_interval: Duration,
}

impl FederationObserver {
pub async fn new(
database: &str,
admin_auth: &str,
mempool_url: &str,
view_refresh_interval_secs: u64,
) -> anyhow::Result<FederationObserver> {
ensure!(
view_refresh_interval_secs > 0,
"View refresh interval must be greater than zero"
);

let connection_pool = {
let pool_config = deadpool_postgres::Config {
url: Some(database.to_owned()),
Expand All @@ -74,6 +81,7 @@ impl FederationObserver {
mempool_url: mempool_url.to_owned(),
task_group: Default::default(),
consensus_meta_cache: Default::default(),
view_refresh_interval: Duration::from_secs(view_refresh_interval_secs),
};

slf.setup_schema().await?;
Expand Down Expand Up @@ -1309,8 +1317,11 @@ impl FederationObserver {
warn!("Error while refreshing views: {e:?}");
}
let elapsed = start.elapsed().unwrap_or_default().as_secs_f64();
info!("Views refresh completed in {elapsed:.2}s. Waiting for next refresh window");
tokio::time::sleep(Duration::from_secs(60)).await;
let wait_secs = self.view_refresh_interval.as_secs();
info!(
"Views refresh completed in {elapsed:.2}s. Waiting {wait_secs}s for next refresh window"
);
tokio::time::sleep(self.view_refresh_interval).await;
}
}

Expand Down
9 changes: 9 additions & 0 deletions fmo_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ struct Args {
default_value = "https://mempool.space/api"
)]
mempool_url: String,

#[arg(
long,
env = "FO_VIEW_REFRESH_INTERVAL_SECS",
default_value_t = 60,
value_parser = clap::value_parser!(u64).range(1..)
)]
view_refresh_interval_secs: u64,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -83,6 +91,7 @@ async fn main() -> anyhow::Result<()> {
&args.database,
&args.admin_auth,
&args.mempool_url,
args.view_refresh_interval_secs,
)
.await?,
});
Expand Down
1 change: 1 addition & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ FO_BIND="127.0.0.1:3000"
FO_DATABASE="postgres://${PGUSER}@/${PGDATABASE}?host=${PGHOST}&port=${PGPORT}"
FO_ADMIN_AUTH="foobar"
FO_MEMPOOL_URL="https://mempool.space/api"
FO_VIEW_REFRESH_INTERVAL_SECS="60"
Loading