Remove Sumtree References and disambiguate some naming (#747)

* start of renamathon

* api renaming

* Rename UTXO-Output to lessen ambiguity

* compile warning

* compile error

* readme fix

* remove file commit in error
This commit is contained in:
Yeastplume
2018-03-05 19:33:44 +00:00
committed by GitHub
parent 884906421c
commit 1143d84238
89 changed files with 591 additions and 591 deletions
+22 -22
View File
@@ -1,10 +1,10 @@
// This file is (hopefully) temporary.
//
// It contains a trait based on (but not exactly equal to) the trait defined
// for the blockchain UTXO set, discussed at
// for the blockchain Output set, discussed at
// https://github.com/ignopeverell/grin/issues/29, and a dummy implementation
// of said trait.
// Notably, UtxoDiff has been left off, and the question of how to handle
// Notably, OutputDiff has been left off, and the question of how to handle
// abstract return types has been deferred.
use std::collections::HashMap;
@@ -18,15 +18,15 @@ use core::core::hash::Hashed;
use types::{BlockChain, PoolError};
use util::secp::pedersen::Commitment;
/// A DummyUtxoSet for mocking up the chain
pub struct DummyUtxoSet {
/// A DummyOutputSet for mocking up the chain
pub struct DummyOutputSet {
outputs: HashMap<Commitment, transaction::Output>,
}
#[allow(dead_code)]
impl DummyUtxoSet {
pub fn empty() -> DummyUtxoSet {
DummyUtxoSet {
impl DummyOutputSet {
pub fn empty() -> DummyOutputSet {
DummyOutputSet {
outputs: HashMap::new(),
}
}
@@ -35,7 +35,7 @@ impl DummyUtxoSet {
hash::ZERO_HASH
}
pub fn apply(&self, b: &block::Block) -> DummyUtxoSet {
pub fn apply(&self, b: &block::Block) -> DummyOutputSet {
let mut new_outputs = self.outputs.clone();
for input in &b.inputs {
@@ -44,7 +44,7 @@ impl DummyUtxoSet {
for output in &b.outputs {
new_outputs.insert(output.commitment(), output.clone());
}
DummyUtxoSet {
DummyOutputSet {
outputs: new_outputs,
}
}
@@ -58,8 +58,8 @@ impl DummyUtxoSet {
}
}
pub fn rewind(&self, _: &block::Block) -> DummyUtxoSet {
DummyUtxoSet {
pub fn rewind(&self, _: &block::Block) -> DummyOutputSet {
DummyOutputSet {
outputs: HashMap::new(),
}
}
@@ -68,17 +68,17 @@ impl DummyUtxoSet {
self.outputs.get(output_ref)
}
fn clone(&self) -> DummyUtxoSet {
DummyUtxoSet {
fn clone(&self) -> DummyOutputSet {
DummyOutputSet {
outputs: self.outputs.clone(),
}
}
// only for testing: add an output to the map
pub fn with_output(&self, output: transaction::Output) -> DummyUtxoSet {
pub fn with_output(&self, output: transaction::Output) -> DummyOutputSet {
let mut new_outputs = self.outputs.clone();
new_outputs.insert(output.commitment(), output);
DummyUtxoSet {
DummyOutputSet {
outputs: new_outputs,
}
}
@@ -88,7 +88,7 @@ impl DummyUtxoSet {
/// need
#[allow(dead_code)]
pub struct DummyChainImpl {
utxo: RwLock<DummyUtxoSet>,
output: RwLock<DummyOutputSet>,
block_headers: RwLock<Vec<block::BlockHeader>>,
}
@@ -96,7 +96,7 @@ pub struct DummyChainImpl {
impl DummyChainImpl {
pub fn new() -> DummyChainImpl {
DummyChainImpl {
utxo: RwLock::new(DummyUtxoSet {
output: RwLock::new(DummyOutputSet {
outputs: HashMap::new(),
}),
block_headers: RwLock::new(vec![]),
@@ -106,7 +106,7 @@ impl DummyChainImpl {
impl BlockChain for DummyChainImpl {
fn is_unspent(&self, output_ref: &OutputIdentifier) -> Result<hash::Hash, PoolError> {
match self.utxo.read().unwrap().get_output(&output_ref.commit) {
match self.output.read().unwrap().get_output(&output_ref.commit) {
Some(_) => Ok(hash::Hash::zero()),
None => Err(PoolError::GenericPoolError),
}
@@ -137,12 +137,12 @@ impl BlockChain for DummyChainImpl {
}
impl DummyChain for DummyChainImpl {
fn update_utxo_set(&mut self, new_utxo: DummyUtxoSet) {
self.utxo = RwLock::new(new_utxo);
fn update_output_set(&mut self, new_output: DummyOutputSet) {
self.output = RwLock::new(new_output);
}
fn apply_block(&self, b: &block::Block) {
self.utxo.write().unwrap().with_block(b);
self.output.write().unwrap().with_block(b);
self.store_head_header(&b.header)
}
@@ -153,7 +153,7 @@ impl DummyChain for DummyChainImpl {
}
pub trait DummyChain: BlockChain {
fn update_utxo_set(&mut self, new_utxo: DummyUtxoSet);
fn update_output_set(&mut self, new_output: DummyOutputSet);
fn apply_block(&self, b: &block::Block);
fn store_head_header(&self, block_header: &block::BlockHeader);
}
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017 The Grin Developers
// 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.
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017 The Grin Developers
// 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.
+20 -20
View File
@@ -1,4 +1,4 @@
// Copyright 2017 The Grin Developers
// 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.
@@ -100,7 +100,7 @@ where
}
/// Searches for an output, designated by its commitment, from the current
/// best UTXO view, presented by taking the best blockchain UTXO set (as
/// best Output view, presented by taking the best blockchain Output set (as
/// determined by the blockchain component) and rectifying pool spent and
/// unspents.
/// Detects double spends and unknown references from the pool and
@@ -456,7 +456,7 @@ where
) -> Result<Vec<Box<transaction::Transaction>>, PoolError> {
// If this pool has been kept in sync correctly, serializing all
// updates, then the inputs must consume only members of the blockchain
// utxo set.
// output set.
// If the block has been resolved properly and reduced fully to its
// canonical form, no inputs may consume outputs generated by previous
// transactions in the block; they would be cut-through. TODO: If this
@@ -467,11 +467,11 @@ where
// consumes the same blockchain output.
// If one exists, we mark the transaction and then examine its
// children. Recursively, we mark each child until a child is
// fully satisfied by outputs in the updated utxo view (after
// fully satisfied by outputs in the updated output view (after
// reconciliation of the block), or there are no more children.
//
// Additionally, to protect our invariant dictating no duplicate
// outputs, each output generated by the new utxo set is checked
// outputs, each output generated by the new output set is checked
// against outputs generated by the pool and the corresponding
// transactions are also marked.
//
@@ -525,7 +525,7 @@ where
/// The transaction designated by conflicting_tx is immediately marked.
/// Each output of this transaction is then examined; if a transaction in
/// the pool spends this output and the output is not replaced by an
/// identical output included in the updated UTXO set, the child is marked
/// identical output included in the updated Output set, the child is marked
/// as well and the process continues recursively.
///
/// Marked transactions are added to the mutable marked_txs HashMap which
@@ -630,7 +630,7 @@ mod tests {
use super::*;
use core::core::build;
use core::global;
use blockchain::{DummyChain, DummyChainImpl, DummyUtxoSet};
use blockchain::{DummyChain, DummyChainImpl, DummyOutputSet};
use util::secp;
use keychain::Keychain;
use std::sync::{Arc, RwLock};
@@ -669,7 +669,7 @@ mod tests {
let parent_transaction = test_transaction(vec![5, 6, 7], vec![11, 3]);
// We want this transaction to be rooted in the blockchain.
let new_utxo = DummyUtxoSet::empty()
let new_output = DummyOutputSet::empty()
.with_output(test_output(5))
.with_output(test_output(6))
.with_output(test_output(7))
@@ -678,7 +678,7 @@ mod tests {
// Prepare a second transaction, connected to the first.
let child_transaction = test_transaction(vec![11, 3], vec![12]);
dummy_chain.update_utxo_set(new_utxo);
dummy_chain.update_output_set(new_output);
// To mirror how this construction is intended to be used, the pool
// is placed inside a RwLock.
@@ -727,12 +727,12 @@ mod tests {
};
dummy_chain.store_head_header(&head_header);
let new_utxo = DummyUtxoSet::empty()
let new_output = DummyOutputSet::empty()
.with_output(test_output(5))
.with_output(test_output(6))
.with_output(test_output(7));
dummy_chain.update_utxo_set(new_utxo);
dummy_chain.update_output_set(new_output);
let pool = RwLock::new(test_setup(&Arc::new(dummy_chain)));
{
@@ -838,7 +838,7 @@ mod tests {
assert_eq!(lock_height, 4);
let coinbase_output = test_coinbase_output(15);
dummy_chain.update_utxo_set(DummyUtxoSet::empty().with_output(coinbase_output));
dummy_chain.update_output_set(DummyOutputSet::empty().with_output(coinbase_output));
let chain_ref = Arc::new(dummy_chain);
let pool = RwLock::new(test_setup(&chain_ref));
@@ -895,15 +895,15 @@ mod tests {
};
dummy_chain.store_head_header(&head_header);
// single UTXO
let new_utxo = DummyUtxoSet::empty().with_output(test_output(100));
// single Output
let new_output = DummyOutputSet::empty().with_output(test_output(100));
dummy_chain.update_utxo_set(new_utxo);
dummy_chain.update_output_set(new_output);
let chain_ref = Arc::new(dummy_chain);
let pool = RwLock::new(test_setup(&chain_ref));
// now create two txs
// tx1 spends the UTXO
// tx1 spends the Output
// tx2 spends output from tx1
let tx1 = test_transaction(vec![100], vec![90]);
let tx2 = test_transaction(vec![90], vec![80]);
@@ -973,13 +973,13 @@ mod tests {
};
dummy_chain.store_head_header(&head_header);
let new_utxo = DummyUtxoSet::empty()
let new_output = DummyOutputSet::empty()
.with_output(test_output(10))
.with_output(test_output(20))
.with_output(test_output(30))
.with_output(test_output(40));
dummy_chain.update_utxo_set(new_utxo);
dummy_chain.update_output_set(new_output);
let chain_ref = Arc::new(dummy_chain);
@@ -1127,13 +1127,13 @@ mod tests {
};
dummy_chain.store_head_header(&head_header);
let new_utxo = DummyUtxoSet::empty()
let new_output = DummyOutputSet::empty()
.with_output(test_output(10))
.with_output(test_output(20))
.with_output(test_output(30))
.with_output(test_output(40));
dummy_chain.update_utxo_set(new_utxo);
dummy_chain.update_output_set(new_output);
let chain_ref = Arc::new(dummy_chain);
+3 -3
View File
@@ -1,4 +1,4 @@
// Copyright 2017 The Grin Developers
// 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.
@@ -182,7 +182,7 @@ impl PoolAdapter for NoopAdapter {
/// not respected.
/// Spending references (input -> output) exist in two structures: internal
/// graph references are contained in the pool edge sets, while references
/// sourced from the blockchain's UTXO set are contained in the
/// sourced from the blockchain's Output set are contained in the
/// blockchain_connections set.
/// Spent by references (output-> input) exist in two structures: pool-pool
/// connections are in the pool edge set, while unspent (dangling) references
@@ -195,7 +195,7 @@ pub struct Pool {
// output's hash.
available_outputs: HashMap<Commitment, graph::Edge>,
// Consumed blockchain utxo's are kept in a separate map.
// Consumed blockchain output's are kept in a separate map.
consumed_blockchain_outputs: HashMap<Commitment, graph::Edge>,
}