Skip to content

Commit

Permalink
Merge pull request #1401 from mintlayer/feature/mempool-feerate-points
Browse files Browse the repository at this point in the history
Add mempool RPC for fetching feerate points
  • Loading branch information
OBorce authored Jan 5, 2024
2 parents 4fe66bb + 767437a commit 768351b
Show file tree
Hide file tree
Showing 46 changed files with 1,101 additions and 168 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions api-server/api-server-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ crypto = { path = '../../crypto/' }
logging = { path = '../../logging'}
pos_accounting = { path = '../../pos_accounting' }
serialization = { path = "../../serialization" }
mempool = { path = "../../mempool" }

async-trait.workspace = true
bb8-postgres = "0.8"
Expand Down
1 change: 1 addition & 0 deletions api-server/scanner-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pos_accounting = { path = "../../pos_accounting" }
utils = { path = "../../utils" }
tx-verifier = { path = "../../chainstate/tx-verifier" }
constraints-value-accumulator = { path = "../../chainstate/constraints-value-accumulator" }
mempool = { path = "../../mempool" }

async-trait.workspace = true
thiserror.workspace = true
Expand Down
7 changes: 7 additions & 0 deletions api-server/scanner-lib/src/sync/remote_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use common::{
chain::{Block, GenBlock},
primitives::{BlockHeight, Id},
};
use mempool::FeeRate;
use node_comm::{
node_traits::NodeInterface,
rpc_client::{NodeRpcClient, NodeRpcError},
Expand All @@ -39,6 +40,8 @@ pub trait RemoteNode {
from: BlockHeight,
max_count: usize,
) -> Result<Vec<Block>, Self::Error>;

async fn mempool_feerate_points(&self) -> Result<Vec<(usize, FeeRate)>, Self::Error>;
}

#[async_trait::async_trait]
Expand All @@ -63,4 +66,8 @@ impl RemoteNode for NodeRpcClient {
) -> Result<Vec<Block>, Self::Error> {
self.get_mainchain_blocks(from, max_count).await
}

async fn mempool_feerate_points(&self) -> Result<Vec<(usize, FeeRate)>, Self::Error> {
self.mempool_get_fee_rate_points().await
}
}
8 changes: 8 additions & 0 deletions api-server/scanner-lib/src/sync/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use crate::blockchain_state::BlockchainState;

use mempool::FeeRate;
use serialization::Encode;

use super::*;
Expand Down Expand Up @@ -169,6 +170,13 @@ impl RemoteNode for MockRemoteNode {
.get_mainchain_blocks(from, max_count)
.unwrap())
}

async fn mempool_feerate_points(&self) -> Result<Vec<(usize, FeeRate)>, Self::Error> {
Ok(vec![(
1,
FeeRate::from_amount_per_kb(Amount::from_atoms(1)),
)])
}
}

