mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-12-23 12:09:52 +00:00
fix calculate_pow
This commit is contained in:
parent
46bf19861a
commit
1f3b5ed127
3 changed files with 35 additions and 15 deletions
|
@ -8,11 +8,15 @@
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::{anyhow, Error};
|
||||||
use monero_serai::block::Block;
|
use monero_serai::block::Block;
|
||||||
|
|
||||||
|
use cuprate_consensus::{BlockChainContext, BlockChainContextService};
|
||||||
use cuprate_helper::{cast::usize_to_u64, map::split_u128_into_low_high_bits};
|
use cuprate_helper::{cast::usize_to_u64, map::split_u128_into_low_high_bits};
|
||||||
use cuprate_rpc_types::misc::{BlockHeader, KeyImageSpentStatus};
|
use cuprate_rpc_types::misc::{BlockHeader, KeyImageSpentStatus};
|
||||||
use cuprate_types::ExtendedBlockHeader;
|
use cuprate_types::ExtendedBlockHeader;
|
||||||
|
|
||||||
use crate::{rpc::request::blockchain, rpc::CupratedRpcHandler};
|
use crate::{
|
||||||
|
rpc::request::{blockchain, blockchain_context},
|
||||||
|
rpc::CupratedRpcHandler,
|
||||||
|
};
|
||||||
|
|
||||||
pub(super) fn into_block_header(
|
pub(super) fn into_block_header(
|
||||||
height: u64,
|
height: u64,
|
||||||
|
|
|
@ -931,20 +931,31 @@ async fn calc_pow(
|
||||||
let block = Block::read(&mut block_blob.as_slice())?;
|
let block = Block::read(&mut block_blob.as_slice())?;
|
||||||
let seed_hash = helper::hex_to_hash(request.seed_hash)?;
|
let seed_hash = helper::hex_to_hash(request.seed_hash)?;
|
||||||
|
|
||||||
// let pow_hash = blockchain_manager::calculate_pow(
|
let block_weight = todo!();
|
||||||
// &mut state.blockchain_manager,
|
|
||||||
// hardfork,
|
|
||||||
// request.height,
|
|
||||||
// block,
|
|
||||||
// seed_hash,
|
|
||||||
// )
|
|
||||||
// .await?;
|
|
||||||
|
|
||||||
// let hex = hex::encode(pow_hash);
|
let median_for_block_reward = blockchain_context::context(&mut state.blockchain_context)
|
||||||
|
.await?
|
||||||
|
.unchecked_blockchain_context()
|
||||||
|
.context_to_verify_block
|
||||||
|
.median_weight_for_block_reward;
|
||||||
|
|
||||||
let hex = todo!();
|
if cuprate_consensus_rules::blocks::check_block_weight(block_weight, median_for_block_reward)
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
return Err(anyhow!("Block blob size is too big, rejecting block"));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(CalcPowResponse { pow_hash: hex })
|
let pow_hash = blockchain_context::calculate_pow(
|
||||||
|
&mut state.blockchain_context,
|
||||||
|
hardfork,
|
||||||
|
block,
|
||||||
|
seed_hash,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let pow_hash = hex::encode(pow_hash);
|
||||||
|
|
||||||
|
Ok(CalcPowResponse { pow_hash })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3542-L3551>
|
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3542-L3551>
|
||||||
|
|
|
@ -73,17 +73,22 @@ pub(crate) async fn fee_estimate(
|
||||||
pub(crate) async fn calculate_pow(
|
pub(crate) async fn calculate_pow(
|
||||||
blockchain_context: &mut BlockChainContextService,
|
blockchain_context: &mut BlockChainContextService,
|
||||||
hardfork: HardFork,
|
hardfork: HardFork,
|
||||||
height: u64,
|
block: Block,
|
||||||
block: Box<Block>,
|
|
||||||
seed_hash: [u8; 32],
|
seed_hash: [u8; 32],
|
||||||
) -> Result<[u8; 32], Error> {
|
) -> Result<[u8; 32], Error> {
|
||||||
|
let Some(height) = block.number() else {
|
||||||
|
return Err(anyhow!("block is missing height"));
|
||||||
|
};
|
||||||
|
|
||||||
|
let block = Box::new(block);
|
||||||
|
|
||||||
let BlockChainContextResponse::CalculatePow(hash) = blockchain_context
|
let BlockChainContextResponse::CalculatePow(hash) = blockchain_context
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow!(e))?
|
.map_err(|e| anyhow!(e))?
|
||||||
.call(BlockChainContextRequest::CalculatePow {
|
.call(BlockChainContextRequest::CalculatePow {
|
||||||
hardfork,
|
hardfork,
|
||||||
height: u64_to_usize(height),
|
height,
|
||||||
block,
|
block,
|
||||||
seed_hash,
|
seed_hash,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue