Added roundtime offset based on contract id. (#238)

This commit is contained in:
Ravin Perera
2021-02-05 17:48:21 +05:30
committed by GitHub
parent c366e8acfa
commit 94eedcaf5b
2 changed files with 7 additions and 1 deletions

View File

@@ -34,6 +34,11 @@ namespace consensus
ctx.stage_time = conf::cfg.contract.roundtime / 4;
ctx.stage_reset_wait_threshold = conf::cfg.contract.roundtime / 10;
// We use a time window boundry offset based on contract id to vary the window boundries between
// different contracts with same round time.
std::hash<std::string> str_hasher;
ctx.round_boundry_offset = str_hasher(conf::cfg.contract.id) % conf::cfg.contract.roundtime;
// Starting consensus processing thread.
ctx.consensus_thread = std::thread(run_consensus);
@@ -306,7 +311,7 @@ namespace consensus
if (ctx.stage == 0)
{
// This gets the start time of current round window. Stage 0 must start in the window after that.
const uint64_t previous_round_start = (((uint64_t)(now / conf::cfg.contract.roundtime)) * conf::cfg.contract.roundtime);
const uint64_t previous_round_start = (((uint64_t)((now - ctx.round_boundry_offset) / conf::cfg.contract.roundtime)) * conf::cfg.contract.roundtime) + ctx.round_boundry_offset;
// Stage 0 must start in the next round window.
// (This makes sure stage 3 gets whichever the remaining time in the round after stages 0,1,2)