Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
305fc86
add rpc server
hinto-janai Mar 28, 2025
0f35406
add init fn
hinto-janai Mar 29, 2025
9ed9b61
add layers
hinto-janai Apr 2, 2025
a65e041
Merge branch 'main' into rpc-server
hinto-janai Apr 15, 2025
386f303
docs
hinto-janai Apr 15, 2025
1c3cc7e
comments
hinto-janai Apr 15, 2025
f2cd202
move
hinto-janai Apr 15, 2025
c5785a0
warn
hinto-janai Apr 15, 2025
7b75701
split config
hinto-janai Apr 15, 2025
f4b407f
split
hinto-janai Apr 15, 2025
f6b2e42
fix toml
hinto-janai Apr 15, 2025
1b57675
impl p2p port
hinto-janai Apr 15, 2025
38c692f
fix tests
hinto-janai Apr 15, 2025
c03bb64
docs
hinto-janai Apr 16, 2025
bd07f14
doc
hinto-janai Apr 16, 2025
c71f642
remove (de)compression
hinto-janai Apr 30, 2025
02598ff
init rpc servers with handlers
hinto-janai May 1, 2025
d408af1
add `rpc.md`
hinto-janai May 1, 2025
3b7d0f5
Merge branch 'main' into rpc-server
hinto-janai May 7, 2025
61e9c7f
Merge branch 'main' into rpc-server
hinto-janai May 12, 2025
cf1fe0e
Merge branch 'main' into rpc-user
hinto-janai May 12, 2025
c5e2c3d
typo
hinto-janai May 12, 2025
d271bc6
sort
hinto-janai May 12, 2025
7dbd117
revert cargo.lock diff
hinto-janai May 12, 2025
11f8d64
🟣
hinto-janai May 14, 2025
be9e478
Merge branch 'main' into rpc-1
hinto-janai May 15, 2025
018386e
not_available()
hinto-janai May 15, 2025
950a9af
`advertise`
hinto-janai May 27, 2025
1675184
Update binaries/cuprated/src/config/rpc.rs
hinto-janai May 27, 2025
ed733d5
update tracing
hinto-janai May 27, 2025
94d1dff
Merge branch 'rpc-server' of github.com:hinto-janai/cuprate into rpc-…
hinto-janai May 27, 2025
850a19e
`tracing::field::display`
hinto-janai May 27, 2025
785c338
fix
hinto-janai May 27, 2025
912eaac
typo
hinto-janai May 27, 2025
a4a25c0
docs
hinto-janai May 27, 2025
eef8abc
Merge branch 'main' into rpc-server
hinto-janai May 27, 2025
3999a56
clippy
hinto-janai May 27, 2025
d1bedcf
remove comment_out
hinto-janai May 28, 2025
5c9338f
add test for `cuprate_helper::net::ip_is_local`
hinto-janai May 28, 2025
a143dec
Merge branch 'rpc-server' into rpc-1
hinto-janai May 28, 2025
fdf478a
Merge branch 'main' into rpc-1
hinto-janai May 28, 2025
7e3728b
Merge branch 'main' into rpc-1
hinto-janai May 30, 2025
923a9e4
fix args
hinto-janai May 30, 2025
4dcde70
`/get_outs`, `/get_height`
hinto-janai May 30, 2025
2ff6629
enable methods
hinto-janai May 30, 2025
188fbf4
Merge branch 'rpc-user' into rpc-1
hinto-janai May 30, 2025
60374db
apply
hinto-janai May 30, 2025
d8e0b8a
block fn
hinto-janai May 30, 2025
8883d8c
fix
hinto-janai May 30, 2025
ed9d6ae
clippy
hinto-janai May 30, 2025
dbf1973
Merge branch 'main' into rpc-1
hinto-janai May 30, 2025
2fb1246
book
hinto-janai May 31, 2025
fc19347
`JsonFormatter` impl
hinto-janai May 31, 2025
8540867
add to config
hinto-janai May 31, 2025
d86a9e7
clean
hinto-janai May 31, 2025
d1ff660
feature
hinto-janai May 31, 2025
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
1 change: 1 addition & 0 deletions Cargo.lock

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

