Module darkfi::validator::utils

source ·
Expand description

Helper utilities

Functions§

  • Auxiliary function to find best ranked fork. The best ranked fork is the one with the highest sum of its blocks squared mining target distances, from max 32 bytes int. In case of a tie, the fork with the highest sum of its blocks squared RandomX hash number distances, from max 32 bytes int, wins.
  • Compute a block’s rank, assuming that its valid, based on provided mining target. Block’s rank is the tuple of its squared mining target distance from max 32 bytes int, along with its squared RandomX hash number distance from max 32 bytes int. Genesis block has rank (0, 0).
  • Deploy DarkFi native wasm contracts to provided blockchain overlay. If overlay already contains the contracts, it will just open the necessary db and trees, and give back what it has. This means that on subsequent runs, our native contracts will already be in a deployed state, so what we actually do here is a redeployment. This kind of operation should only modify the contract’s state in case it wasn’t deployed before (meaning the initial run). Otherwise, it shouldn’t touch anything, or just potentially update the db schemas or whatever is necessary. This logic should be handled in the init function of the actual contract, so make sure the native contracts handle this well.
  • Given a proposal, find the index of a fork chain it extends, along with the specific extended proposal index. Additionally, check that proposal doesn’t already exists in any fork chain.
  • Auxiliary function to calculate the middle value between provided u64 numbers
  • Auxiliary function to calculate the median of a given Vec<u64>. The function sorts the vector internally.