Skip to content

Commit

Permalink
fee and lock_height maintained in kernel features variants (#2859)
Browse files Browse the repository at this point in the history
* fee and lock_height now maintained in kernel features enum variants

* sum fees via explicit enum variants

* cleanup semantics around with_fee and with_lock_height for tx builders

* document the kernel feature variants

* serialize kernel features correctly for api json

* cleanup

* commit

* bump to unstick azure
  • Loading branch information
antiochp authored Aug 19, 2019
1 parent d220410 commit 6036b67
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 142 deletions.
13 changes: 10 additions & 3 deletions api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::sync::Arc;
use crate::chain;
use crate::core::core::hash::Hashed;
use crate::core::core::merkle_proof::MerkleProof;
use crate::core::core::KernelFeatures;
use crate::core::{core, ser};
use crate::p2p;
use crate::util;
Expand Down Expand Up @@ -488,10 +489,16 @@ pub struct TxKernelPrintable {

impl TxKernelPrintable {
pub fn from_txkernel(k: &core::TxKernel) -> TxKernelPrintable {
let features = k.features.as_string();
let (fee, lock_height) = match k.features {
KernelFeatures::Plain { fee } => (fee, 0),
KernelFeatures::Coinbase => (0, 0),
KernelFeatures::HeightLocked { fee, lock_height } => (fee, lock_height),
};
TxKernelPrintable {
features: format!("{:?}", k.features),
fee: k.fee,
lock_height: k.lock_height,
features,
fee,
lock_height,
excess: util::to_hex(k.excess.0.to_vec()),
excess_sig: util::to_hex(k.excess_sig.to_raw_data().to_vec()),
}
Expand Down
15 changes: 8 additions & 7 deletions core/src/core/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ use crate::core::compact_block::{CompactBlock, CompactBlockBody};
use crate::core::hash::{DefaultHashable, Hash, Hashed, ZERO_HASH};
use crate::core::verifier_cache::VerifierCache;
use crate::core::{
transaction, Commitment, Input, Output, Transaction, TransactionBody, TxKernel, Weighting,
transaction, Commitment, Input, KernelFeatures, Output, Transaction, TransactionBody, TxKernel,
Weighting,
};

use crate::global;
use crate::keychain::{self, BlindingFactor};
use crate::pow::{Difficulty, Proof, ProofOfWork};
Expand Down Expand Up @@ -643,10 +645,7 @@ impl Block {

/// Sum of all fees (inputs less outputs) in the block
pub fn total_fees(&self) -> u64 {
self.body
.kernels
.iter()
.fold(0, |acc, ref x| acc.saturating_add(x.fee))
self.body.fee()
}

/// Matches any output with a potential spending input, eliminating them
Expand Down Expand Up @@ -762,8 +761,10 @@ impl Block {
for k in &self.body.kernels {
// check we have no kernels with lock_heights greater than current height
// no tx can be included in a block earlier than its lock_height
if k.lock_height > self.header.height {
return Err(Error::KernelLockHeight(k.lock_height));
if let KernelFeatures::HeightLocked { lock_height, .. } = k.features {
if lock_height > self.header.height {
return Err(Error::KernelLockHeight(lock_height));
}
}
}
Ok(())
Expand Down
1 change: 1 addition & 0 deletions core/src/core/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,5 @@ impl<D: DefaultHashable, E: DefaultHashable, F: DefaultHashable> DefaultHashable
/// Implement Hashed trait for external types here
impl DefaultHashable for crate::util::secp::pedersen::RangeProof {}
impl DefaultHashable for Vec<u8> {}
impl DefaultHashable for u8 {}
impl DefaultHashable for u64 {}
Loading

0 comments on commit 6036b67

Please sign in to comment.