Skip to content

Commit

Permalink
Return block_time with confirmed block, if available
Browse files Browse the repository at this point in the history
  • Loading branch information
CriesofCarrots committed Sep 8, 2020
1 parent 733e053 commit 8572ed2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,7 @@ impl Blockstore {
.unwrap_or_else(|| panic!("Rooted slot {:?} must have blockhash", slot));

let rewards = self.rewards_cf.get(slot)?.unwrap_or_else(Vec::new);
let block_time = self.blocktime_cf.get(slot)?;

let block = ConfirmedBlock {
previous_blockhash: previous_blockhash.to_string(),
Expand All @@ -1699,7 +1700,7 @@ impl Blockstore {
slot_transaction_iterator,
),
rewards,
block_time: None, // See https://github.com/solana-labs/solana/issues/10089
block_time,
};
return Ok(block);
}
Expand Down Expand Up @@ -5733,7 +5734,7 @@ pub mod tests {
let confirmed_block = ledger.get_confirmed_block(slot + 1, None).unwrap();
assert_eq!(confirmed_block.transactions.len(), 100);

let expected_block = ConfirmedBlock {
let mut expected_block = ConfirmedBlock {
transactions: expected_transactions
.iter()
.cloned()
Expand All @@ -5753,6 +5754,14 @@ pub mod tests {
let not_root = ledger.get_confirmed_block(slot + 2, None).unwrap_err();
assert_matches!(not_root, BlockstoreError::SlotNotRooted);

// Test block_time returns, if available
let timestamp = 1_576_183_541;
ledger.blocktime_cf.put(slot + 1, &timestamp).unwrap();
expected_block.block_time = Some(timestamp);

let confirmed_block = ledger.get_confirmed_block(slot + 1, None).unwrap();
assert_eq!(confirmed_block, expected_block);

drop(ledger);
Blockstore::destroy(&ledger_path).expect("Expected successful database destruction");
}
Expand Down

0 comments on commit 8572ed2

Please sign in to comment.