Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

halt.gno

1.63 Kb · 51 lines
 1package params
 2
 3import (
 4	"strconv"
 5
 6	"chain"
 7	prms "sys/params"
 8
 9	"gno.land/r/gov/dao"
10)
11
12const (
13	nodeModulePrefix  = "node"
14	haltHeightKey     = "halt_height"
15	haltMinVersionKey = "halt_min_version"
16)
17
18// NewSetHaltRequest creates a GovDAO proposal to halt all chain nodes at the given block height.
19// Once approved and executed, nodes will gracefully stop after committing the specified block,
20// enabling coordinated chain upgrades.
21//
22// minVersion, if non-empty, sets the minimum binary version required to resume after the halt.
23// Nodes will refuse to restart unless their version satisfies the minimum requirement,
24// preventing old binaries from accidentally resuming a chain halted for an upgrade.
25// Example: minVersion="chain/gnoland1.1" prevents gnoland1.0 from resuming.
26//
27// Use height=0 to cancel a previously scheduled halt.
28func NewSetHaltRequest(cur realm, height int64, minVersion string) dao.ProposalRequest {
29	callback := func(cur realm) error {
30		prms.SetSysParamInt64(nodeModulePrefix, "p", haltHeightKey, height)
31		prms.SetSysParamString(nodeModulePrefix, "p", haltMinVersionKey, minVersion)
32		chain.Emit("set_halt",
33			"height", strconv.FormatInt(height, 10),
34			"min_version", minVersion,
35		)
36		return nil
37	}
38
39	var desc string
40	if height == 0 {
41		desc = "Cancel the scheduled chain halt and clear the minimum version requirement."
42	} else {
43		desc = "Halt the chain at block " + strconv.FormatInt(height, 10) + "."
44		if minVersion != "" {
45			desc += " Requires binary version >= " + minVersion + " to resume."
46		}
47	}
48
49	e := dao.NewSimpleExecutor(0, cur, callback, "")
50	return dao.NewProposalRequest("Set node halt height", desc, e)
51}