fn create_chain(
Expand Down
1 change: 1 addition & 0 deletions api-server/stack-test-suite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ serialization = { path = "../../serialization" }
utils = { path = "../../utils" }
pos_accounting = {path = '../../pos_accounting'}
node-comm = { path = "../../wallet/wallet-node-client" }
mempool = { path = "../../mempool" }

async-trait.workspace = true
axum.workspace = true
Expand Down
31 changes: 22 additions & 9 deletions api-server/stack-test-suite/tests/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,29 @@
mod v1;

use api_server_common::storage::impls::in_memory::transactional::TransactionalApiServerInMemoryStorage;
use api_web_server::{api::web_server, ApiServerWebServerState, TxSubmitClient};
use common::chain::{config::create_unit_test_config, SignedTransaction};
use std::{net::TcpListener, sync::Arc};
use api_web_server::{api::web_server, ApiServerWebServerState, CachedValues, TxSubmitClient};
use common::{
chain::{config::create_unit_test_config, SignedTransaction},
primitives::time::get_time,
};
use mempool::FeeRate;
use node_comm::rpc_client::NodeRpcError;
use std::{
net::TcpListener,
sync::{Arc, RwLock},
};

struct DummyRPC {}

#[async_trait::async_trait]
impl TxSubmitClient for DummyRPC {
async fn submit_tx(
&self,
_: SignedTransaction,
) -> Result<(), node_comm::rpc_client::NodeRpcError> {
async fn submit_tx(&self, _: SignedTransaction) -> Result<(), NodeRpcError> {
Ok(())
}

async fn get_feerate_points(&self) -> Result<Vec<(usize, FeeRate)>, NodeRpcError> {
Ok(vec![])
}
}

pub async fn spawn_webserver(url: &str) -> (tokio::task::JoinHandle<()>, reqwest::Response) {
Expand All @@ -44,11 +53,15 @@ pub async fn spawn_webserver(url: &str) -> (tokio::task::JoinHandle<()>, reqwest
ApiServerWebServerState {
db: Arc::new(storage),
chain_config: Arc::clone(&chain_config),
rpc: Some(Arc::new(DummyRPC {})),
rpc: Arc::new(DummyRPC {}),
cached_values: Arc::new(CachedValues {
feerate_points: RwLock::new((get_time(), vec![])),
}),
time_getter: Default::default(),
}
};

web_server(listener, web_server_state).await.unwrap();
web_server(listener, web_server_state, true).await.unwrap();
});

// Given that the listener port is open, this will block until a
Expand Down
21 changes: 17 additions & 4 deletions api-server/stack-test-suite/tests/v1/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::sync::RwLock;

use api_web_server::CachedValues;
use common::primitives::time::get_time;

use crate::DummyRPC;

use super::*;
Expand Down Expand Up @@ -243,11 +248,15 @@ async fn multiple_outputs_to_single_address(#[case] seed: Seed) {
ApiServerWebServerState {
db: Arc::new(local_node.storage().clone_storage().await),
chain_config: Arc::clone(&chain_config),
rpc: None::<std::sync::Arc<DummyRPC>>,
rpc: Arc::new(DummyRPC {}),
cached_values: Arc::new(CachedValues {
feerate_points: RwLock::new((get_time(), vec![])),
}),
time_getter: Default::default(),
}
};

web_server(listener, web_server_state).await
web_server(listener, web_server_state, true).await
});

for (address, expected_balance) in rx.await.unwrap() {
Expand Down Expand Up @@ -460,11 +469,15 @@ async fn ok(#[case] seed: Seed) {
ApiServerWebServerState {
db: Arc::new(local_node.storage().clone_storage().await),
chain_config: Arc::clone(&chain_config),
rpc: None::<std::sync::Arc<DummyRPC>>,
rpc: Arc::new(DummyRPC {}),
cached_values: Arc::new(CachedValues {
feerate_points: RwLock::new((get_time(), vec![])),
}),
time_getter: Default::default(),
}
};

web_server(listener, web_server_state).await
web_server(listener, web_server_state, true).await
});

for (address, expected_values) in rx.await.unwrap() {
Expand Down
21 changes: 15 additions & 6 deletions api-server/stack-test-suite/tests/v1/address_available_utxos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::BTreeMap;
use std::{collections::BTreeMap, sync::RwLock};

use common::chain::UtxoOutPoint;
use api_web_server::CachedValues;
use common::{chain::UtxoOutPoint, primitives::time::get_time};

use crate::DummyRPC;

Expand Down Expand Up @@ -274,11 +275,15 @@ async fn multiple_utxos_to_single_address(#[case] seed: Seed) {
ApiServerWebServerState {
db: Arc::new(local_node.storage().clone_storage().await),
chain_config: Arc::clone(&chain_config),
rpc: None::<std::sync::Arc<DummyRPC>>,
rpc: Arc::new(DummyRPC {}),
cached_values: Arc::new(CachedValues {
feerate_points: RwLock::new((get_time(), vec![])),
}),
time_getter: Default::default(),
}
};

web_server(listener, web_server_state).await
web_server(listener, web_server_state, true).await
});

for (address, expected) in rx.await.unwrap() {
Expand Down Expand Up @@ -513,11 +518,15 @@ async fn ok(#[case] seed: Seed) {
ApiServerWebServerState {
db: Arc::new(local_node.storage().clone_storage().await),
chain_config: Arc::clone(&chain_config),
rpc: None::<std::sync::Arc<DummyRPC>>,
rpc: Arc::new(DummyRPC {}),
cached_values: Arc::new(CachedValues {
feerate_points: RwLock::new((get_time(), vec![])),
}),
time_getter: Default::default(),
}
};

web_server(listener, web_server_state).await
web_server(listener, web_server_state, true).await
});

