Proper rewarding; needs consensus test doing though.
This commit is contained in:
		
							parent
							
								
									fea418703b
								
							
						
					
					
						commit
						4f68662e53
					
				@ -148,9 +148,9 @@ impl<'engine> OpenBlock<'engine> {
 | 
			
		||||
	pub fn env_info(&self) -> EnvInfo {
 | 
			
		||||
		// TODO: memoise.
 | 
			
		||||
		EnvInfo {
 | 
			
		||||
			number: self.block.header.number.clone(),
 | 
			
		||||
			number: self.block.header.number,
 | 
			
		||||
			author: self.block.header.author.clone(),
 | 
			
		||||
			timestamp: self.block.header.timestamp.clone(),
 | 
			
		||||
			timestamp: self.block.header.timestamp,
 | 
			
		||||
			difficulty: self.block.header.difficulty.clone(),
 | 
			
		||||
			last_hashes: self.last_hashes.clone(),
 | 
			
		||||
			gas_used: self.block.archive.last().map(|t| t.receipt.gas_used).unwrap_or(U256::from(0)),
 | 
			
		||||
 | 
			
		||||
@ -7,11 +7,11 @@ pub type LastHashes = Vec<H256>;
 | 
			
		||||
/// Information concerning the execution environment for a message-call/contract-creation.
 | 
			
		||||
pub struct EnvInfo {
 | 
			
		||||
	/// The block number.
 | 
			
		||||
	pub number: U256,
 | 
			
		||||
	pub number: usize,
 | 
			
		||||
	/// The block author.
 | 
			
		||||
	pub author: Address,
 | 
			
		||||
	/// The block timestamp.
 | 
			
		||||
	pub timestamp: U256,
 | 
			
		||||
	pub timestamp: usize,
 | 
			
		||||
	/// The block difficulty.
 | 
			
		||||
	pub difficulty: U256,
 | 
			
		||||
	/// The block gas limit.
 | 
			
		||||
 | 
			
		||||
@ -17,20 +17,24 @@ impl Ethash {
 | 
			
		||||
 | 
			
		||||
impl Engine for Ethash {
 | 
			
		||||
	fn name(&self) -> &str { "Ethash" }
 | 
			
		||||
	fn version(&self) -> SemanticVersion { SemanticVersion::new(1, 0, 0) }
 | 
			
		||||
	fn spec(&self) -> &Spec { &self.spec }
 | 
			
		||||
	fn evm_schedule(&self, _env_info: &EnvInfo) -> EvmSchedule { EvmSchedule::new_frontier() }
 | 
			
		||||
 | 
			
		||||
	/// Apply the block reward on finalisation of the block.
 | 
			
		||||
	/// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current).
 | 
			
		||||
	fn on_close_block(&self, block: &mut Block) {
 | 
			
		||||
		let reward = self.spec().engine_params.get("blockReward").map(|a| decode(&a)).unwrap_or(U256::from(0u64));
 | 
			
		||||
		let fields = block.fields();
 | 
			
		||||
		fields.state.add_balance(&fields.header.author, &reward);
 | 
			
		||||
/*
 | 
			
		||||
		let uncle_authors = block.uncles.iter().map(|u| u.author().clone()).collect();
 | 
			
		||||
		for a in uncle_authors {
 | 
			
		||||
			block.state_mut().addBalance(a, _blockReward * (8 + i.number() - m_currentBlock.number()) / 8);
 | 
			
		||||
			r += _blockReward / 32;
 | 
			
		||||
		}*/
 | 
			
		||||
 | 
			
		||||
		// Bestow block reward
 | 
			
		||||
		fields.state.add_balance(&fields.header.author, &(reward + reward / U256::from(32) * U256::from(fields.uncles.len())));
 | 
			
		||||
 | 
			
		||||
		// Bestow uncle rewards
 | 
			
		||||
		let current_number = fields.header.number();
 | 
			
		||||
		for u in fields.uncles.iter() {
 | 
			
		||||
			fields.state.add_balance(u.author(), &(reward * U256::from((8 + u.number() - current_number) / 8)));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -43,5 +47,5 @@ fn on_close_block() {
 | 
			
		||||
	engine.spec().ensure_db_good(&mut db);
 | 
			
		||||
	let b = OpenBlock::new(engine.deref(), db, &genesis_header, vec![genesis_header.hash()], Address::zero(), vec![]);
 | 
			
		||||
	let b = b.close();
 | 
			
		||||
	assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244F40000").unwrap());
 | 
			
		||||
	assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap());
 | 
			
		||||
}
 | 
			
		||||
@ -11,8 +11,8 @@ use basic_types::*;
 | 
			
		||||
pub struct Header {
 | 
			
		||||
	// TODO: make all private.
 | 
			
		||||
	pub parent_hash: H256,
 | 
			
		||||
	pub timestamp: U256,
 | 
			
		||||
	pub number: U256,
 | 
			
		||||
	pub timestamp: usize,
 | 
			
		||||
	pub number: usize,
 | 
			
		||||
	pub author: Address,
 | 
			
		||||
 | 
			
		||||
	pub transactions_root: H256,
 | 
			
		||||
@ -41,8 +41,8 @@ impl Header {
 | 
			
		||||
	pub fn new() -> Header {
 | 
			
		||||
		Header {
 | 
			
		||||
			parent_hash: ZERO_H256.clone(),
 | 
			
		||||
			timestamp: BAD_U256.clone(),
 | 
			
		||||
			number: ZERO_U256.clone(),
 | 
			
		||||
			timestamp: 0,
 | 
			
		||||
			number: 0,
 | 
			
		||||
			author: ZERO_ADDRESS.clone(),
 | 
			
		||||
 | 
			
		||||
			transactions_root: ZERO_H256.clone(),
 | 
			
		||||
@ -64,6 +64,7 @@ impl Header {
 | 
			
		||||
	pub fn author(&self) -> &Address { &self.author }
 | 
			
		||||
	pub fn extra_data(&self) -> &Bytes { &self.extra_data }
 | 
			
		||||
	pub fn seal(&self) -> &Vec<Bytes> { &self.seal }
 | 
			
		||||
	pub fn number(&self) -> usize { self.number }
 | 
			
		||||
 | 
			
		||||
	// TODO: seal_at, set_seal_at &c.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -60,7 +60,7 @@ pub struct Spec {
 | 
			
		||||
	pub difficulty: U256,
 | 
			
		||||
	pub gas_limit: U256,
 | 
			
		||||
	pub gas_used: U256,
 | 
			
		||||
	pub timestamp: U256,
 | 
			
		||||
	pub timestamp: usize,
 | 
			
		||||
	pub extra_data: Bytes,
 | 
			
		||||
	pub genesis_state: HashMap<Address, Account>,
 | 
			
		||||
	pub seal_fields: usize,
 | 
			
		||||
@ -92,8 +92,8 @@ impl Spec {
 | 
			
		||||
	pub fn genesis_header(&self) -> Header {
 | 
			
		||||
		Header {
 | 
			
		||||
			parent_hash: self.parent_hash.clone(),
 | 
			
		||||
			timestamp: self.timestamp.clone(),
 | 
			
		||||
			number: U256::from(0u8),
 | 
			
		||||
			timestamp: self.timestamp,
 | 
			
		||||
			number: 0,
 | 
			
		||||
			author: self.author.clone(),
 | 
			
		||||
			transactions_root: SHA3_NULL_RLP.clone(),
 | 
			
		||||
			uncles_hash: RlpStream::new_list(0).out().sha3(),
 | 
			
		||||
@ -181,7 +181,7 @@ impl Spec {
 | 
			
		||||
			difficulty: U256::from_str(&genesis["difficulty"].as_string().unwrap()[2..]).unwrap(),
 | 
			
		||||
			gas_limit: U256::from_str(&genesis["gasLimit"].as_string().unwrap()[2..]).unwrap(),
 | 
			
		||||
			gas_used: U256::from(0u8),
 | 
			
		||||
			timestamp: U256::from_str(&genesis["timestamp"].as_string().unwrap()[2..]).unwrap(),
 | 
			
		||||
			timestamp: usize::from_str(&genesis["timestamp"].as_string().unwrap()[2..]).unwrap(),
 | 
			
		||||
			extra_data: genesis["extraData"].as_string().unwrap()[2..].from_hex().unwrap(),
 | 
			
		||||
			genesis_state: state,
 | 
			
		||||
			seal_fields: seal_fields,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user