Skip to content

Commit

Permalink
minor changes to checks
Browse files Browse the repository at this point in the history
  • Loading branch information
stojanov-igor committed Jan 28, 2025
1 parent 23617e7 commit c1bcbbd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions jam/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ impl Blockchain {
}

pub fn add_block(&mut self, block: Block) -> Result<(), String> {
// Validate the block
if self.validate_block(&block) {
// Update the current slot if block is valid
self.current_slot = block.header.slot;
self.current_slot = block.header.slot; // Update current_slot to the new block's slot
self.chain.push(block);
Ok(())
} else {
Expand All @@ -53,11 +51,13 @@ impl Blockchain {
}

fn validate_slot(&self, slot: u64) -> bool {
// Allow the genesis block (slot 0 or parent hash is genesis hash)
// Allow genesis block (slot 0)
if slot == 0 {
return true;
}
slot >= self.current_slot && slot < self.current_slot + self.epoch_duration

// Ensure the slot is greater than the current slot
slot > self.current_slot
}

fn validate_entropy(&self, entropy: &str) -> bool {
Expand All @@ -74,7 +74,7 @@ impl Blockchain {
parent: parent_hash,
parent_state_root: "0".repeat(64),
extrinsic_hash: extrinsic.calculate_hash(),
slot: self.current_slot,
slot: self.current_slot + 1, // Increment slot for mined block
epoch_mark: None, // Placeholder for simplicity
tickets_mark: None, // Placeholder for simplicity
offenders_mark: vec![],
Expand Down

0 comments on commit c1bcbbd

Please sign in to comment.