for (address, expected_values) in rx.await.unwrap() {
Expand Down
16 changes: 13 additions & 3 deletions api-server/stack-test-suite/tests/v1/address_delegations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use common::chain::{AccountNonce, UtxoOutPoint};
use std::sync::RwLock;

use api_web_server::CachedValues;
use common::{
chain::{AccountNonce, UtxoOutPoint},
primitives::time::get_time,
};

use crate::DummyRPC;

Expand Down Expand Up @@ -200,11 +206,15 @@ async fn ok(#[case] seed: Seed) {
ApiServerWebServerState {
db: Arc::new(local_node.storage().clone_storage().await),
chain_config: Arc::clone(&chain_config),
rpc: None::<std::sync::Arc<DummyRPC>>,
rpc: Arc::new(DummyRPC {}),
cached_values: Arc::new(CachedValues {
feerate_points: RwLock::new((get_time(), vec![])),
}),
time_getter: Default::default(),
}
};

web_server(listener, web_server_state).await
web_server(listener, web_server_state, true).await
});

for (address, expected) in rx.await.unwrap() {
Expand Down
17 changes: 13 additions & 4 deletions api-server/stack-test-suite/tests/v1/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use api_web_server::api::json_helpers::{block_header_to_json, tx_to_json, txoutput_to_json};
use common::{
chain::{stakelock::StakePoolData, CoinUnit, GenBlock, PoolId},
primitives::{per_thousand::PerThousand, H256},
primitives::{per_thousand::PerThousand, time::get_time, H256},
};
use crypto::vrf::{VRFKeyKind, VRFPrivateKey};
use std::sync::RwLock;

use api_web_server::{
api::json_helpers::{block_header_to_json, tx_to_json, txoutput_to_json},
CachedValues,
};

use crate::DummyRPC;

Expand Down Expand Up @@ -211,11 +216,15 @@ async fn ok(#[case] seed: Seed) {
ApiServerWebServerState {
db: Arc::new(local_node.storage().clone_storage().await),
chain_config: tf.chain_config().clone(),
rpc: None::<std::sync::Arc<DummyRPC>>,
rpc: Arc::new(DummyRPC {}),
cached_values: Arc::new(CachedValues {
feerate_points: RwLock::new((get_time(), vec![])),
}),
time_getter: Default::default(),
}
};

web_server(listener, web_server_state).await
web_server(listener, web_server_state, true).await
});

let (block_id, new_expected_block, old_block_id, old_expected_block) = rx.await.unwrap();
Expand Down
13 changes: 9 additions & 4 deletions api-server/stack-test-suite/tests/v1/block_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use api_web_server::api::json_helpers::block_header_to_json;
use api_web_server::{api::json_helpers::block_header_to_json, CachedValues};
use common::{
chain::{stakelock::StakePoolData, CoinUnit, PoolId},
primitives::{per_thousand::PerThousand, H256},
primitives::{per_thousand::PerThousand, time::get_time, H256},
};
use crypto::vrf::{VRFKeyKind, VRFPrivateKey};
use std::sync::RwLock;

use crate::DummyRPC;

Expand Down Expand Up @@ -131,11 +132,15 @@ async fn ok(#[case] seed: Seed) {
ApiServerWebServerState {
db: Arc::new(local_node.storage().clone_storage().await),
chain_config: Arc::clone(&chain_config),
rpc: None::<std::sync::Arc<DummyRPC>>,
rpc: Arc::new(DummyRPC {}),
cached_values: Arc::new(CachedValues {
feerate_points: RwLock::new((get_time(), vec![])),
}),
time_getter: Default::default(),
}
};

web_server(listener, web_server_state).await
web_server(listener, web_server_state, true).await
});

let (block_id, expected_header) = rx.await.unwrap();
Expand Down
Loading

0 comments on commit 768351b

Please sign in to comment.