mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-08 12:21:09 +03:00
Cleaned up total fees from block header. Unnecessary now.
This commit is contained in:
parent
4e9aad639e
commit
6e2a232ca3
6 changed files with 23 additions and 34 deletions
|
@ -36,7 +36,6 @@ pub struct BlockHeader {
|
||||||
pub td: u64, // total difficulty up to this block
|
pub td: u64, // total difficulty up to this block
|
||||||
pub utxo_merkle: Hash,
|
pub utxo_merkle: Hash,
|
||||||
pub tx_merkle: Hash,
|
pub tx_merkle: Hash,
|
||||||
pub total_fees: u64,
|
|
||||||
pub nonce: u64,
|
pub nonce: u64,
|
||||||
pub pow: Proof,
|
pub pow: Proof,
|
||||||
}
|
}
|
||||||
|
@ -50,7 +49,6 @@ impl Default for BlockHeader {
|
||||||
td: 0,
|
td: 0,
|
||||||
utxo_merkle: ZERO_HASH,
|
utxo_merkle: ZERO_HASH,
|
||||||
tx_merkle: ZERO_HASH,
|
tx_merkle: ZERO_HASH,
|
||||||
total_fees: 0,
|
|
||||||
nonce: 0,
|
nonce: 0,
|
||||||
pow: Proof::zero(),
|
pow: Proof::zero(),
|
||||||
}
|
}
|
||||||
|
@ -66,8 +64,7 @@ impl Writeable for BlockHeader {
|
||||||
[write_fixed_bytes, &self.previous],
|
[write_fixed_bytes, &self.previous],
|
||||||
[write_i64, self.timestamp.to_timespec().sec],
|
[write_i64, self.timestamp.to_timespec().sec],
|
||||||
[write_fixed_bytes, &self.utxo_merkle],
|
[write_fixed_bytes, &self.utxo_merkle],
|
||||||
[write_fixed_bytes, &self.tx_merkle],
|
[write_fixed_bytes, &self.tx_merkle]);
|
||||||
[write_u64, self.total_fees]);
|
|
||||||
// make sure to not introduce any variable length data before the nonce to
|
// make sure to not introduce any variable length data before the nonce to
|
||||||
// avoid complicating PoW
|
// avoid complicating PoW
|
||||||
try!(writer.write_u64(self.nonce));
|
try!(writer.write_u64(self.nonce));
|
||||||
|
@ -118,14 +115,12 @@ impl Writeable for Block {
|
||||||
/// from a binary stream.
|
/// from a binary stream.
|
||||||
impl Readable<Block> for Block {
|
impl Readable<Block> for Block {
|
||||||
fn read(reader: &mut Reader) -> Result<Block, ser::Error> {
|
fn read(reader: &mut Reader) -> Result<Block, ser::Error> {
|
||||||
let (height, previous, timestamp, utxo_merkle, tx_merkle, total_fees, nonce) =
|
let (height, previous, timestamp, utxo_merkle, tx_merkle, nonce) = ser_multiread!(reader,
|
||||||
ser_multiread!(reader,
|
|
||||||
read_u64,
|
read_u64,
|
||||||
read_32_bytes,
|
read_32_bytes,
|
||||||
read_i64,
|
read_i64,
|
||||||
read_32_bytes,
|
read_32_bytes,
|
||||||
read_32_bytes,
|
read_32_bytes,
|
||||||
read_u64,
|
|
||||||
read_u64);
|
read_u64);
|
||||||
|
|
||||||
// cuckoo cycle of 42 nodes
|
// cuckoo cycle of 42 nodes
|
||||||
|
@ -157,7 +152,6 @@ impl Readable<Block> for Block {
|
||||||
td: td,
|
td: td,
|
||||||
utxo_merkle: Hash::from_vec(utxo_merkle),
|
utxo_merkle: Hash::from_vec(utxo_merkle),
|
||||||
tx_merkle: Hash::from_vec(tx_merkle),
|
tx_merkle: Hash::from_vec(tx_merkle),
|
||||||
total_fees: total_fees,
|
|
||||||
pow: Proof(pow),
|
pow: Proof(pow),
|
||||||
nonce: nonce,
|
nonce: nonce,
|
||||||
},
|
},
|
||||||
|
@ -179,7 +173,7 @@ impl Committed for Block {
|
||||||
&self.outputs
|
&self.outputs
|
||||||
}
|
}
|
||||||
fn overage(&self) -> i64 {
|
fn overage(&self) -> i64 {
|
||||||
(REWARD as i64) - (self.header.total_fees as i64)
|
(REWARD as i64) - (self.total_fees() as i64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,12 +229,10 @@ impl Block {
|
||||||
outputs.sort_by_key(|out| out.hash());
|
outputs.sort_by_key(|out| out.hash());
|
||||||
|
|
||||||
// calculate the overall Merkle tree and fees
|
// calculate the overall Merkle tree and fees
|
||||||
let fees = txs.iter().map(|tx| tx.fee).sum();
|
|
||||||
|
|
||||||
Ok(Block {
|
Ok(Block {
|
||||||
header: BlockHeader {
|
header: BlockHeader {
|
||||||
height: prev.height + 1,
|
height: prev.height + 1,
|
||||||
total_fees: fees,
|
|
||||||
timestamp: time::now(),
|
timestamp: time::now(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
@ -255,6 +247,10 @@ impl Block {
|
||||||
self.header.hash()
|
self.header.hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn total_fees(&self) -> u64 {
|
||||||
|
self.proofs.iter().map(|p| p.fee).sum()
|
||||||
|
}
|
||||||
|
|
||||||
/// Matches any output with a potential spending input, eliminating them
|
/// Matches any output with a potential spending input, eliminating them
|
||||||
/// from the block. Provides a simple way to compact the block. The
|
/// from the block. Provides a simple way to compact the block. The
|
||||||
/// elimination is stable with respect to inputs and outputs order.
|
/// elimination is stable with respect to inputs and outputs order.
|
||||||
|
@ -312,11 +308,7 @@ impl Block {
|
||||||
|
|
||||||
Block {
|
Block {
|
||||||
// compact will fix the merkle tree
|
// compact will fix the merkle tree
|
||||||
header: BlockHeader {
|
header: BlockHeader { pow: self.header.pow.clone(), ..self.header },
|
||||||
total_fees: self.header.total_fees + other.header.total_fees,
|
|
||||||
pow: self.header.pow.clone(),
|
|
||||||
..self.header
|
|
||||||
},
|
|
||||||
inputs: all_inputs,
|
inputs: all_inputs,
|
||||||
outputs: all_outputs,
|
outputs: all_outputs,
|
||||||
proofs: all_proofs,
|
proofs: all_proofs,
|
||||||
|
|
|
@ -60,7 +60,7 @@ pub const ZERO_HASH: Hash = Hash([0; 32]);
|
||||||
|
|
||||||
/// Serializer that outputs a hash of the serialized object
|
/// Serializer that outputs a hash of the serialized object
|
||||||
pub struct HashWriter {
|
pub struct HashWriter {
|
||||||
state: Keccak
|
state: Keccak,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HashWriter {
|
impl HashWriter {
|
||||||
|
@ -71,9 +71,7 @@ impl HashWriter {
|
||||||
|
|
||||||
impl Default for HashWriter {
|
impl Default for HashWriter {
|
||||||
fn default() -> HashWriter {
|
fn default() -> HashWriter {
|
||||||
HashWriter {
|
HashWriter { state: Keccak::new_sha3_256() }
|
||||||
state: Keccak::new_sha3_256()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +88,7 @@ impl ser::Writer for HashWriter {
|
||||||
|
|
||||||
/// A trait for types that have a canonical hash
|
/// A trait for types that have a canonical hash
|
||||||
pub trait Hashed {
|
pub trait Hashed {
|
||||||
fn hash(&self) -> Hash;
|
fn hash(&self) -> Hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: ser::Writeable> Hashed for W {
|
impl<W: ser::Writeable> Hashed for W {
|
||||||
|
@ -112,4 +110,3 @@ impl Hashed for [u8] {
|
||||||
Hash(ret)
|
Hash(ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,8 +156,10 @@ impl Writeable for HPair {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// An iterator over hashes in a vector that pairs them to build a row in a
|
/// An iterator over hashes in a vector that pairs them to build a row in a
|
||||||
/// Merkle tree. If the vector has an odd number of hashes, it appends a zero hash
|
/// Merkle tree. If the vector has an odd number of hashes, it appends a zero
|
||||||
/// See https://bitcointalk.org/index.php?topic=102395.0 CVE-2012-2459 (block merkle calculation exploit)
|
/// hash
|
||||||
|
/// See https://bitcointalk.org/index.php?topic=102395.0 CVE-2012-2459 (block
|
||||||
|
/// merkle calculation exploit)
|
||||||
/// for the argument against duplication of last hash
|
/// for the argument against duplication of last hash
|
||||||
struct HPairIter(Vec<Hash>);
|
struct HPairIter(Vec<Hash>);
|
||||||
impl Iterator for HPairIter {
|
impl Iterator for HPairIter {
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub fn genesis() -> core::Block {
|
||||||
core::Block {
|
core::Block {
|
||||||
header: core::BlockHeader {
|
header: core::BlockHeader {
|
||||||
height: 0,
|
height: 0,
|
||||||
previous: core::hash::ZERO_HASH,
|
previous: core::hash::Hash([0xff; 32]),
|
||||||
timestamp: time::Tm {
|
timestamp: time::Tm {
|
||||||
tm_year: 1997,
|
tm_year: 1997,
|
||||||
tm_mon: 7,
|
tm_mon: 7,
|
||||||
|
@ -41,7 +41,6 @@ pub fn genesis() -> core::Block {
|
||||||
td: 0,
|
td: 0,
|
||||||
utxo_merkle: core::hash::Hash::from_vec(empty_h.to_vec()),
|
utxo_merkle: core::hash::Hash::from_vec(empty_h.to_vec()),
|
||||||
tx_merkle: core::hash::Hash::from_vec(empty_h.to_vec()),
|
tx_merkle: core::hash::Hash::from_vec(empty_h.to_vec()),
|
||||||
total_fees: 0,
|
|
||||||
nonce: 0,
|
nonce: 0,
|
||||||
pow: core::Proof::zero(), // TODO get actual PoW solution
|
pow: core::Proof::zero(), // TODO get actual PoW solution
|
||||||
},
|
},
|
||||||
|
|
|
@ -61,7 +61,6 @@ struct PowHeader {
|
||||||
pub timestamp: time::Tm,
|
pub timestamp: time::Tm,
|
||||||
pub utxo_merkle: Hash,
|
pub utxo_merkle: Hash,
|
||||||
pub tx_merkle: Hash,
|
pub tx_merkle: Hash,
|
||||||
pub total_fees: u64,
|
|
||||||
pub n_in: u64,
|
pub n_in: u64,
|
||||||
pub n_out: u64,
|
pub n_out: u64,
|
||||||
pub n_proofs: u64,
|
pub n_proofs: u64,
|
||||||
|
@ -78,7 +77,6 @@ impl Writeable for PowHeader {
|
||||||
try!(writer.write_i64(self.timestamp.to_timespec().sec));
|
try!(writer.write_i64(self.timestamp.to_timespec().sec));
|
||||||
try!(writer.write_fixed_bytes(&self.utxo_merkle));
|
try!(writer.write_fixed_bytes(&self.utxo_merkle));
|
||||||
try!(writer.write_fixed_bytes(&self.tx_merkle));
|
try!(writer.write_fixed_bytes(&self.tx_merkle));
|
||||||
try!(writer.write_u64(self.total_fees));
|
|
||||||
try!(writer.write_u64(self.n_in));
|
try!(writer.write_u64(self.n_in));
|
||||||
try!(writer.write_u64(self.n_out));
|
try!(writer.write_u64(self.n_out));
|
||||||
writer.write_u64(self.n_proofs)
|
writer.write_u64(self.n_proofs)
|
||||||
|
@ -95,7 +93,6 @@ impl PowHeader {
|
||||||
timestamp: h.timestamp,
|
timestamp: h.timestamp,
|
||||||
utxo_merkle: h.utxo_merkle,
|
utxo_merkle: h.utxo_merkle,
|
||||||
tx_merkle: h.tx_merkle,
|
tx_merkle: h.tx_merkle,
|
||||||
total_fees: h.total_fees,
|
|
||||||
n_in: b.inputs.len() as u64,
|
n_in: b.inputs.len() as u64,
|
||||||
n_out: b.outputs.len() as u64,
|
n_out: b.outputs.len() as u64,
|
||||||
n_proofs: b.proofs.len() as u64,
|
n_proofs: b.proofs.len() as u64,
|
||||||
|
|
|
@ -49,9 +49,11 @@ impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Error::IOErr(ref e) => write!(f, "{}", e),
|
Error::IOErr(ref e) => write!(f, "{}", e),
|
||||||
Error::UnexpectedData { expected: ref e, received: ref r } => write!(f, "expected {:?}, got {:?}", e, r),
|
Error::UnexpectedData { expected: ref e, received: ref r } => {
|
||||||
|
write!(f, "expected {:?}, got {:?}", e, r)
|
||||||
|
}
|
||||||
Error::CorruptedData => f.write_str("corrupted data"),
|
Error::CorruptedData => f.write_str("corrupted data"),
|
||||||
Error::TooLargeReadErr(ref s) => f.write_str(&s)
|
Error::TooLargeReadErr(ref s) => f.write_str(&s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +62,7 @@ impl error::Error for Error {
|
||||||
fn cause(&self) -> Option<&error::Error> {
|
fn cause(&self) -> Option<&error::Error> {
|
||||||
match *self {
|
match *self {
|
||||||
Error::IOErr(ref e) => Some(e),
|
Error::IOErr(ref e) => Some(e),
|
||||||
_ => None
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +71,7 @@ impl error::Error for Error {
|
||||||
Error::IOErr(ref e) => error::Error::description(e),
|
Error::IOErr(ref e) => error::Error::description(e),
|
||||||
Error::UnexpectedData { expected: _, received: _ } => "unexpected data",
|
Error::UnexpectedData { expected: _, received: _ } => "unexpected data",
|
||||||
Error::CorruptedData => "corrupted data",
|
Error::CorruptedData => "corrupted data",
|
||||||
Error::TooLargeReadErr(ref s) => s
|
Error::TooLargeReadErr(ref s) => s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +92,7 @@ pub enum SerializationMode {
|
||||||
/// Serialize the data that defines the object
|
/// Serialize the data that defines the object
|
||||||
Hash,
|
Hash,
|
||||||
/// Serialize everything that a signer of the object should know
|
/// Serialize everything that a signer of the object should know
|
||||||
SigHash
|
SigHash,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implementations defined how different numbers and binary structures are
|
/// Implementations defined how different numbers and binary structures are
|
||||||
|
|
Loading…
Reference in a new issue