faker1
V2EX  ›  问与答

美图的以太坊代码释义

  •  1
     
  •   faker1 · Jan 16, 2019 · 1148 views
    This topic created in 2682 days ago, the information mentioned may be changed or developed.

    看了下共识使用了 dpos,但是我不太懂,选择打包者这块的代码是什么意思? 代码如下, 知道或者看懂的同学,请指导下(谢谢). 源码位置: https://github.com/meitu/go-ethereum/blob/6be4cd4b94f22b2cea34086bf0aa9752dd4ebf15/consensus/dpos/epoch_context.go#L129.

    func (ec *EpochContext) lookupValidator(now int64) (validator common.Address, err error) {
        validator = common.Address{}
        offset := now % epochInterval  // 这个为什么要先这个样子做, 
        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
    }
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5417 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 03:44 · PVG 11:44 · LAX 20:44 · JFK 23:44
    ♥ Do have faith in what you're doing.