Refactor nomos api: (#521)

* Extracted common service into services
* Moved api implementation to nomos node crate
This commit is contained in:
Daniel Sanchez 2023-11-10 09:28:10 +01:00 committed by GitHub
parent 5c7e0f511f
commit cc6b6d1cc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 21 additions and 17 deletions

View File

@ -2,6 +2,7 @@
members = [
"nomos-core",
"nomos-libp2p",
"nomos-services/api",
"nomos-services/log",
"nomos-services/metrics",
"nomos-services/network",
@ -17,7 +18,6 @@ members = [
"nomos-cli",
"nomos-utils",
"nodes/nomos-node",
"nodes/nomos-node-api",
"nodes/mixnode",
"simulations",
"consensus-engine",

View File

@ -1,2 +0,0 @@
#[cfg(feature = "axum")]
pub mod axum;

View File

@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
async-trait = "0.1"
blake2 = "0.10"
bincode = "2.0.0-rc.2"
bytes = "1.3"
@ -20,7 +21,7 @@ tracing = "0.1"
multiaddr = "0.18"
nomos-core = { path = "../../nomos-core" }
nomos-network = { path = "../../nomos-services/network", features = ["libp2p"] }
nomos-node-api = { path = "../nomos-node-api" }
nomos-api = { path = "../../nomos-services/api" }
nomos-log = { path = "../../nomos-services/log" }
nomos-mempool = { path = "../../nomos-services/mempool", features = ["mock", "libp2p"] }
nomos-http = { path = "../../nomos-services/http", features = ["http"] }
@ -38,3 +39,10 @@ serde_yaml = "0.9"
color-eyre = "0.6.0"
serde = "1"
full-replication = { path = "../../nomos-da/full-replication" }
# openapi related dependencies
utoipa = "4.0"
utoipa-swagger-ui = { version = "4.0" }
# axum related dependencies
axum = { version = "0.6" }
hyper = { version = "0.14", features = ["full"] }
tower-http = { version = "0.4", features = ["cors", "trace"] }

View File

@ -23,7 +23,7 @@ use nomos_mempool::{network::adapters::libp2p::Libp2pAdapter, openapi::Status, M
use nomos_network::backends::libp2p::Libp2p;
use nomos_storage::backends::StorageSerde;
use crate::{
use nomos_api::{
http::{cl, consensus, da, libp2p, mempool, storage},
Backend,
};

View File

@ -4,6 +4,7 @@ use std::{
time::Duration,
};
use crate::api::AxumBackend;
use crate::DataAvailability;
use crate::{Carnot, Tx, Wire, MB16};
use clap::{Parser, ValueEnum};
@ -11,11 +12,11 @@ use color_eyre::eyre::{self, eyre, Result};
use hex::FromHex;
#[cfg(feature = "metrics")]
use metrics::{backend::map::MapMetricsBackend, types::MetricsData, MetricsService};
use nomos_api::ApiService;
use nomos_libp2p::{secp256k1::SecretKey, Multiaddr};
use nomos_log::{Logger, LoggerBackend, LoggerFormat};
use nomos_network::backends::libp2p::Libp2p;
use nomos_network::NetworkService;
use nomos_node_api::{http::backend::axum::AxumBackend, ApiService};
use overwatch_rs::services::ServiceData;
use serde::{Deserialize, Serialize};
use tracing::Level;

View File

@ -1,3 +1,4 @@
pub mod api;
mod config;
mod tx;
@ -9,7 +10,9 @@ use full_replication::{AbsoluteNumber, Attestation, Blob, FullReplication};
use metrics::{backend::map::MapMetricsBackend, types::MetricsData, MetricsService};
use nomos_consensus::network::adapters::libp2p::Libp2pAdapter as ConsensusLibp2pAdapter;
use api::AxumBackend;
use bytes::Bytes;
use nomos_api::ApiService;
use nomos_consensus::CarnotConsensus;
use nomos_core::{
da::{blob, certificate},
@ -27,8 +30,6 @@ use nomos_mempool::{
Transaction as TxDiscriminant,
};
use nomos_network::backends::libp2p::Libp2p;
use nomos_node_api::http::backend::axum::AxumBackend;
use nomos_node_api::ApiService;
use nomos_storage::{
backends::{sled::SledBackend, StorageSerde},
StorageService,

View File

@ -1,5 +1,5 @@
[package]
name = "nomos-node-api"
name = "nomos-api"
version = "0.1.0"
edition = "2021"

View File

@ -1,7 +1,4 @@
pub type DynError = Box<dyn std::error::Error + Send + Sync + 'static>;
pub mod backend;
pub mod cl;
pub mod consensus;
pub mod da;

View File

@ -6,7 +6,7 @@ use std::{
use axum::{routing, Router, Server};
use hyper::Error;
use nomos_node_api::{ApiService, ApiServiceSettings, Backend};
use nomos_api::{ApiService, ApiServiceSettings, Backend};
use overwatch_derive::Services;
use overwatch_rs::{
overwatch::{handle::OverwatchHandle, OverwatchRunner},

View File

@ -9,7 +9,7 @@ nomos-node = { path = "../nodes/nomos-node", default-features = false }
nomos-consensus = { path = "../nomos-services/consensus" }
nomos-network = { path = "../nomos-services/network", features = ["libp2p"]}
nomos-log = { path = "../nomos-services/log" }
nomos-node-api = { path = "../nodes/nomos-node-api", features = ["axum"] }
nomos-api = { path = "../nomos-services/api" }
overwatch-rs = { git = "https://github.com/logos-co/Overwatch", rev = "2f70806" }
nomos-core = { path = "../nomos-core" }
consensus-engine = { path = "../consensus-engine", features = ["serde"] }

View File

@ -17,8 +17,7 @@ use nomos_log::{LoggerBackend, LoggerFormat};
use nomos_mempool::MempoolMetrics;
use nomos_network::backends::libp2p::Libp2pConfig;
use nomos_network::NetworkConfig;
use nomos_node::{Config, Tx};
use nomos_node_api::http::backend::axum::AxumBackendSettings;
use nomos_node::{api::AxumBackendSettings, Config, Tx};
// crates
use fraction::Fraction;
use once_cell::sync::Lazy;
@ -334,7 +333,7 @@ fn create_node_config(
blob_selector_settings: (),
},
log: Default::default(),
http: nomos_node_api::ApiServiceSettings {
http: nomos_api::ApiServiceSettings {
backend_settings: AxumBackendSettings {
address: format!("127.0.0.1:{}", get_available_port())
.parse()