Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hoist fee collector id #2945

Merged
merged 1 commit into from
Feb 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ pub struct Bank {
/// The number of slots in each epoch.
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,

/// The pubkey to send transactions fees to.
collector_id: Pubkey,
}

impl Bank {
Expand All @@ -120,7 +123,7 @@ impl 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();

let mut bank = Self::default();
Expand All @@ -132,14 +135,16 @@ impl Bank {
bank.id = id;
bank.parent = RwLock::new(Some(parent.clone()));
bank.parent_hash = parent.hash();
bank.collector_id = collector_id;

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
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 {
Expand Down Expand Up @@ -197,6 +202,9 @@ impl Bank {
assert!(genesis_block.tokens >= genesis_block.bootstrap_leader_tokens);
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;
self.deposit(&genesis_block.mint_id, mint_tokens);

Expand Down Expand Up @@ -515,7 +523,7 @@ impl Bank {
_ => res.clone(),
})
.collect();
self.deposit(&self.slot_leader(), fees);
self.deposit(&self.collector_id, fees);
results
}

Expand Down Expand Up @@ -1470,8 +1478,9 @@ mod tests {

#[test]
fn test_bank_hash_internal_state_squash() {
let collector_id = Pubkey::default();
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
assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state());
Expand Down