mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
4fda7a6899
* verify a tx like we verify a block (experimental) * first minimal_pool test up and running but not testing what we need to * rework tx_pool validation to use txhashset extension * minimal tx pool wired up but rough * works locally (rough statew though) delete "legacy" pool and graph code * rework the new pool into TransactionPool and Pool impls * rework pool to store pool entries with associated timer and source etc. * all_transactions * extra_txs so we can validate stempool against existing txpool * rework reconcile_block * txhashset apply_raw_tx can now rewind to a checkpoint (prev raw tx) * wip - txhashset tx tests * more flexible rewind on MMRs * add tests to cover apply_raw_txs on txhashset extension * add_to_stempool and add_to_txpool * deaggregate multi kernel tx when adding to txpoool * handle freshness in stempool handle propagation of stempool txs via dandelion monitor * patience timer and fluff if we cannot propagate to next relay * aggregate and fluff stempool is we have no relay * refactor coinbase maturity * rewrote basic tx pool tests to use a real txhashset via chain adapter * rework dandelion monitor to reflect recent discussion works locally but needs a cleanup * refactor dandelion_monitor - split out phases * more pool test coverage * remove old test code from pool (still wip) * block_building and block_reconciliation tests * tracked down chain test failure... * fix test_coinbase_maturity * dandelion_monitor now runs... * refactor dandelion config, shared across p2p and pool components * fix pool tests with new config * fix p2p tests * rework tx pool to deal with duplicate commitments (testnet2 limitation) * cleanup and address some PR feedback * add big comment about pre_tx...
100 lines
2.7 KiB
Rust
100 lines
2.7 KiB
Rust
// Copyright 2018 The Grin Developers
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
extern crate blake2_rfc as blake2;
|
|
extern crate grin_chain as chain;
|
|
extern crate grin_core as core;
|
|
extern crate grin_keychain as keychain;
|
|
extern crate grin_pool as pool;
|
|
extern crate grin_util as util;
|
|
extern crate grin_wallet as wallet;
|
|
|
|
extern crate rand;
|
|
extern crate time;
|
|
|
|
pub mod common;
|
|
|
|
use std::sync::{Arc, RwLock};
|
|
|
|
use core::core::Transaction;
|
|
|
|
use keychain::Keychain;
|
|
use pool::TransactionPool;
|
|
use pool::types::*;
|
|
|
|
use common::*;
|
|
|
|
pub fn test_setup(
|
|
chain: &Arc<CoinbaseMaturityErrorChainAdapter>,
|
|
) -> TransactionPool<CoinbaseMaturityErrorChainAdapter> {
|
|
TransactionPool::new(
|
|
PoolConfig {
|
|
accept_fee_base: 0,
|
|
max_pool_size: 50,
|
|
},
|
|
chain.clone(),
|
|
Arc::new(NoopAdapter {}),
|
|
)
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct CoinbaseMaturityErrorChainAdapter {}
|
|
|
|
impl CoinbaseMaturityErrorChainAdapter {
|
|
pub fn new() -> CoinbaseMaturityErrorChainAdapter {
|
|
CoinbaseMaturityErrorChainAdapter {}
|
|
}
|
|
}
|
|
|
|
impl BlockChain for CoinbaseMaturityErrorChainAdapter {
|
|
fn validate_raw_txs(
|
|
&self,
|
|
_txs: Vec<Transaction>,
|
|
_pre_tx: Option<Transaction>,
|
|
) -> Result<Vec<Transaction>, PoolError> {
|
|
Err(PoolError::Other(
|
|
"not implemented, not a real chain adapter...".to_string(),
|
|
))
|
|
}
|
|
|
|
// Returns an ImmatureCoinbase for every tx we pass in.
|
|
fn verify_coinbase_maturity(&self, _tx: &Transaction) -> Result<(), PoolError> {
|
|
Err(PoolError::ImmatureCoinbase)
|
|
}
|
|
|
|
// Mocking this out for these tests.
|
|
fn verify_tx_lock_height(&self, _tx: &Transaction) -> Result<(), PoolError> {
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
/// Test we correctly verify coinbase maturity when adding txs to the pool.
|
|
#[test]
|
|
fn test_coinbase_maturity() {
|
|
let keychain = Keychain::from_random_seed().unwrap();
|
|
|
|
// Mocking this up with an adapter that will raise an error for coinbase
|
|
// maturity.
|
|
let chain = CoinbaseMaturityErrorChainAdapter::new();
|
|
let pool = RwLock::new(test_setup(&Arc::new(chain.clone())));
|
|
|
|
{
|
|
let mut write_pool = pool.write().unwrap();
|
|
let tx = test_transaction(&keychain, vec![50], vec![49]);
|
|
match write_pool.add_to_pool(test_source(), tx.clone(), true) {
|
|
Err(PoolError::ImmatureCoinbase) => {}
|
|
_ => panic!("Expected an immature coinbase error here."),
|
|
}
|
|
}
|
|
}
|