Skip to content

Commit

Permalink
RPC-468 changes to priority fee service for better modularity and exp…
Browse files Browse the repository at this point in the history
…osing a detailed result API for better visibility (#15)

* RPC-468 refactoring code to make it simpler to make changes to individual calculations

* RPC-468 exposing more information about each calculation

* RPC-468 adding response for detailed request

* RPC-468 updating readme

* RPC-468 fixing issue with tests
  • Loading branch information
dmitriy-helius authored Nov 18, 2024
1 parent 40fd41b commit 6f3804d
Show file tree
Hide file tree
Showing 10 changed files with 2,255 additions and 798 deletions.
139 changes: 137 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ futures = "0.3.24"
figment = { version = "0.10.6", features = ["env", "test"] }
tower = { version = "0.4.13", features = ["full"] }
thiserror = "1.0.63"
anyhow = "1.0.86"
anyhow = "1.0.86"
statrs = "0.17.1"
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,73 @@ cargo run
"id": "1"
}
```

**Request the recommended priority fee details**
The purpose of this API is to understand what data is taken into consideration given the query.
The response shows the statistical distribution of data per account as well as how much data is available in each account.
The request is identical to the one used in getPriorityFeeEstimate request. This is to ensure that same request could be
reused during analysis and during dev / operational stages

```json
{
"id": "version1",
"jsonrpc": "2.0",
"method": "getPriorityFeeEstimateDetails",
"params": [
{
"accountKeys": [
"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"
],
"options": {"recommended": true}
}
]
}
```

**Response**

```json
{
"jsonrpc": "2.0",
"result": {
"priorityFeeEstimateDetails": [
[
"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",
{
"estimates": {
"min": 0.0,
"low": 0.0,
"medium": 0.0,
"high": 0.0,
"veryHigh": 0.0,
"unsafeMax": 25113388.0
},
"mean": 717525.0, // mean fee payed for each transaction for account evaluated over last 150 (or less if requested less) slots
"stdev": 4244937.0, // standard deviation of fee payed for each transaction for account evaluated over last 150 (or less if requested less) slots ,
"skew": null, // skew of fee payed for each transaction for account evaluated over last 150 (or less if requested less) slots. Null if data is randomly distributed and cannot calculate
"count": 35 // Number of transactions for account that were evaluated over last 150 (or less if requested less) slots
}
],
[
"Global",
{
"estimates": {
"min": 0.0,
"low": 0.0,
"medium": 20003.0,
"high": 2276532.0,
"veryHigh": 32352142.0,
"unsafeMax": 2000000000.0
},
"mean": 8118956.0, // mean fee payed for each transaction for all accounts evaluated over last 150 (or less if requested less) slots
"stdev": 53346050.0, // standard deviation of fee payed for each transaction for all account evaluated over last 150 (or less if requested less) slots ,
"skew": null, // skew of fee payed for each transaction for all accounts evaluated over last 150 (or less if requested less) slots. Null if data is randomly distributed and cannot calculate
"count": 14877 // Number of transactions for all accounts that were evaluated over last 150 (or less if requested less) slots
}
]
],
"priorityFeeEstimate": 20003.0
},
"id": "version1"
}
```
19 changes: 19 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
use jsonrpsee::types::{error::INVALID_PARAMS_CODE, ErrorObjectOwned};

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum TransactionValidationError {
TransactionFailed,
TransactionMissing,
MessageMissing,
InvalidAccount,
}

impl Into<&str> for TransactionValidationError {
fn into(self) -> &'static str {
match self {
TransactionValidationError::TransactionFailed => "txn_failed",
TransactionValidationError::TransactionMissing => "txn_missing",
TransactionValidationError::MessageMissing => "message_missing",
TransactionValidationError::InvalidAccount => "invalid_pubkey",
}
}
}

pub fn invalid_request(reason: &str) -> ErrorObjectOwned {
ErrorObjectOwned::owned(
INVALID_PARAMS_CODE,
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub mod errors;
pub mod grpc_consumer;
pub mod grpc_geyser;
pub mod model;
pub mod priority_fee;
pub mod priority_fee_calculation;
pub mod rpc_server;
pub mod slot_cache;
pub mod solana;
15 changes: 3 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
use std::{env, net::UdpSocket, sync::Arc};

use crate::rpc_server::AtlasPriorityFeeEstimatorRpcServer;
use cadence::{BufferedUdpMetricSink, QueuingMetricSink, StatsdClient};
use cadence_macros::set_global_default;
use figment::{providers::Env, Figment};
use grpc_geyser::GrpcGeyserImpl;
use jsonrpsee::server::ServerBuilder;
use jsonrpsee::server::middleware::http::ProxyGetRequestLayer;
use priority_fee::PriorityFeeTracker;
use rpc_server::AtlasPriorityFeeEstimator;
use serde::Deserialize;
use tracing::{error, info};

mod errors;
mod grpc_consumer;
mod grpc_geyser;
mod priority_fee;
mod rpc_server;
mod slot_cache;
mod solana;
use atlas_priority_fee_estimator::grpc_geyser::GrpcGeyserImpl;
use atlas_priority_fee_estimator::priority_fee::PriorityFeeTracker;
use atlas_priority_fee_estimator::rpc_server::{AtlasPriorityFeeEstimator, AtlasPriorityFeeEstimatorRpcServer};

#[derive(Debug, Deserialize, Clone)]
struct EstimatorEnv {
Expand Down
Loading

0 comments on commit 6f3804d

Please sign in to comment.