Skip to content
4 changes: 4 additions & 0 deletions consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ func (beacon *Beacon) SetThreads(threads int) {
}
}

func (p *Beacon) DropOnNewBlock(*types.Header) bool {
return true
}

// IsTTDReached checks if the TotalTerminalDifficulty has been surpassed on the `parentHash` block.
// It depends on the parentHash already being stored in the database.
// If the parentHash is not stored in the database a UnknownAncestor error is returned.
Expand Down
5 changes: 5 additions & 0 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,11 @@ func (c *Clique) APIs(chain consensus.ChainHeaderReader) []rpc.API {
}}
}

func (p *Clique) DropOnNewBlock(header *types.Header) bool {
// drop the block if it is not in turn.
return header.Difficulty.Cmp(diffNoTurn) == 0
}

// SealHash returns the hash of a block prior to it being sealed.
func SealHash(header *types.Header) (hash common.Hash) {
hasher := sha3.NewLegacyKeccak256()
Expand Down
6 changes: 6 additions & 0 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ type Engine interface {

// Close terminates any background threads maintained by the consensus engine.
Close() error

// DropOnNewBlock determine the action of mining when it is interrupted by new imported block.
// Return
// true: the mining result will be dropped
// false: the mining result will be kept and move on to the next mine step.
DropOnNewBlock(header *types.Header) bool
}

// PoW is a consensus engine based on proof-of-work.
Expand Down
4 changes: 4 additions & 0 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ var (
big32 = big.NewInt(32)
)

func (p *Ethash) DropOnNewBlock(*types.Header) bool {
return true
}

// AccumulateRewards credits the coinbase of the given block with the mining
// reward. The total reward consists of the static block reward and rewards for
// included uncles. The coinbase of each uncle block is also rewarded.
Expand Down
14 changes: 8 additions & 6 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,6 @@ func (p *Parlia) Delay(chain consensus.ChainReader, header *types.Header) *time.
return nil
}
delay := p.delayForRamanujanFork(snap, header)
// The blocking time should be no more than half of period
half := time.Duration(p.config.Period) * time.Second / 2
if delay > half {
delay = half
}
return &delay
}

Expand Down Expand Up @@ -852,7 +847,9 @@ func (p *Parlia) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
// Sweet, the protocol permits us to sign the block, wait for our time
delay := p.delayForRamanujanFork(snap, header)

log.Info("Sealing block with", "number", number, "delay", delay, "headerDifficulty", header.Difficulty, "val", val.Hex())
log.Info("Sealing block with", "number", number, "delay", delay,
"header.Time Second", time.Unix(int64(header.Time), 0).Second(),
"headerDifficulty", header.Difficulty, "val", val.Hex())

// Sign all the things!
sig, err := signFn(accounts.Account{Address: val}, accounts.MimetypeParlia, ParliaRLP(header, p.chainConfig.ChainID))
Expand Down Expand Up @@ -964,6 +961,11 @@ func (p *Parlia) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64,
return CalcDifficulty(snap, p.val)
}

func (p *Parlia) DropOnNewBlock(header *types.Header) bool {
// drop the block if it is not in turn.
return header.Difficulty.Cmp(diffNoTurn) == 0
}

// 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.
Expand Down
2 changes: 1 addition & 1 deletion eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var Defaults = Config{
GasCeil: 8000000,
GasPrice: big.NewInt(params.GWei),
Recommit: 3 * time.Second,
DelayLeftOver: 50 * time.Millisecond,
DelayLeftOver: 400 * time.Millisecond,
},
TxPool: core.DefaultTxPoolConfig,
RPCGasCap: 50000000,
Expand Down
Loading