Skip to content

Commit

Permalink
Start
Browse files Browse the repository at this point in the history
  • Loading branch information
erikreppel authored and ligustah committed Apr 26, 2024
1 parent 466f4d2 commit 8cb8929
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/OPERATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ INTERACTIVE: bool (false) - If true, interactive repl will run
ENABLE_RPC: bool (true) - If true, rpc will be used for rules evaluation
ADMIN_API_SECRET: Option<String> (None) - Secret key used to access admin api routes
RATE_LIMIT_RPS: u32 (2) - Rate limit requests per second for the http api
SYNC_LOOKBACK_HOURS: u64 (6) - Number of hours to look back for syncing premints from another node
```

#### Logging
Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ pub struct Config {
// If set to chain, will check the Zora Network MintpoolTrusted nodes contract for boot nodes
#[envconfig(from = "BOOT_NODES", default = "chain")]
pub boot_nodes: BootNodes,

#[envconfig(from = "SYNC_LOOKBACK_HOURS", default = "6")]
pub sync_lookback_hours: u64,
}

impl Config {
Expand Down
27 changes: 26 additions & 1 deletion src/controller.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use crate::chain::inclusion_claim_correct;
use crate::config::{ChainInclusionMode, Config};
use chrono::Utc;
use eyre::WrapErr;
use libp2p::PeerId;
use sqlx::SqlitePool;
use std::ops::Sub;
use std::time::{Duration, SystemTime};
use tokio::select;
use tokio::sync::{mpsc, oneshot};

Expand Down Expand Up @@ -73,11 +76,12 @@ pub struct Controller {
rules: RulesEngine<PremintStorage>,
trusted_peers: Vec<PeerId>,
inclusion_mode: ChainInclusionMode,
config: Config,
}

impl Controller {
pub fn new(
config: &Config,
config: Config,
swarm_command_sender: mpsc::Sender<SwarmCommand>,
swarm_event_receiver: mpsc::Receiver<P2PEvent>,
external_commands: mpsc::Receiver<ControllerCommands>,
Expand All @@ -92,6 +96,7 @@ impl Controller {
rules,
trusted_peers: config.trusted_peers(),
inclusion_mode: config.chain_inclusion_mode,
config,
}
}

Expand Down Expand Up @@ -280,6 +285,26 @@ impl Controller {
}
}
}

/// temporary solution for full state from a known other node via their http api.
/// We should migrate to syncing based on peer_id & libp2p request_response
async fn api_sync(&self, api_url: String) -> eyre::Result<()> {
let seconds = self.config.sync_lookback_hours * 60 * 60;
let from_time = SystemTime::now().sub(Duration::from_secs(seconds));

let from_time = chrono::Utc::now().sub(chrono::Duration::hours(
self.config.sync_lookback_hours as i64,
));

let url = reqwest::Url::parse_with_params(
api_url.as_str(),
&[("from", serde_json::to_string(&from_time)?)],
)?;

// reqwest::get()

Ok(())
}
}

#[derive(Clone)]
Expand Down

0 comments on commit 8cb8929

Please sign in to comment.