Skip to content
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

Create POST /admin/sync #66

Merged
merged 3 commits into from
Apr 26, 2024
Merged
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
10 changes: 10 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,16 @@ curl -X POST http://localhost:7777/admin/add-peer -H "Content-Type: application/
{"Success":{"message":"Peer added"}}
```

### `POST /admin/sync`

Starts a sync against a random node

```
curl -X POST http://localhost:7777/admin/async -H "Authorization: abc"

200
```

## `/metrics` Prometheus Metrics scrape endpoint

Returns prometheus metrics for the node
13 changes: 11 additions & 2 deletions src/api/admin.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use crate::api::routes::APIResponse;
use crate::api::AppState;
use crate::controller::ControllerCommands;
use crate::p2p::NetworkState;
use axum::body::Body;
use axum::extract::{Request, State};
use axum::http::StatusCode;
use axum::middleware::Next;
use axum::response::Response;
use axum::Json;
use serde::Serialize;

pub async fn auth_middleware(
State(state): State<AppState>,
Expand Down Expand Up @@ -77,3 +75,14 @@ pub async fn add_peer(
),
}
}

pub async fn sync(State(state): State<AppState>) -> StatusCode {
match state
.controller
.send_command(ControllerCommands::Sync)
.await
{
Ok(_) => StatusCode::OK,
Err(_) => StatusCode::INTERNAL_SERVER_ERROR,
}
}
1 change: 1 addition & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub fn with_admin_routes(state: AppState, router: Router<AppState>) -> Router<Ap
.route("/admin/add-peer", post(admin::add_peer))
// admin submit premint route is not rate limited (allows for operator to send high volume of premints)
.route("/admin/submit-premint", post(routes::submit_premint))
.route("/admin/sync", post(admin::sync))
.layer(from_fn_with_state(state, admin::auth_middleware))
.layer(
ServiceBuilder::new()
Expand Down
9 changes: 3 additions & 6 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ use std::str::FromStr;

use alloy_primitives::Address;
use async_trait::async_trait;
use chrono::Utc;
use eyre::WrapErr;
use serde::{Deserialize, Serialize};
use sqlx::{QueryBuilder, Sqlite, SqlitePool};
use sqlx::Row;
use sqlx::sqlite::SqliteConnectOptions;
use sqlx::Row;
use sqlx::{QueryBuilder, Sqlite, SqlitePool};

use crate::config::Config;
use crate::premints::zora_premint_v2::types::ZoraPremintV2;
use crate::types::{InclusionClaim, Premint, PremintName, PremintTypes};

async fn init_db(config: &Config) -> SqlitePool {
Expand Down Expand Up @@ -327,6 +325,7 @@ mod test {
use alloy_primitives::Address;
use chrono::{Duration, Utc};
use sqlx::Row;
use std::ops::Sub;

use crate::config::Config;
use crate::premints::zora_premint_v2::types::ZoraPremintV2;
Expand All @@ -337,8 +336,6 @@ mod test {
use crate::types::{InclusionClaim, Premint, PremintTypes};

#[tokio::test]
use chrono::{Duration, Utc};
use std::ops::Sub;
async fn test_insert_and_get() {
let config = Config::test_default();

Expand Down
2 changes: 1 addition & 1 deletion tests/p2p_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async fn test_max_connections() {
let num_nodes = 5;
let limit = 3;

let nodes = mintpool_build::make_nodes(2350, num_nodes, limit).await;
let nodes = mintpool_build::make_nodes(2310, num_nodes, limit).await;
mintpool_build::connect_all_to_first(nodes.clone()).await;

mintpool_build::announce_all(nodes.clone()).await;
Expand Down
Loading