witnet / witnet-rust

Open source Rust implementation of the Witnet decentralized oracle protocol, including full node and wallet backend 👁️🦀
https://docs.witnet.io
GNU General Public License v3.0
180 stars 56 forks source link

feat(mining): reset collateral age of the validator which mined the latest block #2457

Closed drcpu-github closed 4 months ago

drcpu-github commented 4 months ago

I think this is the only spot where we need to reset the collateral age of the validator which mined a block. I am not entirely happy with using self.current_epoch.unwrap_or_default(), but it should be safe since we would not get here if current_epoch was None.

aesedepece commented 4 months ago

I think this is the only spot where we need to reset the collateral age of the validator which mined a block. I am not entirely happy with using self.current_epoch.unwrap_or_default(), but it should be safe since we would not get here if current_epoch was None.

Agreed, it should be fine.

If you want some more peace of mind, a statement like the one around L936 near the start of the function should do it:


let current_epoch = if let Some(epoch) = self.current_epoch {
  epoch
} else {
  return;
}