Let the bank creator decide where to send transaction fees

This commit is contained in:
Greg Fitzgerald 2019-02-26 06:43:43 -07:00
parent feefdca969
commit 3897b66270
1 changed files with 14 additions and 5 deletions

View File

@ -107,8 +107,11 @@ pub struct Bank {
/// The number of slots in each epoch. /// The number of slots in each epoch.
slots_per_epoch: u64, slots_per_epoch: u64,
// A number of slots before slot_index 0. Used to calculate finalized staked nodes. /// A number of slots before slot_index 0. Used to calculate finalized staked nodes.
stakers_slot_offset: u64, stakers_slot_offset: u64,
/// The pubkey to send transactions fees to.
collector_id: Pubkey,
} }
impl Bank { impl Bank {
@ -120,7 +123,7 @@ impl Bank {
} }
/// Create a new bank that points to an immutable checkpoint of another bank. /// Create a new bank that points to an immutable checkpoint of another bank.
pub fn new_from_parent_and_id(parent: &Arc<Bank>, id: u64) -> Self { pub fn new_from_parent_and_id(parent: &Arc<Bank>, collector_id: Pubkey, id: u64) -> Self {
parent.freeze(); parent.freeze();
let mut bank = Self::default(); let mut bank = Self::default();
@ -132,6 +135,7 @@ impl Bank {
bank.id = id; bank.id = id;
bank.parent = RwLock::new(Some(parent.clone())); bank.parent = RwLock::new(Some(parent.clone()));
bank.parent_hash = parent.hash(); bank.parent_hash = parent.hash();
bank.collector_id = collector_id;
bank bank
} }
@ -139,7 +143,8 @@ impl Bank {
/// Create a new bank that points to an immutable checkpoint of another bank. /// Create a new bank that points to an immutable checkpoint of another bank.
/// TODO: remove me in favor of _and_id(), id should not be an assumed value /// TODO: remove me in favor of _and_id(), id should not be an assumed value
pub fn new_from_parent(parent: &Arc<Bank>) -> Self { pub fn new_from_parent(parent: &Arc<Bank>) -> Self {
Self::new_from_parent_and_id(parent, parent.id() + 1) let collector_id = parent.collector_id;
Self::new_from_parent_and_id(parent, collector_id, parent.id() + 1)
} }
pub fn id(&self) -> u64 { pub fn id(&self) -> u64 {
@ -197,6 +202,9 @@ impl Bank {
assert!(genesis_block.tokens >= genesis_block.bootstrap_leader_tokens); assert!(genesis_block.tokens >= genesis_block.bootstrap_leader_tokens);
assert!(genesis_block.bootstrap_leader_tokens >= 2); assert!(genesis_block.bootstrap_leader_tokens >= 2);
// Bootstrap leader collects fees until `new_from_parent_and_id` is called.
self.collector_id = genesis_block.bootstrap_leader_id;
let mint_tokens = genesis_block.tokens - genesis_block.bootstrap_leader_tokens; let mint_tokens = genesis_block.tokens - genesis_block.bootstrap_leader_tokens;
self.deposit(&genesis_block.mint_id, mint_tokens); self.deposit(&genesis_block.mint_id, mint_tokens);
@ -511,7 +519,7 @@ impl Bank {
_ => res.clone(), _ => res.clone(),
}) })
.collect(); .collect();
self.deposit(&self.slot_leader(), fees); self.deposit(&self.collector_id, fees);
results results
} }
@ -1470,8 +1478,9 @@ mod tests {
#[test] #[test]
fn test_bank_hash_internal_state_squash() { fn test_bank_hash_internal_state_squash() {
let collector_id = Pubkey::default();
let bank0 = Arc::new(Bank::new(&GenesisBlock::new(10).0)); let bank0 = Arc::new(Bank::new(&GenesisBlock::new(10).0));
let bank1 = Bank::new_from_parent_and_id(&bank0, 1); let bank1 = Bank::new_from_parent_and_id(&bank0, collector_id, 1);
// no delta in bank1, hashes match // no delta in bank1, hashes match
assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state()); assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state());