Take the 'Sum' out of 'Sumtree' (#702)
* beginning to remove sum * continuing to remove sumtree sums * finished removing sums from pmmr core * renamed sumtree files, and completed changes+test updates in core and store * updating grin/chain to include removelogs * integration of flatfile structure, changes to chain/sumtree to start using them * tests on chain, core and store passing * cleaning up api and tests * formatting * flatfiles stored as part of PMMR backend instead * all compiling and tests running * documentation * added remove + pruning to flatfiles * remove unneeded enum * adding sumtree root struct
This commit is contained in:
+16
-16
@@ -206,13 +206,13 @@ impl Handler for UtxoHandler {
|
||||
}
|
||||
|
||||
// Sum tree handler. Retrieve the roots:
|
||||
// GET /v1/sumtrees/roots
|
||||
// GET /v1/pmmrtrees/roots
|
||||
//
|
||||
// Last inserted nodes::
|
||||
// GET /v1/sumtrees/lastutxos (gets last 10)
|
||||
// GET /v1/sumtrees/lastutxos?n=5
|
||||
// GET /v1/sumtrees/lastrangeproofs
|
||||
// GET /v1/sumtrees/lastkernels
|
||||
// GET /v1/pmmrtrees/lastutxos (gets last 10)
|
||||
// GET /v1/pmmrtrees/lastutxos?n=5
|
||||
// GET /v1/pmmrtrees/lastrangeproofs
|
||||
// GET /v1/pmmrtrees/lastkernels
|
||||
struct SumTreeHandler {
|
||||
chain: Weak<chain::Chain>,
|
||||
}
|
||||
@@ -224,18 +224,18 @@ impl SumTreeHandler {
|
||||
}
|
||||
|
||||
// gets last n utxos inserted in to the tree
|
||||
fn get_last_n_utxo(&self, distance: u64) -> Vec<SumTreeNode> {
|
||||
SumTreeNode::get_last_n_utxo(w(&self.chain), distance)
|
||||
fn get_last_n_utxo(&self, distance: u64) -> Vec<PmmrTreeNode> {
|
||||
PmmrTreeNode::get_last_n_utxo(w(&self.chain), distance)
|
||||
}
|
||||
|
||||
// gets last n utxos inserted in to the tree
|
||||
fn get_last_n_rangeproof(&self, distance: u64) -> Vec<SumTreeNode> {
|
||||
SumTreeNode::get_last_n_rangeproof(w(&self.chain), distance)
|
||||
fn get_last_n_rangeproof(&self, distance: u64) -> Vec<PmmrTreeNode> {
|
||||
PmmrTreeNode::get_last_n_rangeproof(w(&self.chain), distance)
|
||||
}
|
||||
|
||||
// gets last n utxos inserted in to the tree
|
||||
fn get_last_n_kernel(&self, distance: u64) -> Vec<SumTreeNode> {
|
||||
SumTreeNode::get_last_n_kernel(w(&self.chain), distance)
|
||||
fn get_last_n_kernel(&self, distance: u64) -> Vec<PmmrTreeNode> {
|
||||
PmmrTreeNode::get_last_n_kernel(w(&self.chain), distance)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,10 +620,10 @@ pub fn start_rest_apis<T>(
|
||||
"get chain".to_string(),
|
||||
"get chain/utxos".to_string(),
|
||||
"get status".to_string(),
|
||||
"get sumtrees/roots".to_string(),
|
||||
"get sumtrees/lastutxos?n=10".to_string(),
|
||||
"get sumtrees/lastrangeproofs".to_string(),
|
||||
"get sumtrees/lastkernels".to_string(),
|
||||
"get pmmrtrees/roots".to_string(),
|
||||
"get pmmrtrees/lastutxos?n=10".to_string(),
|
||||
"get pmmrtrees/lastrangeproofs".to_string(),
|
||||
"get pmmrtrees/lastkernels".to_string(),
|
||||
"get pool".to_string(),
|
||||
"post pool/push".to_string(),
|
||||
"post peers/a.b.c.d:p/ban".to_string(),
|
||||
@@ -641,7 +641,7 @@ pub fn start_rest_apis<T>(
|
||||
chain_tip: get "/chain" => chain_tip_handler,
|
||||
chain_utxos: get "/chain/utxos/*" => utxo_handler,
|
||||
status: get "/status" => status_handler,
|
||||
sumtree_roots: get "/sumtrees/*" => sumtree_handler,
|
||||
sumtree_roots: get "/pmmrtrees/*" => sumtree_handler,
|
||||
pool_info: get "/pool" => pool_info_handler,
|
||||
pool_push: post "/pool/push" => pool_push_handler,
|
||||
peers_all: get "/peers/all" => peers_all_handler,
|
||||
|
||||
+14
-23
@@ -16,7 +16,6 @@ use std::sync::Arc;
|
||||
|
||||
use core::{core, ser};
|
||||
use core::core::hash::Hashed;
|
||||
use core::core::SumCommit;
|
||||
use core::core::SwitchCommitHash;
|
||||
use chain;
|
||||
use p2p;
|
||||
@@ -89,8 +88,6 @@ impl Status {
|
||||
pub struct SumTrees {
|
||||
/// UTXO Root Hash
|
||||
pub utxo_root_hash: String,
|
||||
// UTXO Root Sum
|
||||
pub utxo_root_sum: String,
|
||||
// Rangeproof root hash
|
||||
pub range_proof_root_hash: String,
|
||||
// Kernel set root hash
|
||||
@@ -101,10 +98,9 @@ impl SumTrees {
|
||||
pub fn from_head(head: Arc<chain::Chain>) -> SumTrees {
|
||||
let roots = head.get_sumtree_roots();
|
||||
SumTrees {
|
||||
utxo_root_hash: roots.0.hash.to_hex(),
|
||||
utxo_root_sum: roots.0.sum.to_hex(),
|
||||
range_proof_root_hash: roots.1.hash.to_hex(),
|
||||
kernel_root_hash: roots.2.hash.to_hex(),
|
||||
utxo_root_hash: roots.0.to_hex(),
|
||||
range_proof_root_hash: roots.1.to_hex(),
|
||||
kernel_root_hash: roots.2.to_hex(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,45 +108,40 @@ impl SumTrees {
|
||||
/// Wrapper around a list of sumtree nodes, so it can be
|
||||
/// presented properly via json
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct SumTreeNode {
|
||||
pub struct PmmrTreeNode {
|
||||
// The hash
|
||||
pub hash: String,
|
||||
// SumCommit (features|commitment), optional (only for utxos)
|
||||
pub sum: Option<SumCommit>,
|
||||
}
|
||||
|
||||
impl SumTreeNode {
|
||||
pub fn get_last_n_utxo(chain: Arc<chain::Chain>, distance: u64) -> Vec<SumTreeNode> {
|
||||
impl PmmrTreeNode {
|
||||
pub fn get_last_n_utxo(chain: Arc<chain::Chain>, distance: u64) -> Vec<PmmrTreeNode> {
|
||||
let mut return_vec = Vec::new();
|
||||
let last_n = chain.get_last_n_utxo(distance);
|
||||
for x in last_n {
|
||||
return_vec.push(SumTreeNode {
|
||||
hash: util::to_hex(x.hash.to_vec()),
|
||||
sum: Some(x.sum),
|
||||
return_vec.push(PmmrTreeNode {
|
||||
hash: util::to_hex(x.0.to_vec()),
|
||||
});
|
||||
}
|
||||
return_vec
|
||||
}
|
||||
|
||||
pub fn get_last_n_rangeproof(head: Arc<chain::Chain>, distance: u64) -> Vec<SumTreeNode> {
|
||||
pub fn get_last_n_rangeproof(head: Arc<chain::Chain>, distance: u64) -> Vec<PmmrTreeNode> {
|
||||
let mut return_vec = Vec::new();
|
||||
let last_n = head.get_last_n_rangeproof(distance);
|
||||
for elem in last_n {
|
||||
return_vec.push(SumTreeNode {
|
||||
hash: util::to_hex(elem.hash.to_vec()),
|
||||
sum: None,
|
||||
return_vec.push(PmmrTreeNode {
|
||||
hash: util::to_hex(elem.0.to_vec()),
|
||||
});
|
||||
}
|
||||
return_vec
|
||||
}
|
||||
|
||||
pub fn get_last_n_kernel(head: Arc<chain::Chain>, distance: u64) -> Vec<SumTreeNode> {
|
||||
pub fn get_last_n_kernel(head: Arc<chain::Chain>, distance: u64) -> Vec<PmmrTreeNode> {
|
||||
let mut return_vec = Vec::new();
|
||||
let last_n = head.get_last_n_kernel(distance);
|
||||
for elem in last_n {
|
||||
return_vec.push(SumTreeNode {
|
||||
hash: util::to_hex(elem.hash.to_vec()),
|
||||
sum: None,
|
||||
return_vec.push(PmmrTreeNode {
|
||||
hash: util::to_hex(elem.0.to_vec()),
|
||||
});
|
||||
}
|
||||
return_vec
|
||||
|
||||
Reference in New Issue
Block a user