Skip to content

Commit

Permalink
add subscriber notifications for rollbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-solana committed Nov 2, 2018
1 parent 63321a6 commit 1531b9f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,25 @@ impl Bank {
self.last_ids.write().unwrap().checkpoint();
}
pub fn rollback(&self) {
let rolled_back_pubkeys: Vec<Pubkey> = self
.accounts
.read()
.unwrap()
.accounts
.keys()
.map(|pubkey| pubkey.clone())
.collect();

self.accounts.write().unwrap().rollback();

rolled_back_pubkeys.iter().for_each(|pubkey| {
self.accounts
.read()
.unwrap()
.load(&pubkey)
.map(|account| self.check_account_subscriptions(&pubkey, account));
});

self.last_ids.write().unwrap().rollback();
}
pub fn checkpoint_depth(&self) -> usize {
Expand Down Expand Up @@ -2187,4 +2205,12 @@ mod tests {
Err(BankError::DuplicateSignature)
);
}
#[test]
#[should_panic]
fn test_rollback_panic() {
let alice = Mint::new(10_000);
let bank = Bank::new(&alice);
bank.rollback();
}

}

0 comments on commit 1531b9f

Please sign in to comment.