Skip to content

Commit

Permalink
grin v5.3 (0071) never speak of the verifier cache again (mimblewimbl…
Browse files Browse the repository at this point in the history
  • Loading branch information
bayk committed Jun 17, 2024
1 parent 6237f54 commit 2d8a6fe
Show file tree
Hide file tree
Showing 42 changed files with 203 additions and 783 deletions.
11 changes: 4 additions & 7 deletions api/src/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::chain::{Chain, SyncState};
use crate::core::core::hash::Hash;
use crate::core::core::hash::Hashed;
use crate::core::core::transaction::Transaction;
use crate::core::core::verifier_cache::VerifierCache;
use crate::handlers::blocks_api::{BlockHandler, HeaderHandler};
use crate::handlers::chain_api::{ChainHandler, KernelHandler, OutputHandler};
use crate::handlers::pool_api::PoolHandler;
Expand All @@ -43,23 +42,21 @@ use std::sync::Weak;
/// Methods in this API are intended to be 'single use'.
///
pub struct Foreign<B, P, V>
pub struct Foreign<B, P>
where
B: BlockChain,
P: PoolAdapter,
V: VerifierCache + 'static,
{
pub peers: Weak<grin_p2p::Peers>,
pub chain: Weak<Chain>,
pub tx_pool: Weak<RwLock<pool::TransactionPool<B, P, V>>>,
pub tx_pool: Weak<RwLock<pool::TransactionPool<B, P>>>,
pub sync_state: Weak<SyncState>,
}

impl<B, P, V> Foreign<B, P, V>
impl<B, P> Foreign<B, P>
where
B: BlockChain,
P: PoolAdapter,
V: VerifierCache + 'static,
{
/// Create a new API instance with the chain, transaction pool, peers and `sync_state`. All subsequent
/// API calls will operate on this instance of node API.
Expand All @@ -78,7 +75,7 @@ where
pub fn new(
peers: Weak<grin_p2p::Peers>,
chain: Weak<Chain>,
tx_pool: Weak<RwLock<pool::TransactionPool<B, P, V>>>,
tx_pool: Weak<RwLock<pool::TransactionPool<B, P>>>,
sync_state: Weak<SyncState>,
) -> Self {
Foreign {
Expand Down
4 changes: 1 addition & 3 deletions api/src/foreign_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use crate::core::core::hash::Hash;
use crate::core::core::transaction::Transaction;
use crate::core::core::verifier_cache::VerifierCache;
use crate::foreign::Foreign;
use crate::pool::PoolEntry;
use crate::pool::{BlockChain, PoolAdapter};
Expand Down Expand Up @@ -904,11 +903,10 @@ pub trait ForeignRpc: Sync + Send {
fn get_libp2p_messages(&self) -> Result<Libp2pMessages, ErrorKind>;
}

impl<B, P, V> ForeignRpc for Foreign<B, P, V>
impl<B, P> ForeignRpc for Foreign<B, P>
where
B: BlockChain,
P: PoolAdapter,
V: VerifierCache + 'static,
{
fn get_header(
&self,
Expand Down
24 changes: 9 additions & 15 deletions api/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ use crate::auth::{
};
use crate::chain;
use crate::chain::{Chain, SyncState};
use crate::core::core::verifier_cache::VerifierCache;
use crate::core::global;
use crate::core::stratum;
use crate::foreign::Foreign;
Expand Down Expand Up @@ -71,10 +70,10 @@ use std::thread;

/// Listener version, providing same API but listening for requests on a
/// port and wrapping the calls
pub fn node_apis<B, P, V>(
pub fn node_apis<B, P>(
addr: &str,
chain: Arc<chain::Chain>,
tx_pool: Arc<RwLock<pool::TransactionPool<B, P, V>>>,
tx_pool: Arc<RwLock<pool::TransactionPool<B, P>>>,
peers: Arc<p2p::Peers>,
sync_state: Arc<chain::SyncState>,
api_secret: Option<String>,
Expand All @@ -88,7 +87,6 @@ pub fn node_apis<B, P, V>(
where
B: BlockChain + 'static,
P: PoolAdapter + 'static,
V: VerifierCache + 'static,
{
// Manually build router when getting rid of v1
//let mut router = Router::new();
Expand Down Expand Up @@ -241,29 +239,27 @@ impl crate::router::Handler for OwnerAPIHandlerV2 {
}

/// V2 API Handler/Wrapper for foreign functions
pub struct ForeignAPIHandlerV2<B, P, V>
pub struct ForeignAPIHandlerV2<B, P>
where
B: BlockChain,
P: PoolAdapter,
V: VerifierCache + 'static,
{
pub peers: Weak<grin_p2p::Peers>,
pub chain: Weak<Chain>,
pub tx_pool: Weak<RwLock<pool::TransactionPool<B, P, V>>>,
pub tx_pool: Weak<RwLock<pool::TransactionPool<B, P>>>,
pub sync_state: Weak<SyncState>,
}

impl<B, P, V> ForeignAPIHandlerV2<B, P, V>
impl<B, P> ForeignAPIHandlerV2<B, P>
where
B: BlockChain,
P: PoolAdapter,
V: VerifierCache + 'static,
{
/// Create a new foreign API handler for GET methods
pub fn new(
peers: Weak<grin_p2p::Peers>,
chain: Weak<Chain>,
tx_pool: Weak<RwLock<pool::TransactionPool<B, P, V>>>,
tx_pool: Weak<RwLock<pool::TransactionPool<B, P>>>,
sync_state: Weak<SyncState>,
) -> Self {
ForeignAPIHandlerV2 {
Expand All @@ -275,11 +271,10 @@ where
}
}

impl<B, P, V> crate::router::Handler for ForeignAPIHandlerV2<B, P, V>
impl<B, P> crate::router::Handler for ForeignAPIHandlerV2<B, P>
where
B: BlockChain + 'static,
P: PoolAdapter + 'static,
V: VerifierCache + 'static,
{
fn post(&self, req: Request<Body>) -> ResponseFuture {
let api = Foreign::new(
Expand Down Expand Up @@ -425,17 +420,16 @@ fn response<T: Into<Body>>(status: StatusCode, text: T) -> Response<Body> {
since = "4.0.0",
note = "The V1 Node API will be removed in grin 5.0.0. Please migrate to the V2 API as soon as possible."
)]*/
pub fn build_router<B, P, V>(
pub fn build_router<B, P>(
chain: Arc<chain::Chain>,
tx_pool: Arc<RwLock<pool::TransactionPool<B, P, V>>>,
tx_pool: Arc<RwLock<pool::TransactionPool<B, P>>>,
peers: Arc<p2p::Peers>,
sync_state: Arc<chain::SyncState>,
allow_to_stop: bool,
) -> Result<Router, RouterError>
where
B: BlockChain + 'static,
P: PoolAdapter + 'static,
V: VerifierCache + 'static,
{
let route_list = vec![
"get blocks".to_string(),
Expand Down
30 changes: 11 additions & 19 deletions api/src/handlers/pool_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use super::utils::w;
use crate::core::core::hash::Hashed;
use crate::core::core::verifier_cache::VerifierCache;
use crate::core::core::Transaction;
use crate::core::ser::{self, ProtocolVersion};
use crate::pool::{self, BlockChain, PoolAdapter, PoolEntry};
Expand All @@ -29,20 +28,18 @@ use std::sync::Weak;

/// Get basic information about the transaction pool.
/// GET /v1/pool
pub struct PoolInfoHandler<B, P, V>
pub struct PoolInfoHandler<B, P>
where
B: BlockChain,
P: PoolAdapter,
V: VerifierCache + 'static,
{
pub tx_pool: Weak<RwLock<pool::TransactionPool<B, P, V>>>,
pub tx_pool: Weak<RwLock<pool::TransactionPool<B, P>>>,
}

impl<B, P, V> Handler for PoolInfoHandler<B, P, V>
impl<B, P> Handler for PoolInfoHandler<B, P>
where
B: BlockChain,
P: PoolAdapter,
V: VerifierCache + 'static,
{
fn get(&self, _req: Request<Body>) -> ResponseFuture {
let pool_arc = w_fut!(&self.tx_pool);
Expand All @@ -54,20 +51,18 @@ where
}
}

pub struct PoolHandler<B, P, V>
pub struct PoolHandler<B, P>
where
B: BlockChain,
P: PoolAdapter,
V: VerifierCache + 'static,
{
pub tx_pool: Weak<RwLock<pool::TransactionPool<B, P, V>>>,
pub tx_pool: Weak<RwLock<pool::TransactionPool<B, P>>>,
}

impl<B, P, V> PoolHandler<B, P, V>
impl<B, P> PoolHandler<B, P>
where
B: BlockChain,
P: PoolAdapter,
V: VerifierCache + 'static,
{
pub fn get_pool_size(&self) -> Result<usize, Error> {
let pool_arc = w(&self.tx_pool)?;
Expand Down Expand Up @@ -121,23 +116,21 @@ struct TxWrapper {

/// Push new transaction to our local transaction pool.
/// POST /v1/pool/push_tx
pub struct PoolPushHandler<B, P, V>
pub struct PoolPushHandler<B, P>
where
B: BlockChain,
P: PoolAdapter,
V: VerifierCache + 'static,
{
pub tx_pool: Weak<RwLock<pool::TransactionPool<B, P, V>>>,
pub tx_pool: Weak<RwLock<pool::TransactionPool<B, P>>>,
}

async fn update_pool<B, P, V>(
pool: Weak<RwLock<pool::TransactionPool<B, P, V>>>,
async fn update_pool<B, P>(
pool: Weak<RwLock<pool::TransactionPool<B, P>>>,
req: Request<Body>,
) -> Result<(), Error>
where
B: BlockChain,
P: PoolAdapter,
V: VerifierCache + 'static,
{
let pool = w(&pool)?;
let params = QueryParams::from(req.uri().query());
Expand Down Expand Up @@ -181,11 +174,10 @@ where
Ok(())
}

impl<B, P, V> Handler for PoolPushHandler<B, P, V>
impl<B, P> Handler for PoolPushHandler<B, P>
where
B: BlockChain + 'static,
P: PoolAdapter + 'static,
V: VerifierCache + 'static,
{
fn post(&self, req: Request<Body>) -> ResponseFuture {
let pool = self.tx_pool.clone();
Expand Down
5 changes: 0 additions & 5 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use crate::core::core::hash::{Hash, Hashed};
use crate::core::core::merkle_proof::MerkleProof;
use crate::core::core::verifier_cache::VerifierCache;
use crate::core::core::{
Block, BlockHeader, BlockSums, Committed, Inputs, KernelFeatures, Output, OutputIdentifier,
SegmentIdentifier, Transaction, TxKernel,
Expand Down Expand Up @@ -156,7 +155,6 @@ pub struct Chain {
txhashset: Arc<RwLock<txhashset::TxHashSet>>,
header_pmmr: Arc<RwLock<txhashset::PMMRHandle<BlockHeader>>>,
sync_pmmr: Arc<RwLock<txhashset::PMMRHandle<BlockHeader>>>,
verifier_cache: Arc<RwLock<dyn VerifierCache>>,
pibd_segmenter: Arc<RwLock<Option<Segmenter>>>,
// POW verification function
pow_verifier: fn(&BlockHeader) -> Result<(), pow::Error>,
Expand All @@ -173,7 +171,6 @@ impl Chain {
adapter: Arc<dyn ChainAdapter + Send + Sync>,
genesis: Block,
pow_verifier: fn(&BlockHeader) -> Result<(), pow::Error>,
verifier_cache: Arc<RwLock<dyn VerifierCache>>,
archive_mode: bool,
) -> Result<Chain, Error> {
let store = Arc::new(store::ChainStore::new(&db_root)?);
Expand Down Expand Up @@ -225,7 +222,6 @@ impl Chain {
sync_pmmr: Arc::new(RwLock::new(sync_pmmr)),
pibd_segmenter: Arc::new(RwLock::new(None)),
pow_verifier,
verifier_cache,
archive_mode,
genesis: genesis.header,
};
Expand Down Expand Up @@ -614,7 +610,6 @@ impl Chain {
Ok(pipe::BlockContext {
opts,
pow_verifier: self.pow_verifier,
verifier_cache: self.verifier_cache.clone(),
header_pmmr,
txhashset,
batch,
Expand Down
8 changes: 2 additions & 6 deletions chain/src/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use crate::core::consensus;
use crate::core::core::hash::Hashed;
use crate::core::core::verifier_cache::VerifierCache;
use crate::core::core::Committed;
use crate::core::core::{
block, Block, BlockHeader, BlockSums, HeaderVersion, OutputIdentifier, TransactionBody,
Expand All @@ -27,11 +26,10 @@ use crate::error::{Error, ErrorKind};
use crate::store;
use crate::txhashset;
use crate::types::{CommitPos, Options, Tip};
use crate::util::RwLock;
use grin_core::core::hash::Hash;
use grin_util::RwLock;
use std::collections::HashSet;
use std::iter::FromIterator;
use std::sync::Arc;

/// Contextual information required to process a new block and either reject or
/// accept it.
Expand All @@ -46,8 +44,6 @@ pub struct BlockContext<'a> {
pub header_pmmr: &'a mut txhashset::PMMRHandle<BlockHeader>,
/// The active batch to use for block processing.
pub batch: store::Batch<'a>,
/// The verifier cache (caching verifier for rangeproofs and kernel signatures)
pub verifier_cache: Arc<RwLock<dyn VerifierCache>>,
}

lazy_static! {
Expand Down Expand Up @@ -540,7 +536,7 @@ fn validate_header(header: &BlockHeader, ctx: &mut BlockContext<'_>) -> Result<(
fn validate_block(block: &Block, ctx: &mut BlockContext<'_>) -> Result<(), Error> {
let prev = ctx.batch.get_previous_header(&block.header)?;
block
.validate(&prev.total_kernel_offset, ctx.verifier_cache.clone())
.validate(&prev.total_kernel_offset)
.map_err(ErrorKind::InvalidBlockProof)?;
Ok(())
}
Expand Down
5 changes: 0 additions & 5 deletions chain/tests/chain_test_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ use self::chain::types::NoopAdapter;
use self::chain::types::Options;
use self::chain::Chain;
use self::core::core::hash::Hashed;
use self::core::core::verifier_cache::LruVerifierCache;
use self::core::core::Block;
use self::core::genesis;
use self::core::global::ChainTypes;
use self::core::libtx::{self, reward};
use self::core::{consensus, global, pow};
use self::keychain::{ExtKeychainPath, Keychain};
use self::util::RwLock;
use chrono::Duration;
use grin_chain as chain;
use grin_core as core;
use grin_keychain as keychain;
use grin_util as util;
use std::fs;
use std::sync::Arc;

Expand All @@ -37,13 +34,11 @@ pub fn clean_output_dir(dir_name: &str) {
}

pub fn init_chain(dir_name: &str, genesis: Block) -> Chain {
let verifier_cache = Arc::new(RwLock::new(LruVerifierCache::new()));
Chain::init(
dir_name.to_string(),
Arc::new(NoopAdapter {}),
genesis,
pow::verify_size,
verifier_cache,
false,
)
.unwrap()
Expand Down
Loading

0 comments on commit 2d8a6fe

Please sign in to comment.