mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-12 23:13:45 +00:00
fix: revert cancel active seal logic
This commit is contained in:
parent
7ee88de5ab
commit
767fe584b5
4 changed files with 7 additions and 58 deletions
|
|
@ -127,12 +127,6 @@ var (
|
||||||
errRecentlySigned = errors.New("recently signed")
|
errRecentlySigned = errors.New("recently signed")
|
||||||
)
|
)
|
||||||
|
|
||||||
// ActiveSealingOp keeps the context of the active sealing operation
|
|
||||||
type ActiveSealingOp struct {
|
|
||||||
number uint64
|
|
||||||
cancel context.CancelFunc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SignerFn is a signer callback function to request a header to be signed by a
|
// SignerFn is a signer callback function to request a header to be signed by a
|
||||||
// backing account.
|
// backing account.
|
||||||
type SignerFn func(accounts.Account, string, []byte) ([]byte, error)
|
type SignerFn func(accounts.Account, string, []byte) ([]byte, error)
|
||||||
|
|
@ -238,9 +232,8 @@ type Bor struct {
|
||||||
stateReceiverABI abi.ABI
|
stateReceiverABI abi.ABI
|
||||||
HeimdallClient IHeimdallClient
|
HeimdallClient IHeimdallClient
|
||||||
|
|
||||||
stateDataFeed event.Feed
|
stateDataFeed event.Feed
|
||||||
scope event.SubscriptionScope
|
scope event.SubscriptionScope
|
||||||
activeSealingOp *ActiveSealingOp
|
|
||||||
// The fields below are for testing only
|
// The fields below are for testing only
|
||||||
fakeDiff bool // Skip difficulty verifications
|
fakeDiff bool // Skip difficulty verifications
|
||||||
}
|
}
|
||||||
|
|
@ -728,9 +721,6 @@ func (c *Bor) Authorize(signer common.Address, signFn SignerFn) {
|
||||||
// Seal implements consensus.Engine, attempting to create a sealed block using
|
// Seal implements consensus.Engine, attempting to create a sealed block using
|
||||||
// the local signing credentials.
|
// the local signing credentials.
|
||||||
func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error {
|
func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error {
|
||||||
// if c.activeSealingOp != nil {
|
|
||||||
// return &SealingInFlightError{c.activeSealingOp.number}
|
|
||||||
// }
|
|
||||||
header := block.Header()
|
header := block.Header()
|
||||||
|
|
||||||
// Sealing the genesis block is not supported
|
// Sealing the genesis block is not supported
|
||||||
|
|
@ -777,17 +767,12 @@ func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan
|
||||||
|
|
||||||
// Wait until sealing is terminated or delay timeout.
|
// Wait until sealing is terminated or delay timeout.
|
||||||
log.Trace("Waiting for slot to sign and propagate", "delay", common.PrettyDuration(delay))
|
log.Trace("Waiting for slot to sign and propagate", "delay", common.PrettyDuration(delay))
|
||||||
shouldSeal := make(chan bool)
|
|
||||||
go c.WaitForSealingOp(number, shouldSeal, delay, stop)
|
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
select {
|
||||||
close(shouldSeal)
|
case <-stop:
|
||||||
c.activeSealingOp = nil
|
log.Debug("Discarding sealing operation for block", "number", number)
|
||||||
}()
|
|
||||||
switch <-shouldSeal {
|
|
||||||
case false:
|
|
||||||
return
|
return
|
||||||
case true:
|
case <-time.After(delay):
|
||||||
if wiggle > 0 {
|
if wiggle > 0 {
|
||||||
log.Info(
|
log.Info(
|
||||||
"Sealing out-of-turn",
|
"Sealing out-of-turn",
|
||||||
|
|
@ -803,38 +788,15 @@ func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan
|
||||||
"headerDifficulty", header.Difficulty,
|
"headerDifficulty", header.Difficulty,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case results <- block.WithSeal(header):
|
case results <- block.WithSeal(header):
|
||||||
default:
|
default:
|
||||||
log.Warn("Sealing result was not read by miner", "sealhash", SealHash(header))
|
log.Warn("Sealing result was not read by miner", "number", number, "sealhash", SealHash(header))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitForSealingOp blocks until delay elapses or stop signal is received
|
|
||||||
func (c *Bor) WaitForSealingOp(number uint64, shouldSeal chan bool, delay time.Duration, stop <-chan struct{}) {
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
c.activeSealingOp = &ActiveSealingOp{number, cancel}
|
|
||||||
select {
|
|
||||||
case <-stop:
|
|
||||||
shouldSeal <- false
|
|
||||||
case <-ctx.Done():
|
|
||||||
shouldSeal <- false
|
|
||||||
case <-time.After(delay):
|
|
||||||
shouldSeal <- true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CancelActiveSealingOp cancels in-flight sealing process
|
|
||||||
func (c *Bor) CancelActiveSealingOp() {
|
|
||||||
if c.activeSealingOp != nil {
|
|
||||||
log.Debug("Discarding active sealing operation", "number", c.activeSealingOp.number)
|
|
||||||
c.activeSealingOp.cancel()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
|
// 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
|
// that a new block should have based on the previous blocks in the chain and the
|
||||||
// current signer.
|
// current signer.
|
||||||
|
|
|
||||||
|
|
@ -69,17 +69,6 @@ func (e *MaxCheckpointLengthExceededError) Error() string {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
type SealingInFlightError struct {
|
|
||||||
Number uint64
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *SealingInFlightError) Error() string {
|
|
||||||
return fmt.Sprintf(
|
|
||||||
"Requested concurrent block sealing. Sealing for block %d is already in progress",
|
|
||||||
e.Number,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MismatchingValidatorsError is returned if a last block in sprint contains a
|
// MismatchingValidatorsError is returned if a last block in sprint contains a
|
||||||
// list of validators different from the one that local node calculated
|
// list of validators different from the one that local node calculated
|
||||||
type MismatchingValidatorsError struct {
|
type MismatchingValidatorsError struct {
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,6 @@ type Engine interface {
|
||||||
type Bor interface {
|
type Bor interface {
|
||||||
Engine
|
Engine
|
||||||
IsValidatorAction(chain ChainReader, from common.Address, tx *types.Transaction) bool
|
IsValidatorAction(chain ChainReader, from common.Address, tx *types.Transaction) bool
|
||||||
CancelActiveSealingOp()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PoW is a consensus engine based on proof-of-work.
|
// PoW is a consensus engine based on proof-of-work.
|
||||||
|
|
|
||||||
|
|
@ -1718,7 +1718,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
|
||||||
if lastCanon != nil && bc.CurrentBlock().Hash() == lastCanon.Hash() {
|
if lastCanon != nil && bc.CurrentBlock().Hash() == lastCanon.Hash() {
|
||||||
events = append(events, ChainHeadEvent{lastCanon})
|
events = append(events, ChainHeadEvent{lastCanon})
|
||||||
}
|
}
|
||||||
bc.engine.(consensus.Bor).CancelActiveSealingOp()
|
|
||||||
return it.index, events, coalescedLogs, err
|
return it.index, events, coalescedLogs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue