halt.gno
2.17 Kb · 59 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="v1.3.0" prevents a v1.2.0 binary from resuming.
26//
27// minVersion must be a release tag the node can parse: vMAJOR.MINOR.PATCH, or
28// betanet's retired chain/gnolandMAJOR.MINOR. It is NOT the chain's launch tag —
29// naming "chain/mainnet" here parses as nothing, so the comparison degrades to
30// byte equality and refuses the upgraded binary alongside the stale ones, leaving
31// the chain unable to restart. This function does not check the shape; the release
32// tooling does. See RELEASING.md and gno.land/cmd/gnoland/UPGRADES.md, and prefer
33// misc/govdao-scripts/set-halt.sh over writing the call by hand.
34//
35// Use height=0 to cancel a previously scheduled halt.
36func NewSetHaltRequest(cur realm, height int64, minVersion string) dao.ProposalRequest {
37 callback := func(cur realm) error {
38 prms.SetSysParamInt64(nodeModulePrefix, "p", haltHeightKey, height)
39 prms.SetSysParamString(nodeModulePrefix, "p", haltMinVersionKey, minVersion)
40 chain.Emit("set_halt",
41 "height", strconv.FormatInt(height, 10),
42 "min_version", minVersion,
43 )
44 return nil
45 }
46
47 var desc string
48 if height == 0 {
49 desc = "Cancel the scheduled chain halt and clear the minimum version requirement."
50 } else {
51 desc = "Halt the chain at block " + strconv.FormatInt(height, 10) + "."
52 if minVersion != "" {
53 desc += " Requires binary version >= " + minVersion + " to resume."
54 }
55 }
56
57 e := dao.NewSimpleExecutor(0, cur, callback, "")
58 return dao.NewProposalRequest("Set node halt height", desc, e)
59}