mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-03-11 08:56:26 +00:00
add BlockChainContextService
, on_get_block_hash
This commit is contained in:
parent
2522bb8836
commit
fd136b23f6
3 changed files with 20 additions and 16 deletions
|
@ -3,6 +3,7 @@
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
|
use cuprate_consensus::BlockChainContextService;
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
use monero_serai::block::Block;
|
use monero_serai::block::Block;
|
||||||
use tower::Service;
|
use tower::Service;
|
||||||
|
@ -102,6 +103,9 @@ pub struct CupratedRpcHandler {
|
||||||
/// Read handle to the blockchain database.
|
/// Read handle to the blockchain database.
|
||||||
pub blockchain_read: BlockchainReadHandle,
|
pub blockchain_read: BlockchainReadHandle,
|
||||||
|
|
||||||
|
/// Handle to the blockchain context service.
|
||||||
|
pub blockchain_context: BlockChainContextService,
|
||||||
|
|
||||||
/// Handle to the blockchain manager.
|
/// Handle to the blockchain manager.
|
||||||
pub blockchain_manager: BlockchainManagerHandle,
|
pub blockchain_manager: BlockchainManagerHandle,
|
||||||
|
|
||||||
|
@ -117,6 +121,7 @@ impl CupratedRpcHandler {
|
||||||
pub const fn new(
|
pub const fn new(
|
||||||
restricted: bool,
|
restricted: bool,
|
||||||
blockchain_read: BlockchainReadHandle,
|
blockchain_read: BlockchainReadHandle,
|
||||||
|
blockchain_context: BlockChainContextService,
|
||||||
blockchain_manager: BlockchainManagerHandle,
|
blockchain_manager: BlockchainManagerHandle,
|
||||||
txpool_read: TxpoolReadHandle,
|
txpool_read: TxpoolReadHandle,
|
||||||
txpool_manager: std::convert::Infallible,
|
txpool_manager: std::convert::Infallible,
|
||||||
|
@ -124,6 +129,7 @@ impl CupratedRpcHandler {
|
||||||
Self {
|
Self {
|
||||||
restricted,
|
restricted,
|
||||||
blockchain_read,
|
blockchain_read,
|
||||||
|
blockchain_context,
|
||||||
blockchain_manager,
|
blockchain_manager,
|
||||||
txpool_read,
|
txpool_read,
|
||||||
txpool_manager,
|
txpool_manager,
|
||||||
|
|
|
@ -38,7 +38,11 @@ use cuprate_rpc_types::{
|
||||||
CORE_RPC_VERSION,
|
CORE_RPC_VERSION,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::rpc::{helper, request::blockchain, CupratedRpcHandler};
|
use crate::rpc::{
|
||||||
|
helper,
|
||||||
|
request::{blockchain, blockchain_context, blockchain_manager},
|
||||||
|
CupratedRpcHandler,
|
||||||
|
};
|
||||||
|
|
||||||
/// Map a [`JsonRpcRequest`] to the function that will lead to a [`JsonRpcResponse`].
|
/// Map a [`JsonRpcRequest`] to the function that will lead to a [`JsonRpcResponse`].
|
||||||
pub(super) async fn map_request(
|
pub(super) async fn map_request(
|
||||||
|
@ -115,7 +119,8 @@ async fn on_get_block_hash(
|
||||||
request: OnGetBlockHashRequest,
|
request: OnGetBlockHashRequest,
|
||||||
) -> Result<OnGetBlockHashResponse, Error> {
|
) -> Result<OnGetBlockHashResponse, Error> {
|
||||||
let [height] = request.block_height;
|
let [height] = request.block_height;
|
||||||
let hash = blockchain::block_hash(&mut state.blockchain_read, height, todo!()).await?;
|
let hash = blockchain::block_hash(&mut state.blockchain_read, height, todo!("access to chain"))
|
||||||
|
.await?;
|
||||||
let block_hash = hex::encode(hash);
|
let block_hash = hex::encode(hash);
|
||||||
|
|
||||||
Ok(OnGetBlockHashResponse { block_hash })
|
Ok(OnGetBlockHashResponse { block_hash })
|
||||||
|
@ -126,21 +131,14 @@ async fn submit_block(
|
||||||
mut state: CupratedRpcHandler,
|
mut state: CupratedRpcHandler,
|
||||||
request: SubmitBlockRequest,
|
request: SubmitBlockRequest,
|
||||||
) -> Result<SubmitBlockResponse, Error> {
|
) -> Result<SubmitBlockResponse, Error> {
|
||||||
|
// Parse hex into block.
|
||||||
let [blob] = request.block_blob;
|
let [blob] = request.block_blob;
|
||||||
|
|
||||||
let limit = todo!(); //blockchain::cumulative_block_weight_limit(&mut state.blockchain_read).await?;
|
|
||||||
|
|
||||||
// if blob.len() > limit + BLOCK_SIZE_SANITY_LEEWAY {
|
|
||||||
// return Err(anyhow!("Block size is too big, rejecting block"));
|
|
||||||
// }
|
|
||||||
|
|
||||||
let bytes = hex::decode(blob)?;
|
let bytes = hex::decode(blob)?;
|
||||||
let block = Block::read(&mut bytes.as_slice())?;
|
let block = Block::read(&mut bytes.as_slice())?;
|
||||||
|
let block_id = hex::encode(block.hash());
|
||||||
|
|
||||||
// <https://github.com/monero-project/monero/blob/master/src/cryptonote_core/cryptonote_core.cpp#L1540>
|
// Attempt to relay the block.
|
||||||
let block_id = todo!("submit block to DB");
|
blockchain_manager::relay_block(&mut state.blockchain_manager, block).await?;
|
||||||
todo!("relay to P2P");
|
|
||||||
todo!("send to txpool");
|
|
||||||
|
|
||||||
Ok(SubmitBlockResponse {
|
Ok(SubmitBlockResponse {
|
||||||
base: ResponseBase::ok(),
|
base: ResponseBase::ok(),
|
||||||
|
@ -383,7 +381,7 @@ async fn hard_fork_info(
|
||||||
Ok(HardForkInfoResponse {
|
Ok(HardForkInfoResponse {
|
||||||
base: AccessResponseBase::ok(),
|
base: AccessResponseBase::ok(),
|
||||||
earliest_height: todo!(),
|
earliest_height: todo!(),
|
||||||
enabled: hard_fork.is_current(),
|
enabled: todo!("hard_fork.is_latest() is not always correct"),
|
||||||
state: todo!(),
|
state: todo!(),
|
||||||
threshold: todo!(),
|
threshold: todo!(),
|
||||||
version: hard_fork.as_u8(),
|
version: hard_fork.as_u8(),
|
||||||
|
|
|
@ -836,9 +836,9 @@ define_request_and_response! {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
state: 0,
|
state: 0,
|
||||||
threshold: 0,
|
threshold: 0,
|
||||||
version: 3,
|
version: 16,
|
||||||
votes: 10080,
|
votes: 10080,
|
||||||
voting: 3,
|
voting: 16,
|
||||||
window: 10080
|
window: 10080
|
||||||
}
|
}
|
||||||
)]
|
)]
|
||||||
|
|
Loading…
Reference in a new issue