message: verify_block_in_chain() -> ChainState::verify_block()
diff: @@ -6,33 +6,29 @@ pub struct ChainState {
  pub prev_block: HeaderHash,
  pub prev_date: Option<BlockDate>,
  pub slot_leaders: Vec<address::StakeholderId>,
  + pub protocol_magic: ProtocolMagic,
  }
  impl ChainState {
  - pub fn new(genesis_prev: &HeaderHash) -> Self {
  + pub fn new(genesis_prev: &HeaderHash, protocol_magic: ProtocolMagic) -> Self {
  ChainState {
  prev_block: genesis_prev.clone(),
  prev_date: None,
  - slot_leaders: vec![]
  - }
  + slot_leaders: vec![],
  + protocol_magic
  }
  }
  -pub fn verify_block_in_chain(
  - protocol_magic: ProtocolMagic,
  - chain_state: &mut ChainState,
  - block_hash: &HeaderHash,
  - blk: &Block) -> Result<(), Error>
  -{
  - let res = do_verify(protocol_magic, chain_state, block_hash, blk);
  + pub fn verify_block(&mut self, block_hash: &HeaderHash, blk: &Block) -> Result<(), Error> {
  + let res = self.do_verify(block_hash, blk);
  - chain_state.prev_block = block_hash.clone();
  - chain_state.prev_date = Some(blk.get_header().get_blockdate());
  + self.prev_block = block_hash.clone();
  + self.prev_date = Some(blk.get_header().get_blockdate());
  match blk {
  Block::GenesisBlock(blk) => {
  - chain_state.slot_leaders = blk.body.slot_leaders.clone();
  + self.slot_leaders = blk.body.slot_leaders.clone();
  },
  Block::MainBlock(_) => {
  @@ -42,22 +38,18 @@ pub fn verify_block_in_chain(
  res
  }
  -fn do_verify(
  - protocol_magic: ProtocolMagic,
  - chain_state: &mut ChainState,
  - block_hash: &HeaderHash,
  - blk: &Block) -> Result<(), Error>
  + fn do_verify(&self, block_hash: &HeaderHash, blk: &Block) -> Result<(), Error>
  {
  - verify_block(protocol_magic, block_hash, blk)?;
  + verify_block(self.protocol_magic, block_hash, blk)?;
  - if blk.get_header().get_previous_header() != chain_state.prev_block {
  + if blk.get_header().get_previous_header() != self.prev_block {
  return Err(Error::WrongPreviousBlock)
  }
  // Check the block date.
  let date = blk.get_header().get_blockdate();
  - match chain_state.prev_date {
  + match self.prev_date {
  Some(prev_date) => {
  if date <= prev_date {
  return Err(Error::BlockDateInPast)
  @@ -85,11 +77,11 @@ fn do_verify(
  Block::MainBlock(blk) => {
  let slot_id = blk.header.consensus.slot_id.slotid as usize;
  - if slot_id >= chain_state.slot_leaders.len() {
  + if slot_id >= self.slot_leaders.len() {
  return Err(Error::NonExistentSlot)
  }
  - let slot_leader = &chain_state.slot_leaders[slot_id];
  + let slot_leader = &self.slot_leaders[slot_id];
  // Note: the block signature was already checked in
  // verify_block, so here we only check the leader key
  @@ -102,3 +94,5 @@ fn do_verify(
  Ok(())
  }
  +}
  +
  