ethereum / sharding

Sharding manager contract, and related software and tests
480 stars 105 forks source link

Asserts in getEligibleProposer don't seem correct #40

Closed jamesray1 closed 6 years ago

jamesray1 commented 6 years ago
def getEligibleProposer(shardId: num, period: num) -> address:
    assert period >= LOOKAHEAD_PERIODS
    assert (period - LOOKAHEAD_PERIODS) * PERIOD_LENGTH < block.number

Shouldn't this be:

assert period <= LOOKAHEAD_PERIODS
assert (LOOKAHEAD_PERIODS - period) * PERIOD_LENGTH > block.number

This is supported by "The function should be able to return a value for the current period or any future period up to LOOKAHEAD_PERIODS periods ahead."

hwwhww commented 6 years ago

Thank you for reviewing!

  1. The input period in the getEligibleProposer actually can be the future period we want to know.
  2. The goal is creating a time window for the caller knowing who is the eligible proposer LOOKAHEAD_PERIODS periods ahead, it implies that the eligible proposer of the current period cannot be sampled before LOOKAHEAD_PERIODS periods. So if I'm a validator, current_block_number is 25, current_period is 5, and LOOKAHEAD_PERIODS is 4. Then the validator uses message call to call getEligibleProposer with period = current_period + LOOKAHEAD_PERIODS = 5 + 4 = 9.

This line is for making sure that we already have enough block.number to sample the collator of the given future period.

assert (period - LOOKAHEAD_PERIODS) * PERIOD_LENGTH < block.number
assert (9 - 4) * 5 < 26
jamesray1 commented 6 years ago

OK, thanks for clarifying!