server: reorg

This commit is contained in:
nym21
2026-04-02 13:19:56 +02:00
parent 099699872e
commit d92cf43c57
13 changed files with 56 additions and 52 deletions

View File

@@ -153,6 +153,6 @@ impl<T> Loss<T> {
.into_iter()
.rev()
.enumerate()
.map(move |(n, threshold)| (threshold, &ranges[len - 1 - n..]))
.map(move |(n, threshold)| (threshold, &ranges[len - 2 - n..]))
}
}

View File

@@ -208,6 +208,6 @@ impl<T> Profit<T> {
.into_iter()
.rev()
.enumerate()
.map(move |(n, threshold)| (threshold, &ranges[..n + 1]))
.map(move |(n, threshold)| (threshold, &ranges[..n + 2]))
}
}

View File

@@ -273,7 +273,7 @@ impl ProfitabilityMetrics {
ProfitabilityBucket::forced_import(db, name, version, indexes, cached_starts)
})?;
let aggregate_version = version + Version::ONE;
let aggregate_version = version + Version::TWO;
let profit = Profit::try_new(|name| {
ProfitabilityBucket::forced_import(db, name, aggregate_version, indexes, cached_starts)

View File

@@ -10,9 +10,7 @@ use brk_types::{
ValidateAddrParam,
};
use crate::{CacheStrategy, extended::TransformResponseExtended};
use super::AppState;
use crate::{AppState, CacheStrategy, extended::TransformResponseExtended};
pub trait AddrRoutes {
fn add_addr_routes(self) -> Self;

View File

@@ -9,9 +9,7 @@ use brk_types::{
BlockTimestamp, HeightParam, TimestampParam, Transaction, TxIndex, Txid,
};
use crate::{CacheStrategy, extended::TransformResponseExtended};
use super::AppState;
use crate::{AppState, CacheStrategy, extended::TransformResponseExtended};
pub trait BlockRoutes {
fn add_block_routes(self) -> Self;

View File

@@ -5,9 +5,7 @@ use axum::{
};
use brk_types::{MempoolBlock, RecommendedFees};
use crate::extended::TransformResponseExtended;
use super::AppState;
use crate::{AppState, extended::TransformResponseExtended};
pub trait FeesRoutes {
fn add_fees_routes(self) -> Self;

View File

@@ -3,13 +3,9 @@ use axum::{
extract::{Query, State},
http::{HeaderMap, Uri},
};
use brk_types::{
DifficultyAdjustment, HistoricalPrice, OptionalTimestampParam, Prices, Timestamp,
};
use brk_types::{DifficultyAdjustment, HistoricalPrice, OptionalTimestampParam, Prices, Timestamp};
use crate::{CacheStrategy, extended::TransformResponseExtended};
use super::AppState;
use crate::{AppState, CacheStrategy, extended::TransformResponseExtended};
pub trait GeneralRoutes {
fn add_general_routes(self) -> Self;

View File

@@ -5,9 +5,7 @@ use axum::{
};
use brk_types::{Dollars, MempoolInfo, MempoolRecentTx, Txid};
use crate::extended::TransformResponseExtended;
use super::AppState;
use crate::{AppState, extended::TransformResponseExtended};
pub trait MempoolRoutes {
fn add_mempool_routes(self) -> Self;

View File

@@ -7,14 +7,11 @@ use axum::{
};
use brk_types::{
BlockCountParam, BlockFeesEntry, BlockInfoV1, BlockRewardsEntry, BlockSizesWeights,
DifficultyAdjustmentEntry, HashrateSummary, PoolDetail,
PoolHashrateEntry, PoolInfo, PoolSlugAndHeightParam, PoolSlugParam, PoolsSummary,
RewardStats, TimePeriodParam,
DifficultyAdjustmentEntry, HashrateSummary, PoolDetail, PoolHashrateEntry, PoolInfo,
PoolSlugAndHeightParam, PoolSlugParam, PoolsSummary, RewardStats, TimePeriodParam,
};
use crate::{CacheStrategy, Error, extended::TransformResponseExtended};
use super::AppState;
use crate::{AppState, CacheStrategy, Error, extended::TransformResponseExtended};
pub trait MiningRoutes {
fn add_mining_routes(self) -> Self;

View File

@@ -0,0 +1,35 @@
use aide::axum::ApiRouter;
use crate::AppState;
mod addrs;
mod blocks;
mod fees;
mod general;
mod mempool;
mod mining;
mod transactions;
use addrs::AddrRoutes;
use blocks::BlockRoutes;
use fees::FeesRoutes;
use general::GeneralRoutes;
use mempool::MempoolRoutes;
use mining::MiningRoutes;
use transactions::TxRoutes;
pub trait MempoolSpaceRoutes {
fn add_mempool_space_routes(self) -> Self;
}
impl MempoolSpaceRoutes for ApiRouter<AppState> {
fn add_mempool_space_routes(self) -> Self {
self.add_general_routes()
.add_addr_routes()
.add_block_routes()
.add_mining_routes()
.add_fees_routes()
.add_mempool_routes()
.add_tx_routes()
}
}

View File

@@ -7,13 +7,10 @@ use axum::{
http::{HeaderMap, Uri},
};
use brk_types::{
CpfpInfo, MerkleProof, Transaction, TxOutspend, TxStatus, Txid, TxidParam, TxidVout,
TxidsParam,
CpfpInfo, MerkleProof, Transaction, TxOutspend, TxStatus, Txid, TxidParam, TxidVout, TxidsParam,
};
use crate::{CacheStrategy, extended::TransformResponseExtended};
use super::AppState;
use crate::{AppState, CacheStrategy, extended::TransformResponseExtended};
pub trait TxRoutes {
fn add_tx_routes(self) -> Self;
@@ -26,7 +23,7 @@ impl TxRoutes for ApiRouter<AppState> {
"/api/v1/cpfp/{txid}",
get_with(
async |uri: Uri, headers: HeaderMap, Path(txid): Path<TxidParam>, State(state): State<AppState>| {
state.cached_json(&headers, CacheStrategy::MempoolHash(0), &uri, move |q| q.cpfp(txid)).await
state.cached_json(&headers, state.mempool_cache(), &uri, move |q| q.cpfp(txid)).await
},
|op| op
.id("get_cpfp")
@@ -223,7 +220,7 @@ impl TxRoutes for ApiRouter<AppState> {
get_with(
async |uri: Uri, headers: HeaderMap, State(state): State<AppState>| {
let params = TxidsParam::from_query(uri.query().unwrap_or(""));
state.cached_json(&headers, CacheStrategy::MempoolHash(0), &uri, move |q| q.transaction_times(&params.txids)).await
state.cached_json(&headers, state.mempool_cache(), &uri, move |q| q.transaction_times(&params.txids)).await
},
|op| op
.id("get_transaction_times")

View File

@@ -14,26 +14,19 @@ use axum::{
use crate::{
Error,
api::{
addrs::AddrRoutes, blocks::BlockRoutes, fees::FeesRoutes, general::GeneralRoutes,
mempool::MempoolRoutes, metrics_legacy::ApiMetricsLegacyRoutes, mining::MiningRoutes,
series::ApiSeriesRoutes, server::ServerRoutes, transactions::TxRoutes,
mempool_space::MempoolSpaceRoutes, metrics::ApiMetricsLegacyRoutes,
series::ApiSeriesRoutes, server::ServerRoutes,
},
extended::{ResponseExtended, TransformResponseExtended},
};
use super::AppState;
mod addrs;
mod blocks;
mod fees;
mod general;
mod mempool;
mod metrics_legacy;
mod mining;
mod mempool_space;
mod metrics;
mod openapi;
mod series;
mod server;
mod transactions;
pub use openapi::*;
@@ -46,13 +39,7 @@ impl ApiRoutes for ApiRouter<AppState> {
self.add_server_routes()
.add_series_routes()
.add_metrics_legacy_routes()
.add_general_routes()
.add_addr_routes()
.add_block_routes()
.add_mining_routes()
.add_fees_routes()
.add_mempool_routes()
.add_tx_routes()
.add_mempool_space_routes()
.route("/api/server", get(Redirect::temporary("/api#tag/server")))
.api_route(
"/openapi.json",