applied all requested changes from review
This commit is contained in:
parent
08ed2f3145
commit
08ab2eac76
|
@ -124,7 +124,7 @@ impl Block {
|
|||
network: &Network,
|
||||
) -> Result<(), error::BlockError> {
|
||||
let block_nu =
|
||||
NetworkUpgrade::current(&network, self.coinbase_height().expect("a valid height"));
|
||||
NetworkUpgrade::current(network, self.coinbase_height().expect("a valid height"));
|
||||
|
||||
if self
|
||||
.transactions
|
||||
|
|
|
@ -348,13 +348,14 @@ impl Arbitrary for Block {
|
|||
type Parameters = LedgerState;
|
||||
|
||||
fn arbitrary_with(ledger_state: Self::Parameters) -> Self::Strategy {
|
||||
let ledger_state_clone = ledger_state.clone();
|
||||
let transactions_strategy =
|
||||
let transactions_strategy = {
|
||||
let ledger_state = ledger_state.clone();
|
||||
// Generate a random number transactions. A coinbase tx is always generated, so if
|
||||
// `transaction_count` is zero, the block will contain only the coinbase tx.
|
||||
(0..MAX_ARBITRARY_ITEMS).prop_flat_map(move |transaction_count| {
|
||||
Transaction::vec_strategy(ledger_state_clone.clone(), transaction_count)
|
||||
});
|
||||
Transaction::vec_strategy(ledger_state.clone(), transaction_count)
|
||||
})
|
||||
};
|
||||
|
||||
// TODO: if needed, fixup:
|
||||
// - history and authorizing data commitments
|
||||
|
|
|
@ -109,13 +109,13 @@ impl Commitment {
|
|||
use Commitment::*;
|
||||
use CommitmentError::*;
|
||||
|
||||
match NetworkUpgrade::current(&network, height) {
|
||||
match NetworkUpgrade::current(network, height) {
|
||||
Genesis | BeforeOverwinter | Overwinter => Ok(PreSaplingReserved(bytes)),
|
||||
Sapling | Blossom => match sapling::tree::Root::try_from(bytes) {
|
||||
Ok(root) => Ok(FinalSaplingRoot(root)),
|
||||
_ => Err(InvalidSapingRootBytes),
|
||||
},
|
||||
Heartwood if Some(height) == Heartwood.activation_height(&network) => {
|
||||
Heartwood if Some(height) == Heartwood.activation_height(network) => {
|
||||
if bytes == CHAIN_HISTORY_ACTIVATION_RESERVED {
|
||||
Ok(ChainHistoryActivationReserved)
|
||||
} else {
|
||||
|
|
|
@ -83,7 +83,7 @@ impl NonEmptyHistoryTree {
|
|||
peaks: BTreeMap<u32, Entry>,
|
||||
current_height: Height,
|
||||
) -> Result<Self, HistoryTreeError> {
|
||||
let network_upgrade = NetworkUpgrade::current(&network, current_height);
|
||||
let network_upgrade = NetworkUpgrade::current(network, current_height);
|
||||
let inner = match network_upgrade {
|
||||
NetworkUpgrade::Genesis
|
||||
| NetworkUpgrade::BeforeOverwinter
|
||||
|
@ -138,7 +138,7 @@ impl NonEmptyHistoryTree {
|
|||
let height = block
|
||||
.coinbase_height()
|
||||
.expect("block must have coinbase height during contextual verification");
|
||||
let network_upgrade = NetworkUpgrade::current(&network, height);
|
||||
let network_upgrade = NetworkUpgrade::current(network, height);
|
||||
let (tree, entry) = match network_upgrade {
|
||||
NetworkUpgrade::Genesis
|
||||
| NetworkUpgrade::BeforeOverwinter
|
||||
|
@ -239,8 +239,8 @@ impl NonEmptyHistoryTree {
|
|||
|
||||
/// Extend the history tree with the given blocks.
|
||||
pub fn try_extend<
|
||||
'b,
|
||||
T: IntoIterator<Item = (Arc<Block>, &'b sapling::tree::Root, &'b orchard::tree::Root)>,
|
||||
'a,
|
||||
T: IntoIterator<Item = (Arc<Block>, &'a sapling::tree::Root, &'a orchard::tree::Root)>,
|
||||
>(
|
||||
&mut self,
|
||||
iter: T,
|
||||
|
@ -392,7 +392,7 @@ impl Clone for NonEmptyHistoryTree {
|
|||
),
|
||||
InnerHistoryTree::OrchardOnward(_) => InnerHistoryTree::OrchardOnward(
|
||||
Tree::<OrchardOnward>::new_from_cache(
|
||||
&self.network.clone(),
|
||||
&self.network,
|
||||
self.network_upgrade,
|
||||
self.size,
|
||||
&self.peaks,
|
||||
|
@ -414,15 +414,9 @@ impl Clone for NonEmptyHistoryTree {
|
|||
|
||||
/// A History Tree that keeps track of its own creation in the Heartwood
|
||||
/// activation block, being empty beforehand.
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct HistoryTree(Option<NonEmptyHistoryTree>);
|
||||
|
||||
impl Clone for HistoryTree {
|
||||
fn clone(&self) -> Self {
|
||||
HistoryTree(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl HistoryTree {
|
||||
/// Create a HistoryTree from a block.
|
||||
///
|
||||
|
@ -435,7 +429,7 @@ impl HistoryTree {
|
|||
orchard_root: &orchard::tree::Root,
|
||||
) -> Result<Self, HistoryTreeError> {
|
||||
let heartwood_height = NetworkUpgrade::Heartwood
|
||||
.activation_height(&network)
|
||||
.activation_height(network)
|
||||
.expect("Heartwood height is known");
|
||||
match block
|
||||
.coinbase_height()
|
||||
|
@ -444,8 +438,7 @@ impl HistoryTree {
|
|||
{
|
||||
std::cmp::Ordering::Less => Ok(HistoryTree(None)),
|
||||
_ => Ok(
|
||||
NonEmptyHistoryTree::from_block(&network, block, sapling_root, orchard_root)?
|
||||
.into(),
|
||||
NonEmptyHistoryTree::from_block(network, block, sapling_root, orchard_root)?.into(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
@ -463,7 +456,7 @@ impl HistoryTree {
|
|||
orchard_root: &orchard::tree::Root,
|
||||
) -> Result<(), HistoryTreeError> {
|
||||
let heartwood_height = NetworkUpgrade::Heartwood
|
||||
.activation_height(&network)
|
||||
.activation_height(network)
|
||||
.expect("Heartwood height is known");
|
||||
match block
|
||||
.coinbase_height()
|
||||
|
|
Loading…
Reference in New Issue