cleaning up
This commit is contained in:
parent
07069cab14
commit
14df21533d
|
@ -26,9 +26,13 @@ pub struct ConsensusParams {
|
|||
/// BIP141, BIP143, BIP147 deployment
|
||||
pub segwit_deployment: Option<Deployment>,
|
||||
|
||||
/// Interval (in blocks) to calculate average work.
|
||||
pub pow_averaging_window: u32,
|
||||
/// % of possible down adjustment of work.
|
||||
pub pow_max_adjust_down: u32,
|
||||
/// % of possible up adjustment of work.
|
||||
pub pow_max_adjust_up: u32,
|
||||
/// Optimal blocks interval (in seconds).
|
||||
pub pow_target_spacing: u32,
|
||||
}
|
||||
|
||||
|
@ -102,6 +106,14 @@ impl ConsensusParams {
|
|||
(self.averaging_window_timespan() * (100 + self.pow_max_adjust_down)) / 100
|
||||
}
|
||||
|
||||
pub fn max_block_size(&self) -> usize {
|
||||
2_000_000
|
||||
}
|
||||
|
||||
pub fn max_block_sigops(&self) -> usize {
|
||||
20_000
|
||||
}
|
||||
|
||||
pub fn max_transaction_size(&self) -> usize {
|
||||
100_000 // TODO: changed after sapling
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use storage;
|
|||
use message::Services;
|
||||
use network::{Network, ConsensusParams};
|
||||
use p2p::InternetProtocol;
|
||||
use seednodes::zcash_seednodes;
|
||||
use seednodes::{zcash_seednodes, zcash_testnet_seednodes};
|
||||
use rpc_apis::ApiSet;
|
||||
use {USER_AGENT, REGTEST_USER_AGENT};
|
||||
use primitives::hash::H256;
|
||||
|
@ -96,7 +96,8 @@ pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
|
|||
Some(s) => vec![s.parse().map_err(|_| "Invalid seednode".to_owned())?],
|
||||
None => match network {
|
||||
Network::Mainnet => zcash_seednodes().into_iter().map(Into::into).collect(),
|
||||
Network::Other(_) | Network::Testnet | Network::Regtest | Network::Unitest => Vec::new(),
|
||||
Network::Testnet => zcash_testnet_seednodes().into_iter().map(Into::into).collect(),
|
||||
Network::Other(_) | Network::Regtest | Network::Unitest => Vec::new(),
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -5,3 +5,9 @@ pub fn zcash_seednodes() -> Vec<&'static str> {
|
|||
"dnsseed.znodes.org:8233",
|
||||
]
|
||||
}
|
||||
|
||||
pub fn zcash_testnet_seednodes() -> Vec<&'static str> {
|
||||
vec![
|
||||
"dnsseed.testnet.z.cash:18233",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -229,10 +229,11 @@ impl<T, U, V> LocalNode<T, U, V> where T: TaskExecutor, U: Server, V: Client {
|
|||
|
||||
/// Get block template for mining
|
||||
pub fn get_block_template(&self) -> BlockTemplate {
|
||||
let max_block_size = 2_000_000;
|
||||
let max_block_size = self.consensus.max_block_size();
|
||||
let max_block_sigops = self.consensus.max_block_sigops();
|
||||
let block_assembler = BlockAssembler {
|
||||
max_block_size: max_block_size as u32,
|
||||
max_block_sigops: 20_000,
|
||||
max_block_sigops: max_block_sigops as u32,
|
||||
};
|
||||
let memory_pool = &*self.memory_pool.read();
|
||||
block_assembler.create_new_block(&self.storage, memory_pool, time::get_time().sec as u32, &self.consensus)
|
||||
|
|
|
@ -29,7 +29,7 @@ impl<'a> BlockAcceptor<'a> {
|
|||
) -> Self {
|
||||
BlockAcceptor {
|
||||
finality: BlockFinality::new(block, height, deployments, headers),
|
||||
serialized_size: BlockSerializedSize::new(block),
|
||||
serialized_size: BlockSerializedSize::new(block, consensus),
|
||||
coinbase_script: BlockCoinbaseScript::new(block, consensus, height),
|
||||
coinbase_claim: BlockCoinbaseClaim::new(block, store, height),
|
||||
sigops: BlockSigops::new(block, store, consensus),
|
||||
|
@ -82,19 +82,21 @@ impl<'a> BlockFinality<'a> {
|
|||
|
||||
pub struct BlockSerializedSize<'a> {
|
||||
block: CanonBlock<'a>,
|
||||
max_block_size: usize,
|
||||
}
|
||||
|
||||
impl<'a> BlockSerializedSize<'a> {
|
||||
fn new(block: CanonBlock<'a>) -> Self {
|
||||
fn new(block: CanonBlock<'a>, consensus: &'a ConsensusParams) -> Self {
|
||||
BlockSerializedSize {
|
||||
block: block,
|
||||
max_block_size: consensus.max_block_size(),
|
||||
}
|
||||
}
|
||||
|
||||
fn check(&self) -> Result<(), Error> {
|
||||
let size = self.block.size();
|
||||
|
||||
if size > 2_000_000 {
|
||||
if size > self.max_block_size {
|
||||
return Err(Error::Size(size));
|
||||
}
|
||||
|
||||
|
@ -107,6 +109,7 @@ pub struct BlockSigops<'a> {
|
|||
store: &'a TransactionOutputProvider,
|
||||
bip16_active: bool,
|
||||
checkdatasig_active: bool,
|
||||
max_block_sigops: usize,
|
||||
}
|
||||
|
||||
impl<'a> BlockSigops<'a> {
|
||||
|
@ -123,6 +126,7 @@ impl<'a> BlockSigops<'a> {
|
|||
store: store,
|
||||
bip16_active,
|
||||
checkdatasig_active,
|
||||
max_block_sigops: consensus.max_block_sigops(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,7 +136,7 @@ impl<'a> BlockSigops<'a> {
|
|||
.map(|tx| transaction_sigops(&tx.raw, &store, self.bip16_active, self.checkdatasig_active))
|
||||
.fold(0, |acc, tx_sigops| (acc + tx_sigops));
|
||||
|
||||
if sigops > 20_000 {
|
||||
if sigops > self.max_block_sigops {
|
||||
return Err(Error::MaximumSigops);
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ impl<'a> MemoryPoolTransactionAcceptor<'a> {
|
|||
) -> Self {
|
||||
trace!(target: "verification", "Mempool-Tx verification {}", transaction.hash.to_reversed_str());
|
||||
let transaction_index = 0;
|
||||
let max_block_sigops = 20_000;
|
||||
let max_block_sigops = consensus.max_block_sigops();
|
||||
MemoryPoolTransactionAcceptor {
|
||||
missing_inputs: TransactionMissingInputs::new(transaction, output_store, transaction_index),
|
||||
maturity: TransactionMaturity::new(transaction, meta_store, height),
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::collections::HashSet;
|
||||
use chain::IndexedBlock;
|
||||
use network::ConsensusParams;
|
||||
use sigops::transaction_sigops;
|
||||
use duplex_store::NoopStore;
|
||||
use error::{Error, TransactionError};
|
||||
|
@ -15,14 +16,14 @@ pub struct BlockVerifier<'a> {
|
|||
}
|
||||
|
||||
impl<'a> BlockVerifier<'a> {
|
||||
pub fn new(block: &'a IndexedBlock) -> Self {
|
||||
pub fn new(block: &'a IndexedBlock, consensus: &'a ConsensusParams) -> Self {
|
||||
BlockVerifier {
|
||||
empty: BlockEmpty::new(block),
|
||||
coinbase: BlockCoinbase::new(block),
|
||||
serialized_size: BlockSerializedSize::new(block, 2_000_000),
|
||||
serialized_size: BlockSerializedSize::new(block, consensus),
|
||||
extra_coinbases: BlockExtraCoinbases::new(block),
|
||||
transactions_uniqueness: BlockTransactionsUniqueness::new(block),
|
||||
sigops: BlockSigops::new(block, 20_000),
|
||||
sigops: BlockSigops::new(block, consensus),
|
||||
merkle_root: BlockMerkleRoot::new(block),
|
||||
}
|
||||
}
|
||||
|
@ -65,10 +66,10 @@ pub struct BlockSerializedSize<'a> {
|
|||
}
|
||||
|
||||
impl<'a> BlockSerializedSize<'a> {
|
||||
fn new(block: &'a IndexedBlock, max_size: usize) -> Self {
|
||||
fn new(block: &'a IndexedBlock, consensus: &'a ConsensusParams) -> Self {
|
||||
BlockSerializedSize {
|
||||
block: block,
|
||||
max_size: max_size,
|
||||
max_size: consensus.max_block_size(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,10 +153,10 @@ pub struct BlockSigops<'a> {
|
|||
}
|
||||
|
||||
impl<'a> BlockSigops<'a> {
|
||||
fn new(block: &'a IndexedBlock, max_sigops: usize) -> Self {
|
||||
fn new(block: &'a IndexedBlock, consensus: &'a ConsensusParams) -> Self {
|
||||
BlockSigops {
|
||||
block: block,
|
||||
max_sigops: max_sigops,
|
||||
max_sigops: consensus.max_block_sigops(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,10 +13,10 @@ pub struct ChainVerifier<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ChainVerifier<'a> {
|
||||
pub fn new(block: &'a IndexedBlock, consensus: &ConsensusParams, current_time: u32) -> Self {
|
||||
pub fn new(block: &'a IndexedBlock, consensus: &'a ConsensusParams, current_time: u32) -> Self {
|
||||
trace!(target: "verification", "Block pre-verification {}", block.hash().to_reversed_str());
|
||||
ChainVerifier {
|
||||
block: BlockVerifier::new(block),
|
||||
block: BlockVerifier::new(block, consensus),
|
||||
header: HeaderVerifier::new(&block.header, consensus, current_time),
|
||||
transactions: block.transactions.iter().map(TransactionVerifier::new).collect(),
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ impl<'a> MemoryPoolTransactionVerifier<'a> {
|
|||
null_non_coinbase: TransactionNullNonCoinbase::new(transaction),
|
||||
is_coinbase: TransactionMemoryPoolCoinbase::new(transaction),
|
||||
size: TransactionSize::new(transaction, consensus),
|
||||
sigops: TransactionSigops::new(transaction, 20_000),
|
||||
sigops: TransactionSigops::new(transaction, consensus.max_block_sigops()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue