mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
feat: shutdown node at upgrade height
This commit is contained in:
parent
6ebd351534
commit
f29e6ddb65
2 changed files with 32 additions and 0 deletions
|
|
@ -355,6 +355,9 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isCon
|
||||||
// Start up the node itself
|
// Start up the node itself
|
||||||
utils.StartNode(ctx, stack, isConsole)
|
utils.StartNode(ctx, stack, isConsole)
|
||||||
|
|
||||||
|
upgradeBlockHeight := uint64(10)
|
||||||
|
utils.ShutdownAtUpgradeBlockHeight(ctx, stack, upgradeBlockHeight)
|
||||||
|
|
||||||
// Unlock any account specifically requested
|
// Unlock any account specifically requested
|
||||||
unlockAccounts(ctx, stack)
|
unlockAccounts(ctx, stack)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,35 @@ func StartNode(ctx *cli.Context, stack *node.Node, isConsole bool) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ShutdownAtUpgradeBlockHeight(ctx *cli.Context, n *node.Node, upgradeBlockHeight uint64) {
|
||||||
|
sub := n.EventMux().Subscribe(core.ChainHeadEvent{})
|
||||||
|
go func() {
|
||||||
|
defer sub.Unsubscribe()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
log.Info("ShutdownAtUpgradeBlockHeight: context cancelled, exiting goroutine")
|
||||||
|
return
|
||||||
|
case ev, ok := <-sub.Chan():
|
||||||
|
if !ok {
|
||||||
|
log.Error("ShutdownAtUpgradeBlockHeight: subscription closed, exiting goroutine")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ch, ok := ev.Data.(core.ChainHeadEvent)
|
||||||
|
if !ok {
|
||||||
|
log.Error("ShutdownAtUpgradeBlockHeight: failed to convert ChainHeadEvent, exiting goroutine")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ch.Block.Number().Uint64() >= upgradeBlockHeight {
|
||||||
|
log.Info("Target upgrade block height reached, initiating shutdown", "block", ch.Block.Number().Uint64())
|
||||||
|
n.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func monitorFreeDiskSpace(sigc chan os.Signal, path string, freeDiskSpaceCritical uint64) {
|
func monitorFreeDiskSpace(sigc chan os.Signal, path string, freeDiskSpaceCritical uint64) {
|
||||||
if path == "" {
|
if path == "" {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue