-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sequencer auto recover when meet an unexpected shutdown (#166)
Co-authored-by: Owen <103096885+owen-reorg@users.noreply.github.com>
- Loading branch information
1 parent
1770748
commit 215dee2
Showing
7 changed files
with
221 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package miner | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
|
||
"github.com/ethereum/go-ethereum/beacon/engine" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/log" | ||
) | ||
|
||
// StateFixManager manages the fix operation state and notification mechanism. | ||
type StateFixManager struct { | ||
mutex sync.Mutex // Protects access to fix state | ||
} | ||
|
||
// NewFixManager initializes a FixManager with required dependencies | ||
func NewFixManager() *StateFixManager { | ||
return &StateFixManager{} | ||
} | ||
|
||
// StartFix launches a goroutine to manage the fix process and tracks the fix state. | ||
func (fm *StateFixManager) StartFix(worker *worker, id engine.PayloadID, parentHash common.Hash) error { | ||
fm.mutex.Lock() | ||
defer fm.mutex.Unlock() | ||
|
||
log.Info("Fix is in progress for the block", "id", id) | ||
|
||
err := worker.fix(parentHash) | ||
if err != nil { | ||
log.Error("Fix process failed", "error", err) | ||
return err | ||
} | ||
|
||
log.Info("Fix process completed successfully", "id", id) | ||
return nil | ||
} | ||
|
||
// RecoverFromLocal attempts to recover the block and MPT data from the local chain. | ||
// | ||
// blockHash: The latest header(unsafe block) hash of the block to recover. | ||
func (fm *StateFixManager) RecoverFromLocal(w *worker, blockHash common.Hash) error { | ||
block := w.chain.GetBlockByHash(blockHash) | ||
if block == nil { | ||
return fmt.Errorf("block not found in local chain") | ||
} | ||
|
||
log.Info("Fixing data for block", "block number", block.NumberU64()) | ||
latestValid, err := w.chain.RecoverStateAndSetHead(block) | ||
if err != nil { | ||
return fmt.Errorf("failed to recover state: %v", err) | ||
} | ||
|
||
log.Info("Recovered states up to block", "latestValid", latestValid) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters