Skip to content

Commit 5fe9a23

Browse files
committed
fix: handle byron blocks mint where there is no issuer
1 parent a8a36b4 commit 5fe9a23

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

modules/epochs_state/src/epochs_state.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ impl EpochsState {
150150
let span = info_span!("epochs_state.handle_mint", block = block_info.number);
151151
span.in_scope(|| {
152152
if let Some(header) = header.as_ref() {
153-
if let Some(issuer_vkey) = header.issuer_vkey() {
154-
state.handle_mint(block_info, issuer_vkey);
155-
}
153+
state.handle_mint(block_info, header.issuer_vkey());
156154
}
157155
});
158156
}

modules/epochs_state/src/state.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,15 @@ impl State {
183183

184184
// Handle mint
185185
// This will update last block time
186-
pub fn handle_mint(&mut self, block_info: &BlockInfo, issuer_vkey: &[u8]) {
186+
pub fn handle_mint(&mut self, block_info: &BlockInfo, issuer_vkey: Option<&[u8]>) {
187187
self.last_block_time = block_info.timestamp;
188188
self.last_block_height = block_info.number;
189189
self.epoch_blocks += 1;
190-
let spo_id = PoolId::from(keyhash_224(issuer_vkey));
191-
192-
// Count one on this hash
193-
*(self.blocks_minted.entry(spo_id).or_insert(0)) += 1;
190+
if let Some(issuer_vkey) = issuer_vkey {
191+
let spo_id = PoolId::from(keyhash_224(issuer_vkey));
192+
// Count one on this hash
193+
*(self.blocks_minted.entry(spo_id).or_insert(0)) += 1;
194+
}
194195
}
195196

196197
// Handle Block Txs
@@ -329,9 +330,9 @@ mod tests {
329330
let mut state = State::new(&GenesisValues::mainnet());
330331
let issuer = b"issuer_key";
331332
let mut block = make_block(100);
332-
state.handle_mint(&block, issuer);
333+
state.handle_mint(&block, Some(issuer));
333334
block.number += 1;
334-
state.handle_mint(&block, issuer);
335+
state.handle_mint(&block, Some(issuer));
335336

336337
assert_eq!(state.epoch_blocks, 2);
337338
assert_eq!(state.blocks_minted.len(), 1);
@@ -345,11 +346,11 @@ mod tests {
345346
fn handle_mint_multiple_issuer_records_counts() {
346347
let mut state = State::new(&GenesisValues::mainnet());
347348
let mut block = make_block(100);
348-
state.handle_mint(&block, b"issuer_1");
349+
state.handle_mint(&block, Some(b"issuer_1"));
349350
block.number += 1;
350-
state.handle_mint(&block, b"issuer_2");
351+
state.handle_mint(&block, Some(b"issuer_2"));
351352
block.number += 1;
352-
state.handle_mint(&block, b"issuer_2");
353+
state.handle_mint(&block, Some(b"issuer_2"));
353354

354355
assert_eq!(state.epoch_blocks, 3);
355356
assert_eq!(state.blocks_minted.len(), 2);
@@ -408,7 +409,7 @@ mod tests {
408409
let genesis = GenesisValues::mainnet();
409410
let mut state = State::new(&genesis);
410411
let block = make_block(1);
411-
state.handle_mint(&block, b"issuer_1");
412+
state.handle_mint(&block, Some(b"issuer_1"));
412413
state.handle_block_txs(
413414
&block,
414415
&BlockTxsMessage {
@@ -464,7 +465,7 @@ mod tests {
464465
)));
465466
let mut state = history.lock().await.get_current_state();
466467
let mut block = make_block(1);
467-
state.handle_mint(&block, b"issuer_1");
468+
state.handle_mint(&block, Some(b"issuer_1"));
468469
state.handle_block_txs(
469470
&block,
470471
&BlockTxsMessage {
@@ -477,7 +478,7 @@ mod tests {
477478

478479
let mut state = history.lock().await.get_current_state();
479480
block.number += 1;
480-
state.handle_mint(&block, b"issuer_1");
481+
state.handle_mint(&block, Some(b"issuer_1"));
481482
state.handle_block_txs(
482483
&block,
483484
&BlockTxsMessage {
@@ -494,7 +495,7 @@ mod tests {
494495

495496
block = make_rolled_back_block(0);
496497
let mut state = history.lock().await.get_rolled_back_state(block.number);
497-
state.handle_mint(&block, b"issuer_2");
498+
state.handle_mint(&block, Some(b"issuer_2"));
498499
state.handle_block_txs(
499500
&block,
500501
&BlockTxsMessage {

0 commit comments

Comments
 (0)