mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-24 11:26:03 +00:00
Compare commits
No commits in common. "2d2d4931f82029304c4fa378b66abb0727fb3495" and "d634bea297a7b65b276ab903b07bb5220191a52c" have entirely different histories.
2d2d4931f8
...
d634bea297
1 changed files with 35 additions and 35 deletions
|
@ -1,8 +1,4 @@
|
||||||
//! RPC request handler functions (JSON-RPC).
|
//! RPC request handler functions (JSON-RPC).
|
||||||
//!
|
|
||||||
//! TODO:
|
|
||||||
//! Many handlers have `todo!()`s for internals that must be completed, see:
|
|
||||||
//! <https://github.com/Cuprate/cuprate/pull/308>
|
|
||||||
|
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
@ -440,7 +436,9 @@ async fn get_info(
|
||||||
let rpc_connections_count = if restricted {
|
let rpc_connections_count = if restricted {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
todo!("implement a connection counter in axum/RPC")
|
todo!(
|
||||||
|
"implement a connection counter in axum/RPC, maybe `AtomicU64` any handler activating"
|
||||||
|
)
|
||||||
};
|
};
|
||||||
let start_time = if restricted { 0 } else { *START_INSTANT_UNIX };
|
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(&mut state.blockchain_manager).await?;
|
||||||
|
@ -1009,16 +1007,8 @@ async fn flush_cache(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An async-friendly wrapper for [`add_aux_pow_inner`].
|
|
||||||
async fn add_aux_pow(
|
|
||||||
state: CupratedRpcHandler,
|
|
||||||
request: AddAuxPowRequest,
|
|
||||||
) -> Result<AddAuxPowResponse, Error> {
|
|
||||||
tokio::task::spawn_blocking(|| add_aux_pow_inner(state, request)).await?
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L2072-L2207>
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L2072-L2207>
|
||||||
fn add_aux_pow_inner(
|
async fn add_aux_pow(
|
||||||
mut state: CupratedRpcHandler,
|
mut state: CupratedRpcHandler,
|
||||||
request: AddAuxPowRequest,
|
request: AddAuxPowRequest,
|
||||||
) -> Result<AddAuxPowResponse, Error> {
|
) -> Result<AddAuxPowResponse, Error> {
|
||||||
|
@ -1047,42 +1037,52 @@ fn add_aux_pow_inner(
|
||||||
|
|
||||||
let len = aux_pow.len();
|
let len = aux_pow.len();
|
||||||
|
|
||||||
// TODO: why is this here? it does nothing:
|
|
||||||
// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L2110-L2112>
|
|
||||||
let mut path_domain = 1_usize;
|
let mut path_domain = 1_usize;
|
||||||
while 1 << path_domain < len {
|
while 1 << path_domain < len {
|
||||||
path_domain += 1;
|
path_domain += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_nonce(aux_pow_len: usize) -> Result<(u32, Box<[u32]>), Error> {
|
let mut nonce = 0_u32;
|
||||||
// INVARIANT: this must be the same `.len()` as `aux_pow`
|
let mut collision = true;
|
||||||
let mut slots: Box<[u32]> = vec![u32::MAX; aux_pow_len].into_boxed_slice();
|
let mut slots: Box<[u32]> = vec![0; len].into_boxed_slice(); // INVARIANT: this must be the same `.len()` as `aux_pow`
|
||||||
let mut slot_seen: Box<[bool]> = vec![false; aux_pow_len].into_boxed_slice();
|
|
||||||
|
|
||||||
for nonce in 0..u32::MAX {
|
for n in 0..u32::MAX {
|
||||||
for i in &mut slots {
|
nonce = n;
|
||||||
let slot_u32: u32 = todo!("const uint32_t slot = cryptonote::get_aux_slot(aux_pow[idx].first, nonce, aux_pow.size());");
|
|
||||||
let slot = u32_to_usize(slot_u32);
|
|
||||||
|
|
||||||
if slot >= aux_pow_len {
|
let slot_seen: Vec<bool> = vec![false; len];
|
||||||
return Err(anyhow!("Computed slot is out of range"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if slot_seen[slot] {
|
collision = false;
|
||||||
return Ok((nonce, slots));
|
|
||||||
}
|
|
||||||
|
|
||||||
slot_seen[slot] = true;
|
slots.iter_mut().for_each(|i| *i = u32::MAX);
|
||||||
*i = slot_u32;
|
|
||||||
|
for i in &mut slots {
|
||||||
|
let slot_u32: u32 = todo!("const uint32_t slot = cryptonote::get_aux_slot(aux_pow[idx].first, nonce, aux_pow.size());");
|
||||||
|
let slot = u32_to_usize(slot_u32);
|
||||||
|
|
||||||
|
if slot >= len {
|
||||||
|
return Err(anyhow!("Computed slot is out of range"));
|
||||||
}
|
}
|
||||||
|
|
||||||
slots.fill(u32::MAX);
|
if slot_seen[slot] {
|
||||||
|
collision = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
slot_seen[slot] = true;
|
||||||
|
*i = slot_u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(anyhow!("Failed to find a suitable nonce"))
|
if !collision {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (nonce, slots) = find_nonce(len)?;
|
let nonce = nonce;
|
||||||
|
let slots = slots;
|
||||||
|
|
||||||
|
if collision {
|
||||||
|
return Err(anyhow!("Failed to find a suitable nonce"));
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: use iterator version.
|
// FIXME: use iterator version.
|
||||||
let (aux_pow_id_raw, aux_pow_raw) = {
|
let (aux_pow_id_raw, aux_pow_raw) = {
|
||||||
|
|
Loading…
Reference in a new issue