diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 1b693f75b3..31fe4d905e 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -652,7 +652,9 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, stop <-ch return block.WithSeal(header), nil } -// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have. +// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty +// that a new block should have based on the previous blocks in the chain and the +// current signer. func (c *Clique) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int { snap, err := c.snapshot(chain, parent.Number.Uint64(), parent.Hash(), nil) if err != nil { @@ -661,7 +663,9 @@ func (c *Clique) CalcDifficulty(chain consensus.ChainReader, time uint64, parent return CalcDifficulty(snap, c.signer) } -// CalcDifficulty returns block difficulty according to local signer is the inturn signer or not. +// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty +// that a new block should have based on the previous blocks in the chain and the +// current signer. func CalcDifficulty(snap *Snapshot, signer common.Address) *big.Int { if snap.inturn(snap.Number+1, signer) { return new(big.Int).Set(diffInTurn) diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 34f73d1f42..ab4acf8ec2 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -291,7 +291,9 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainReader, time uint64, p return CalcDifficulty(chain.Config(), time, parent) } -// CalcDifficulty returns block difficulty according to the parent block's time and difficulty. +// CalcDifficulty is the difficulty adjustment algorithm. It returns +// the difficulty that a new block should have when created at time +// given the parent block's time and difficulty. func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int { next := new(big.Int).Add(parent.Number, big1) switch { diff --git a/core/chain_makers.go b/core/chain_makers.go index d107add59c..0e5e3791e5 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -164,8 +164,11 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse } blocks, receipts := make(types.Blocks, n), make([]types.Receipts, n) genblock := func(i int, parent *types.Block, statedb *state.StateDB) (*types.Block, types.Receipts) { + // TODO(karalabe): This is needed for clique, which depends on multiple blocks. + // It's nonetheless ugly to spin up a blockchain here. Get rid of this somehow. blockchain, _ := NewBlockChain(db, config, engine, vm.Config{}) defer blockchain.Stop() + b := &BlockGen{i: i, parent: parent, chain: blocks, chainReader: blockchain, statedb: statedb, config: config, engine: engine} b.header = makeHeader(b.chainReader, parent, statedb, b.engine)