height (header version) specific output PMMR root rules (#3147)

* height (header version) specific output PMMR root rules

* cleanup

* cleanup based on PR feedback

* address feedback
This commit is contained in:
Antioch Peverell
2019-12-05 11:55:10 +00:00
committed by GitHub
parent 3a333ae00f
commit 0b21ee607a
7 changed files with 74 additions and 38 deletions
+4 -1
View File
@@ -47,7 +47,10 @@ pub struct TxHashSetHandler {
impl TxHashSetHandler {
// gets roots
fn get_roots(&self) -> Result<TxHashSet, Error> {
Ok(TxHashSet::from_head(w(&self.chain)?))
let res = TxHashSet::from_head(w(&self.chain)?).context(ErrorKind::Internal(
"failed to read roots from txhashset".to_owned(),
))?;
Ok(res)
}
// gets last n outputs inserted in to the tree
+10 -7
View File
@@ -116,13 +116,16 @@ pub struct TxHashSet {
}
impl TxHashSet {
pub fn from_head(head: Arc<chain::Chain>) -> TxHashSet {
let roots = head.get_txhashset_roots();
TxHashSet {
output_root_hash: roots.output_root().to_hex(),
range_proof_root_hash: roots.rproof_root.to_hex(),
kernel_root_hash: roots.kernel_root.to_hex(),
}
/// A TxHashSet in the context of the api is simply the collection of PMMR roots.
/// We can obtain these in a lightweight way by reading them from the head of the chain.
/// We will have validated the roots on this header against the roots of the txhashset.
pub fn from_head(chain: Arc<chain::Chain>) -> Result<TxHashSet, chain::Error> {
let header = chain.head_header()?;
Ok(TxHashSet {
output_root_hash: header.output_root.to_hex(),
range_proof_root_hash: header.range_proof_root.to_hex(),
kernel_root_hash: header.kernel_root.to_hex(),
})
}
}