DWQA QuestionsCategory: BlockchainThe Solution of ETF Code in American Map
FIZLIN asked 2 years ago

I read the consensus using dpos, but I don’t quite understand, what is the meaning of choosing the packer’s code? The code is as follows, know or understand the students, please guide. Source location:

func (ec *EpochContext) lookupValidator(now int64) (validator common.Address, err error) {
    validator = common.Address{}
    Offset: = now% epochInterval /// Why do you do this first? 
    if offset%blockInterval != 0 {
        return common.Address{}, ErrInvalidMintBlockTime
    offset /= blockInterval

    validators, err := ec.DposContext.GetValidators()
    if err != nil {
        return common.Address{}, err
    validatorSize := len(validators)
    if validatorSize == 0 {
        return common.Address{}, errors.New("failed to lookup validator")
    offset %= int64(validatorSize)
    return validators[offset], nil