faker1
V2EX  ›  问与答

美图的以太坊代码释义

  •  1
     
  •   faker1 · Jan 16, 2019 · 1176 views
    This topic created in 2699 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   ·   1052 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 18:05 · PVG 02:05 · LAX 11:05 · JFK 14:05
    ♥ Do have faith in what you're doing.