Stop caching the Monero block hash now in processor that we have Block::hash

This commit is contained in:
Luke Parker
2023-07-03 12:39:47 -04:00
parent 2bbd545704
commit 06faeec5bc

View File

@@ -13,7 +13,7 @@ use frost::{curve::Ed25519, ThresholdKeys};
use monero_serai::{ use monero_serai::{
Protocol, Protocol,
transaction::Transaction, transaction::Transaction,
block::Block as MBlock, block::Block,
rpc::{RpcError, HttpRpc, Rpc}, rpc::{RpcError, HttpRpc, Rpc},
wallet::{ wallet::{
ViewPair, Scanner, ViewPair, Scanner,
@@ -134,20 +134,18 @@ pub struct SignableTransaction {
actual: MSignableTransaction, actual: MSignableTransaction,
} }
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Block([u8; 32], MBlock);
impl BlockTrait<Monero> for Block { impl BlockTrait<Monero> for Block {
type Id = [u8; 32]; type Id = [u8; 32];
fn id(&self) -> Self::Id { fn id(&self) -> Self::Id {
self.0 self.hash()
} }
fn parent(&self) -> Self::Id { fn parent(&self) -> Self::Id {
self.1.header.previous self.header.previous
} }
fn time(&self) -> u64 { fn time(&self) -> u64 {
self.1.header.timestamp self.header.timestamp
} }
fn median_fee(&self) -> Fee { fn median_fee(&self) -> Fee {
@@ -256,14 +254,18 @@ impl Coin for Monero {
} }
async fn get_block(&self, number: usize) -> Result<Self::Block, CoinError> { async fn get_block(&self, number: usize) -> Result<Self::Block, CoinError> {
let hash = self.rpc.get_block_hash(number).await.map_err(|_| CoinError::ConnectionError)?; Ok(Block(
let block = self.rpc.get_block(hash).await.map_err(|_| CoinError::ConnectionError)?; self
Ok(Block(hash, block)) .rpc
.get_block(self.rpc.get_block_hash(number).await.map_err(|_| CoinError::ConnectionError)?)
.await
.map_err(|_| CoinError::ConnectionError)?,
))
} }
async fn get_outputs( async fn get_outputs(
&self, &self,
block: &Self::Block, block: &Block,
key: EdwardsPoint, key: EdwardsPoint,
) -> Result<Vec<Self::Output>, CoinError> { ) -> Result<Vec<Self::Output>, CoinError> {
let mut txs = Self::scanner(key) let mut txs = Self::scanner(key)
@@ -305,7 +307,7 @@ impl Coin for Monero {
async fn get_eventuality_completions( async fn get_eventuality_completions(
&self, &self,
eventualities: &mut EventualitiesTracker<Eventuality>, eventualities: &mut EventualitiesTracker<Eventuality>,
block: &Self::Block, block: &Block,
) -> HashMap<[u8; 32], [u8; 32]> { ) -> HashMap<[u8; 32], [u8; 32]> {
let block = &block.1; let block = &block.1;
@@ -317,7 +319,7 @@ impl Coin for Monero {
async fn check_block( async fn check_block(
coin: &Monero, coin: &Monero,
eventualities: &mut EventualitiesTracker<Eventuality>, eventualities: &mut EventualitiesTracker<Eventuality>,
block: &MBlock, block: &Block,
res: &mut HashMap<[u8; 32], [u8; 32]>, res: &mut HashMap<[u8; 32], [u8; 32]>,
) { ) {
for hash in &block.txs { for hash in &block.txs {