Revert "add block validation consensus rule for block coinbase output" (#691)

also fix tests for size of blocks etc.

This reverts commit ecda870d70.
This commit is contained in:
Antioch Peverell 2018-02-07 12:23:48 -05:00 committed by GitHub
parent 78a6447a09
commit ad594b53de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 44 deletions

View file

@ -44,16 +44,6 @@ pub fn reward(fee: u64) -> u64 {
/// Number of blocks before a coinbase matures and can be spent /// Number of blocks before a coinbase matures and can be spent
pub const COINBASE_MATURITY: u64 = 1_000; pub const COINBASE_MATURITY: u64 = 1_000;
/// Max number of coinbase outputs in a valid block.
/// This is to prevent a miner generating an excessively large "compact block".
/// But we do techincally support blocks with multiple coinbase outputs/kernels.
pub const MAX_BLOCK_COINBASE_OUTPUTS: u64 = 1;
/// Max number of coinbase kernels in a valid block.
/// This is to prevent a miner generating an excessively large "compact block".
/// But we do techincally support blocks with multiple coinbase outputs/kernels.
pub const MAX_BLOCK_COINBASE_KERNELS: u64 = 1;
/// Block interval, in seconds, the network will tune its next_target for. Note /// Block interval, in seconds, the network will tune its next_target for. Note
/// that we may reduce this value in the future as we get more data on mining /// that we may reduce this value in the future as we get more data on mining
/// with Cuckoo Cycle, networks improve and block propagation is optimized /// with Cuckoo Cycle, networks improve and block propagation is optimized
@ -131,7 +121,7 @@ pub fn valid_header_version(height: u64, version: u16) -> bool {
/// Time window in blocks to calculate block time median /// Time window in blocks to calculate block time median
pub const MEDIAN_TIME_WINDOW: u64 = 11; pub const MEDIAN_TIME_WINDOW: u64 = 11;
/// Index at half the desired median /// Index at half the desired median
pub const MEDIAN_TIME_INDEX: u64 = MEDIAN_TIME_WINDOW / 2; pub const MEDIAN_TIME_INDEX: u64 = MEDIAN_TIME_WINDOW / 2;
/// Number of blocks used to calculate difficulty adjustments /// Number of blocks used to calculate difficulty adjustments
@ -181,8 +171,8 @@ impl fmt::Display for TargetError {
/// The difficulty calculation is based on both Digishield and GravityWave /// The difficulty calculation is based on both Digishield and GravityWave
/// family of difficulty computation, coming to something very close to Zcash. /// family of difficulty computation, coming to something very close to Zcash.
/// The refence difficulty is an average of the difficulty over a window of /// The refence difficulty is an average of the difficulty over a window of
/// DIFFICULTY_ADJUST_WINDOW blocks. The corresponding timespan is calculated /// DIFFICULTY_ADJUST_WINDOW blocks. The corresponding timespan is calculated
/// by using the difference between the median timestamps at the beginning /// by using the difference between the median timestamps at the beginning
/// and the end of the window. /// and the end of the window.
pub fn next_difficulty<T>(cursor: T) -> Result<Difficulty, TargetError> pub fn next_difficulty<T>(cursor: T) -> Result<Difficulty, TargetError>
where where
@ -202,7 +192,7 @@ where
.fold(Difficulty::zero(), |sum, d| sum + d.clone().unwrap().1); .fold(Difficulty::zero(), |sum, d| sum + d.clone().unwrap().1);
// Obtain the median window for the earlier time period // Obtain the median window for the earlier time period
// which is just the first MEDIAN_TIME_WINDOW elements // which is just the first MEDIAN_TIME_WINDOW elements
let mut window_earliest: Vec<u64> = diff_data.iter() let mut window_earliest: Vec<u64> = diff_data.iter()
.take(MEDIAN_TIME_WINDOW as usize) .take(MEDIAN_TIME_WINDOW as usize)
.map(|n| n.clone().unwrap().0) .map(|n| n.clone().unwrap().0)

View file

@ -73,10 +73,6 @@ pub enum Error {
/// The lock_height needed to be reached for the coinbase output to mature /// The lock_height needed to be reached for the coinbase output to mature
lock_height: u64, lock_height: u64,
}, },
/// Limit on number of coinbase outputs in a valid block.
CoinbaseOutputCountExceeded,
/// Limit on number of coinbase kernels in a valid block.
CoinbaseKernelCountExceeded,
/// Other unspecified error condition /// Other unspecified error condition
Other(String) Other(String)
} }
@ -234,14 +230,10 @@ impl Writeable for CompactBlock {
try!(self.header.write(writer)); try!(self.header.write(writer));
if writer.serialization_mode() != ser::SerializationMode::Hash { if writer.serialization_mode() != ser::SerializationMode::Hash {
// TODO - make these constants and put them somewhere reusable?
assert!(self.out_full.len() < 16);
assert!(self.kern_full.len() < 16);
ser_multiwrite!( ser_multiwrite!(
writer, writer,
[write_u8, self.out_full.len() as u8], [write_u64, self.out_full.len() as u64],
[write_u8, self.kern_full.len() as u8], [write_u64, self.kern_full.len() as u64],
[write_u64, self.kern_ids.len() as u64] [write_u64, self.kern_ids.len() as u64]
); );
@ -265,7 +257,7 @@ impl Readable for CompactBlock {
let header = try!(BlockHeader::read(reader)); let header = try!(BlockHeader::read(reader));
let (out_full_len, kern_full_len, kern_id_len) = let (out_full_len, kern_full_len, kern_id_len) =
ser_multiread!(reader, read_u8, read_u8, read_u64); ser_multiread!(reader, read_u64, read_u64, read_u64);
let out_full = read_and_verify_sorted(reader, out_full_len as u64)?; let out_full = read_and_verify_sorted(reader, out_full_len as u64)?;
let kern_full = read_and_verify_sorted(reader, kern_full_len as u64)?; let kern_full = read_and_verify_sorted(reader, kern_full_len as u64)?;
@ -670,12 +662,11 @@ impl Block {
Ok(()) Ok(())
} }
/// Validate the coinbase outputs generated by miners. Entails 3 main checks: // Validate the coinbase outputs generated by miners. Entails 2 main checks:
/// //
/// * That the block does not exceed the number of permitted coinbase outputs or kernels. // * That the sum of all coinbase-marked outputs equal the supply.
/// * That the sum of all coinbase-marked outputs equal the supply. // * That the sum of blinding factors for all coinbase-marked outputs match
/// * That the sum of blinding factors for all coinbase-marked outputs match // the coinbase-marked kernels.
/// the coinbase-marked kernels.
fn verify_coinbase(&self) -> Result<(), Error> { fn verify_coinbase(&self) -> Result<(), Error> {
let cb_outs = self.outputs let cb_outs = self.outputs
.iter() .iter()
@ -689,16 +680,6 @@ impl Block {
.cloned() .cloned()
.collect::<Vec<TxKernel>>(); .collect::<Vec<TxKernel>>();
// First check that we do not have too many coinbase outputs in the block.
if cb_outs.len() as u64 > consensus::MAX_BLOCK_COINBASE_OUTPUTS {
return Err(Error::CoinbaseOutputCountExceeded);
}
// And that we do not have too many coinbase kernels in the block.
if cb_kerns.len() as u64 > consensus::MAX_BLOCK_COINBASE_KERNELS {
return Err(Error::CoinbaseKernelCountExceeded);
}
let over_commit; let over_commit;
let out_adjust_sum; let out_adjust_sum;
let kerns_sum; let kerns_sum;
@ -1054,7 +1035,7 @@ mod test {
ser::serialize(&mut vec, &b.as_compact_block()).expect("serialization failed"); ser::serialize(&mut vec, &b.as_compact_block()).expect("serialization failed");
assert_eq!( assert_eq!(
vec.len(), vec.len(),
5_662 5_676
); );
} }
@ -1067,7 +1048,7 @@ mod test {
ser::serialize(&mut vec, &b.as_compact_block()).expect("serialization failed"); ser::serialize(&mut vec, &b.as_compact_block()).expect("serialization failed");
assert_eq!( assert_eq!(
vec.len(), vec.len(),
5_668 5_682
); );
} }
@ -1111,7 +1092,7 @@ mod test {
ser::serialize(&mut vec, &b.as_compact_block()).expect("serialization failed"); ser::serialize(&mut vec, &b.as_compact_block()).expect("serialization failed");
assert_eq!( assert_eq!(
vec.len(), vec.len(),
5_722 5_736
); );
} }