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)

View File

@@ -71,6 +71,7 @@ namespace consensus
uint64_t round_start_time = 0;
uint16_t stage_time = 0; // Time allocated to a consensus stage.
uint16_t stage_reset_wait_threshold = 0; // Minimum stage wait time to reset the stage.
uint64_t round_boundry_offset = 0; // Time window boundry offset based on contract id.
std::optional<sc::execution_context> contract_ctx;
std::mutex contract_ctx_mutex;