add current to bank syscalls (#4581)
This commit is contained in:
parent
fdaa939892
commit
37c2fa1d8d
|
@ -29,6 +29,7 @@ use solana_sdk::hash::{extend_and_hash, Hash};
|
|||
use solana_sdk::native_loader;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, Signature};
|
||||
use solana_sdk::syscall::current::{self, Current};
|
||||
use solana_sdk::syscall::fees::{self, Fees};
|
||||
use solana_sdk::syscall::slot_hashes::{self, SlotHashes};
|
||||
use solana_sdk::syscall::tick_height::{self, TickHeight};
|
||||
|
@ -275,6 +276,7 @@ impl Bank {
|
|||
bank.epoch_stakes.insert(i, stakes.clone());
|
||||
}
|
||||
}
|
||||
bank.update_current();
|
||||
bank
|
||||
}
|
||||
|
||||
|
@ -331,6 +333,7 @@ impl Bank {
|
|||
bank.parents().iter().enumerate().for_each(|(i, p)| {
|
||||
bank.ancestors.insert(p.slot(), i + 1);
|
||||
});
|
||||
bank.update_current();
|
||||
|
||||
bank
|
||||
}
|
||||
|
@ -355,6 +358,18 @@ impl Bank {
|
|||
*self.hash.read().unwrap() != Hash::default()
|
||||
}
|
||||
|
||||
fn update_current(&self) {
|
||||
let mut account = current::create_account(1);
|
||||
let current = Current {
|
||||
slot: self.slot,
|
||||
epoch: self.epoch_schedule.get_epoch(self.slot),
|
||||
stakers_epoch: self.epoch_schedule.get_stakers_epoch(self.slot),
|
||||
};
|
||||
current.to(&mut account).unwrap();
|
||||
|
||||
self.store(¤t::id(), &account);
|
||||
}
|
||||
|
||||
fn update_slot_hashes(&self) {
|
||||
let mut account = self
|
||||
.get_account(&slot_hashes::id())
|
||||
|
|
|
@ -62,6 +62,11 @@ impl EpochSchedule {
|
|||
}
|
||||
}
|
||||
|
||||
/// get epoch for the given slot
|
||||
pub fn get_epoch(&self, slot: u64) -> u64 {
|
||||
self.get_epoch_and_slot_index(slot).0
|
||||
}
|
||||
|
||||
/// get epoch and offset into the epoch for the given slot
|
||||
pub fn get_epoch_and_slot_index(&self, slot: u64) -> (u64, u64) {
|
||||
if slot < self.first_normal_slot {
|
||||
|
|
|
@ -14,10 +14,9 @@ const ID: [u8; 32] = [
|
|||
#[repr(C)]
|
||||
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
|
||||
pub struct Current {
|
||||
slot: u64,
|
||||
block: u64,
|
||||
epoch: u64,
|
||||
stakers_epoch: u64,
|
||||
pub slot: u64,
|
||||
pub epoch: u64,
|
||||
pub stakers_epoch: u64,
|
||||
}
|
||||
|
||||
impl Current {
|
||||
|
|
Loading…
Reference in New Issue