Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 12 additions & 9 deletions modules/chain_store/src/stores/fjall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct FjallStore {
keyspace: Keyspace,
blocks: FjallBlockStore,
txs: FjallTXStore,
last_persisted_block: Option<u64>,
last_persisted_block: u64,
}

const DEFAULT_DATABASE_PATH: &str = "fjall-blocks";
Expand All @@ -36,11 +36,17 @@ impl FjallStore {
let txs = FjallTXStore::new(&keyspace)?;

let last_persisted_block = if !clear {
blocks.block_hashes_by_number.iter().next_back().and_then(|res| {
res.ok().and_then(|(key, _)| key.as_ref().try_into().ok().map(u64::from_be_bytes))
})
blocks
.block_hashes_by_number
.iter()
.next_back()
.and_then(|res| {
res.ok()
.and_then(|(key, _)| key.as_ref().try_into().ok().map(u64::from_be_bytes))
})
.unwrap_or(0)
} else {
None
0
};

Ok(Self {
Expand Down Expand Up @@ -81,10 +87,7 @@ impl super::Store for FjallStore {
}

fn should_persist(&self, block_number: u64) -> bool {
match self.last_persisted_block {
Some(last) => block_number > last,
None => false,
}
block_number > self.last_persisted_block
}

fn get_block_by_hash(&self, hash: &[u8]) -> Result<Option<Block>> {
Expand Down
4 changes: 1 addition & 3 deletions modules/epochs_state/src/epochs_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ impl EpochsState {
let span = info_span!("epochs_state.handle_mint", block = block_info.number);
span.in_scope(|| {
if let Some(header) = header.as_ref() {
if let Some(issuer_vkey) = header.issuer_vkey() {
state.handle_mint(block_info, issuer_vkey);
}
state.handle_mint(block_info, header.issuer_vkey());
}
});
}
Expand Down
29 changes: 15 additions & 14 deletions modules/epochs_state/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,15 @@ impl State {

// Handle mint
// This will update last block time
pub fn handle_mint(&mut self, block_info: &BlockInfo, issuer_vkey: &[u8]) {
pub fn handle_mint(&mut self, block_info: &BlockInfo, issuer_vkey: Option<&[u8]>) {
self.last_block_time = block_info.timestamp;
self.last_block_height = block_info.number;
self.epoch_blocks += 1;
let spo_id = PoolId::from(keyhash_224(issuer_vkey));

// Count one on this hash
*(self.blocks_minted.entry(spo_id).or_insert(0)) += 1;
if let Some(issuer_vkey) = issuer_vkey {
let spo_id = PoolId::from(keyhash_224(issuer_vkey));
// Count one on this hash
*(self.blocks_minted.entry(spo_id).or_insert(0)) += 1;
}
}

// Handle Block Txs
Expand Down Expand Up @@ -329,9 +330,9 @@ mod tests {
let mut state = State::new(&GenesisValues::mainnet());
let issuer = b"issuer_key";
let mut block = make_block(100);
state.handle_mint(&block, issuer);
state.handle_mint(&block, Some(issuer));
block.number += 1;
state.handle_mint(&block, issuer);
state.handle_mint(&block, Some(issuer));

assert_eq!(state.epoch_blocks, 2);
assert_eq!(state.blocks_minted.len(), 1);
Expand All @@ -345,11 +346,11 @@ mod tests {
fn handle_mint_multiple_issuer_records_counts() {
let mut state = State::new(&GenesisValues::mainnet());
let mut block = make_block(100);
state.handle_mint(&block, b"issuer_1");
state.handle_mint(&block, Some(b"issuer_1"));
block.number += 1;
state.handle_mint(&block, b"issuer_2");
state.handle_mint(&block, Some(b"issuer_2"));
block.number += 1;
state.handle_mint(&block, b"issuer_2");
state.handle_mint(&block, Some(b"issuer_2"));

assert_eq!(state.epoch_blocks, 3);
assert_eq!(state.blocks_minted.len(), 2);
Expand Down Expand Up @@ -408,7 +409,7 @@ mod tests {
let genesis = GenesisValues::mainnet();
let mut state = State::new(&genesis);
let block = make_block(1);
state.handle_mint(&block, b"issuer_1");
state.handle_mint(&block, Some(b"issuer_1"));
state.handle_block_txs(
&block,
&BlockTxsMessage {
Expand Down Expand Up @@ -464,7 +465,7 @@ mod tests {
)));
let mut state = history.lock().await.get_current_state();
let mut block = make_block(1);
state.handle_mint(&block, b"issuer_1");
state.handle_mint(&block, Some(b"issuer_1"));
state.handle_block_txs(
&block,
&BlockTxsMessage {
Expand All @@ -477,7 +478,7 @@ mod tests {

let mut state = history.lock().await.get_current_state();
block.number += 1;
state.handle_mint(&block, b"issuer_1");
state.handle_mint(&block, Some(b"issuer_1"));
state.handle_block_txs(
&block,
&BlockTxsMessage {
Expand All @@ -494,7 +495,7 @@ mod tests {

block = make_rolled_back_block(0);
let mut state = history.lock().await.get_rolled_back_state(block.number);
state.handle_mint(&block, b"issuer_2");
state.handle_mint(&block, Some(b"issuer_2"));
state.handle_block_txs(
&block,
&BlockTxsMessage {
Expand Down