32 changes: 32 additions & 0 deletions binaries/cuprated/src/config/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::{

use serde::{Deserialize, Serialize};

use cuprate_rpc_interface::JsonFormatter;

use crate::config::macros::config_struct;

config_struct! {
Expand Down Expand Up @@ -39,6 +41,34 @@ config_struct! {
/// Examples | true, false
pub enable: bool,

/// Adjust the JSON output formatting.
///
/// The default formatting is:
/// - "Compact" for restricted RPC
/// - "Pretty" for unrestricted RPC
///
/// "Compact" example:
/// ```
/// {"jsonrpc":"2.0","id":"0","result":{"status":"OK","untrusted":false,"count":3423276}}
/// ```
///
/// "Pretty" example:
/// ```
/// {
/// "jsonrpc": "2.0",
/// "id": "0",
/// "result": {
/// "status": "OK",
/// "untrusted": false,
/// "count": 3423276
/// }
/// }
/// ```
///
/// Type | Number
/// Valid values | "Compact", "Pretty"
pub json_formatter: JsonFormatter,

#[comment_out = true]
/// If a request is above this byte limit, it will be rejected.
///
Expand Down Expand Up @@ -91,6 +121,7 @@ impl Default for UnrestrictedRpcConfig {
address: SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 18081)),
enable: true,
request_byte_limit: 0,
json_formatter: JsonFormatter::Pretty,
}
}
}
Expand All @@ -104,6 +135,7 @@ impl Default for RestrictedRpcConfig {
// 1 megabyte.
// <https://github.com/monero-project/monero/blob/3b01c490953fe92f3c6628fa31d280a4f0490d28/src/cryptonote_config.h#L134>
request_byte_limit: 1024 * 1024,
json_formatter: JsonFormatter::Compact,
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions binaries/cuprated/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn main() {
let tx_handler = IncomingTxHandler::init(
network_interfaces.clearnet_network_interface.clone(),
txpool_write_handle.clone(),
txpool_read_handle,
txpool_read_handle.clone(),
context_svc.clone(),
blockchain_read_handle.clone(),
);
Expand All @@ -149,15 +149,20 @@ fn main() {
blockchain::init_blockchain_manager(
network_interfaces.clearnet_network_interface,
blockchain_write_handle,
blockchain_read_handle,
txpool_write_handle,
blockchain_read_handle.clone(),
txpool_write_handle.clone(),
context_svc.clone(),
config.block_downloader_config(),
)
.await;

// Initialize the RPC server(s).
rpc::init_rpc_servers(config.rpc);
rpc::init_rpc_servers(
config.rpc,
blockchain_read_handle,
context_svc.clone(),
txpool_read_handle,
);

// Start the command listener.
if std::io::IsTerminal::is_terminal(&std::io::stdin()) {
Expand Down
20 changes: 8 additions & 12 deletions binaries/cuprated/src/rpc/handlers/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use cuprate_types::{
};

use crate::rpc::{
handlers::{helper, shared},
handlers::{helper, shared, shared::not_available},
service::{blockchain, txpool},
CupratedRpcHandler,
};
Expand All @@ -44,17 +44,13 @@ pub async fn map_request(
use BinResponse as Resp;

Ok(match request {
Req::GetBlocks(r) => Resp::GetBlocks(get_blocks(state, r).await?),
Req::GetBlocksByHeight(r) => Resp::GetBlocksByHeight(get_blocks_by_height(state, r).await?),
Req::GetHashes(r) => Resp::GetHashes(get_hashes(state, r).await?),
Req::GetOutputIndexes(r) => Resp::GetOutputIndexes(get_output_indexes(state, r).await?),
Req::GetOuts(r) => Resp::GetOuts(get_outs(state, r).await?),
Req::GetTransactionPoolHashes(r) => {
Resp::GetTransactionPoolHashes(get_transaction_pool_hashes(state, r).await?)
}
Req::GetOutputDistribution(r) => {
Resp::GetOutputDistribution(get_output_distribution(state, r).await?)
}
Req::GetBlocks(r) => Resp::GetBlocks(not_available()?),
Req::GetBlocksByHeight(r) => Resp::GetBlocksByHeight(not_available()?),
Req::GetHashes(r) => Resp::GetHashes(not_available()?),
Req::GetOutputIndexes(r) => Resp::GetOutputIndexes(not_available()?),
Req::GetOuts(r) => Resp::GetOuts(not_available()?),
Req::GetTransactionPoolHashes(r) => Resp::GetTransactionPoolHashes(not_available()?),
Req::GetOutputDistribution(r) => Resp::GetOutputDistribution(not_available()?),
})
}

Expand Down
8 changes: 5 additions & 3 deletions binaries/cuprated/src/rpc/handlers/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use cuprate_rpc_types::{
base::{AccessResponseBase, ResponseBase},
misc::BlockHeader,
};
use cuprate_types::HardFork;
use cuprate_types::{Chain, HardFork};
use monero_serai::transaction::Timelock;

use crate::rpc::{
Expand Down Expand Up @@ -58,15 +58,17 @@ pub(super) async fn block_header(
let seed_hash = blockchain::block_hash(
&mut state.blockchain_read,
height,
todo!("access to `cuprated`'s Chain"),
// TODO: access to `cuprated`'s Chain
Chain::Main,
)
.await?;

Some(
blockchain_context::calculate_pow(
&mut state.blockchain_context,
hardfork,
block,
// TODO: expensive clone
block.clone(),
seed_hash,
)
.await?,
Expand Down
93 changes: 40 additions & 53 deletions binaries/cuprated/src/rpc/handlers/json_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use crate::{
constants::VERSION_BUILD,
rpc::{
constants::{FIELD_NOT_SUPPORTED, UNSUPPORTED_RPC_CALL},
handlers::{helper, shared},
handlers::{helper, shared, shared::not_available},
service::{address_book, blockchain, blockchain_context, blockchain_manager, txpool},
CupratedRpcHandler,
},
Expand All @@ -77,11 +77,11 @@ pub async fn map_request(
use JsonRpcResponse as Resp;

Ok(match request {
Req::GetBlockTemplate(r) => Resp::GetBlockTemplate(get_block_template(state, r).await?),
Req::GetBlockTemplate(r) => Resp::GetBlockTemplate(not_available()?),
Req::GetBlockCount(r) => Resp::GetBlockCount(get_block_count(state, r).await?),
Req::OnGetBlockHash(r) => Resp::OnGetBlockHash(on_get_block_hash(state, r).await?),
Req::SubmitBlock(r) => Resp::SubmitBlock(submit_block(state, r).await?),
Req::GenerateBlocks(r) => Resp::GenerateBlocks(generate_blocks(state, r).await?),
Req::SubmitBlock(r) => Resp::SubmitBlock(not_available()?),
Req::GenerateBlocks(r) => Resp::GenerateBlocks(not_available()?),
Req::GetLastBlockHeader(r) => {
Resp::GetLastBlockHeader(get_last_block_header(state, r).await?)
}
Expand All @@ -95,33 +95,25 @@ pub async fn map_request(
Resp::GetBlockHeadersRange(get_block_headers_range(state, r).await?)
}
Req::GetBlock(r) => Resp::GetBlock(get_block(state, r).await?),
Req::GetConnections(r) => Resp::GetConnections(get_connections(state, r).await?),
Req::GetInfo(r) => Resp::GetInfo(get_info(state, r).await?),
Req::HardForkInfo(r) => Resp::HardForkInfo(hard_fork_info(state, r).await?),
Req::SetBans(r) => Resp::SetBans(set_bans(state, r).await?),
Req::GetBans(r) => Resp::GetBans(get_bans(state, r).await?),
Req::Banned(r) => Resp::Banned(banned(state, r).await?),
Req::FlushTransactionPool(r) => {
Resp::FlushTransactionPool(flush_transaction_pool(state, r).await?)
}
Req::GetOutputHistogram(r) => {
Resp::GetOutputHistogram(get_output_histogram(state, r).await?)
}
Req::GetCoinbaseTxSum(r) => Resp::GetCoinbaseTxSum(get_coinbase_tx_sum(state, r).await?),
Req::GetVersion(r) => Resp::GetVersion(get_version(state, r).await?),
Req::GetFeeEstimate(r) => Resp::GetFeeEstimate(get_fee_estimate(state, r).await?),
Req::GetAlternateChains(r) => {
Resp::GetAlternateChains(get_alternate_chains(state, r).await?)
}
Req::RelayTx(r) => Resp::RelayTx(relay_tx(state, r).await?),
Req::SyncInfo(r) => Resp::SyncInfo(sync_info(state, r).await?),
Req::GetTransactionPoolBacklog(r) => {
Resp::GetTransactionPoolBacklog(get_transaction_pool_backlog(state, r).await?)
}
Req::GetMinerData(r) => Resp::GetMinerData(get_miner_data(state, r).await?),
Req::PruneBlockchain(r) => Resp::PruneBlockchain(prune_blockchain(state, r).await?),
Req::CalcPow(r) => Resp::CalcPow(calc_pow(state, r).await?),
Req::AddAuxPow(r) => Resp::AddAuxPow(add_aux_pow(state, r).await?),
Req::GetConnections(r) => Resp::GetConnections(not_available()?),
Req::GetInfo(r) => Resp::GetInfo(not_available()?),
Req::HardForkInfo(r) => Resp::HardForkInfo(not_available()?),
Req::SetBans(r) => Resp::SetBans(not_available()?),
Req::GetBans(r) => Resp::GetBans(not_available()?),
Req::Banned(r) => Resp::Banned(not_available()?),
Req::FlushTransactionPool(r) => Resp::FlushTransactionPool(not_available()?),
Req::GetOutputHistogram(r) => Resp::GetOutputHistogram(not_available()?),
Req::GetCoinbaseTxSum(r) => Resp::GetCoinbaseTxSum(not_available()?),
Req::GetVersion(r) => Resp::GetVersion(not_available()?),
Req::GetFeeEstimate(r) => Resp::GetFeeEstimate(not_available()?),
Req::GetAlternateChains(r) => Resp::GetAlternateChains(not_available()?),
Req::RelayTx(r) => Resp::RelayTx(not_available()?),
Req::SyncInfo(r) => Resp::SyncInfo(not_available()?),
Req::GetTransactionPoolBacklog(r) => Resp::GetTransactionPoolBacklog(not_available()?),
Req::GetMinerData(r) => Resp::GetMinerData(not_available()?),
Req::PruneBlockchain(r) => Resp::PruneBlockchain(not_available()?),
Req::CalcPow(r) => Resp::CalcPow(not_available()?),
Req::AddAuxPow(r) => Resp::AddAuxPow(not_available()?),

// Unsupported RPC calls.
Req::GetTxIdsLoose(_) | Req::FlushCache(_) => return Err(anyhow!(UNSUPPORTED_RPC_CALL)),
Expand Down Expand Up @@ -172,7 +164,7 @@ async fn get_block_template(
seed_hash,
next_seed_hash,
} = *blockchain_manager::create_block_template(
&mut state.blockchain_manager,
todo!(),
prev_block,
request.wallet_address,
request.extra_nonce.0,
Expand Down Expand Up @@ -242,7 +234,7 @@ async fn submit_block(
let block_id = Hex(block.hash());

// Attempt to relay the block.
blockchain_manager::relay_block(&mut state.blockchain_manager, Box::new(block)).await?;
blockchain_manager::relay_block(todo!(), Box::new(block)).await?;

Ok(SubmitBlockResponse {
base: helper::response_base(false),
Expand All @@ -269,7 +261,7 @@ async fn generate_blocks(
};

let (blocks, height) = blockchain_manager::generate_blocks(
&mut state.blockchain_manager,
todo!(),
request.amount_of_blocks,
prev_block,
request.starting_nonce,
Expand Down Expand Up @@ -479,7 +471,7 @@ async fn get_info(
(String::new(), false)
};

let busy_syncing = blockchain_manager::syncing(&mut state.blockchain_manager).await?;
let busy_syncing = blockchain_manager::syncing(todo!()).await?;

let (cumulative_difficulty, cumulative_difficulty_top64) =
split_u128_into_low_high_bits(cumulative_difficulty);
Expand Down Expand Up @@ -524,12 +516,10 @@ async fn get_info(
let rpc_connections_count = if restricted { 0 } else { 0 };

let start_time = if restricted { 0 } else { *START_INSTANT_UNIX };
let synchronized = blockchain_manager::synced(&mut state.blockchain_manager).await?;
let synchronized = blockchain_manager::synced(todo!()).await?;

let target_height = blockchain_manager::target_height(&mut state.blockchain_manager).await?;
let target = blockchain_manager::target(&mut state.blockchain_manager)
.await?
.as_secs();
let target_height = blockchain_manager::target_height(todo!()).await?;
let target = blockchain_manager::target(todo!()).await?.as_secs();
let top_block_hash = Hex(c.top_hash);

let tx_count = blockchain::total_tx_count(&mut state.blockchain_read).await?;
Expand Down Expand Up @@ -738,7 +728,7 @@ async fn flush_transaction_pool(
.map(|h| h.0)
.collect::<Vec<[u8; 32]>>();

txpool::flush(&mut state.txpool_manager, tx_hashes).await?;
txpool::flush(todo!(), tx_hashes).await?;

Ok(FlushTransactionPoolResponse { status: Status::Ok })
}
Expand Down Expand Up @@ -807,7 +797,7 @@ async fn get_version(
_: GetVersionRequest,
) -> Result<GetVersionResponse, Error> {
let current_height = helper::top_height(&mut state).await?.0;
let target_height = blockchain_manager::target_height(&mut state.blockchain_manager).await?;
let target_height = blockchain_manager::target_height(todo!()).await?;

let mut hard_forks = Vec::with_capacity(HardFork::COUNT);

Expand Down Expand Up @@ -880,7 +870,7 @@ async fn relay_tx(
.map(|h| h.0)
.collect::<Vec<[u8; 32]>>();

txpool::relay(&mut state.txpool_manager, tx_hashes).await?;
txpool::relay(todo!(), tx_hashes).await?;

Ok(RelayTxResponse { status: Status::Ok })
}
Expand All @@ -892,20 +882,19 @@ async fn sync_info(
) -> Result<SyncInfoResponse, Error> {
let height = usize_to_u64(state.blockchain_context.blockchain_context().chain_height);

let target_height = blockchain_manager::target_height(&mut state.blockchain_manager).await?;
let target_height = blockchain_manager::target_height(todo!()).await?;

let peers = address_book::connection_info::<ClearNet>(&mut DummyAddressBook)
.await?
.into_iter()
.map(|info| SyncInfoPeer { info })
.collect();

let next_needed_pruning_seed =
blockchain_manager::next_needed_pruning_seed(&mut state.blockchain_manager)
.await?
.compress();
let next_needed_pruning_seed = blockchain_manager::next_needed_pruning_seed(todo!())
.await?
.compress();

let spans = blockchain_manager::spans::<ClearNet>(&mut state.blockchain_manager).await?;
let spans = blockchain_manager::spans::<ClearNet>(todo!()).await?;

// <https://github.com/Cuprate/cuprate/pull/320#discussion_r1811063772>
let overview = String::from(FIELD_NOT_SUPPORTED);
Expand Down Expand Up @@ -994,10 +983,8 @@ async fn prune_blockchain(
mut state: CupratedRpcHandler,
request: PruneBlockchainRequest,
) -> Result<PruneBlockchainResponse, Error> {
let pruned = blockchain_manager::pruned(&mut state.blockchain_manager).await?;
let pruning_seed = blockchain_manager::prune(&mut state.blockchain_manager)
.await?
.compress();
let pruned = blockchain_manager::pruned(todo!()).await?;
let pruning_seed = blockchain_manager::prune(todo!()).await?.compress();

Ok(PruneBlockchainResponse {
base: helper::response_base(false),
Expand Down
Loading
Loading