proposal.gno
3.09 Kb · 92 lines
1package proposal
2
3import (
4 "errors"
5
6 "gno.land/p/nt/ufmt/v0"
7 valopers "gno.land/r/gnops/valopers"
8 "gno.land/r/gov/dao"
9 sysparams "gno.land/r/sys/params"
10 validators "gno.land/r/sys/validators/v3"
11)
12
13var (
14 ErrValidatorMissing = errors.New("the validator is missing")
15 ErrSameValues = errors.New("the valoper has the same voting power and pubkey")
16)
17
18// NewValidatorProposalRequest creates a proposal request to the GovDAO
19// for adding (or removing) the given valoper to/from the validator set.
20//
21// Signature is preserved for historical-replay compatibility (gnoland-1
22// callers call this with a single address). Body is rewired to call
23// v3's operator-keyed NewValidatorProposalRequest with a single-element
24// slice; v3's executor re-resolves the signing pubkey from valoperCache
25// at execution time, so a mid-flight rotation publishes the current key.
26func NewValidatorProposalRequest(cur realm, addr address) dao.ProposalRequest {
27 var (
28 valoper = valopers.GetByAddr(addr)
29 votingPower = uint64(1)
30 )
31
32 exist := validators.IsValidator(valoper.SigningAddress)
33
34 // Determine the voting power
35 if !valoper.KeepRunning {
36 if !exist {
37 panic(ErrValidatorMissing)
38 }
39 votingPower = uint64(0)
40 }
41
42 if exist {
43 validator := validators.GetValidator(valoper.SigningAddress)
44 if validator.VotingPower == votingPower && validator.PubKey == valoper.SigningPubKey {
45 panic(ErrSameValues)
46 }
47 }
48
49 // Craft the proposal title and description, framed around the
50 // valoper profile. Voters see the operator identity (moniker +
51 // operator address); the signing key is an implementation detail
52 // resolved at execution time by v3's executor.
53 title := ufmt.Sprintf(
54 "Add valoper %s to the valset",
55 valoper.Moniker,
56 )
57
58 description := ufmt.Sprintf("Valoper profile: [%s](/r/gnops/valopers:%s)\n\n%s",
59 valoper.Moniker,
60 valoper.OperatorAddress,
61 valoper.Render(),
62 )
63
64 return validators.NewValidatorProposalRequest(cross(cur),
65 []validators.ValoperChange{validators.NewValoperChange(valoper.OperatorAddress, votingPower)},
66 title,
67 description,
68 )
69}
70
71// ProposeNewInstructionsProposalRequest creates a proposal to the GovDAO
72// for updating the realm instructions.
73func ProposeNewInstructionsProposalRequest(cur realm, newInstructions string) dao.ProposalRequest {
74 cb := valopers.NewInstructionsProposalCallback(newInstructions)
75 // Create a proposal
76 title := "/p/gnops/valopers: Update instructions"
77 description := ufmt.Sprintf("Update the instructions to: \n\n%s", newInstructions)
78
79 e := dao.NewSimpleExecutor(0, cur, cb, "")
80
81 return dao.NewProposalRequest(title, description, e)
82}
83
84// ProposeNewMinFeeProposalRequest creates a proposal to the GovDAO
85// for updating the minimum fee to register a new valoper. Signature
86// preserved for historical-replay compatibility (gnoland-1's
87// set_minfee.gno MsgRun calls this); body now delegates to the
88// generic sys/params factory so the fee lives in
89// node:valoper:register_fee.
90func ProposeNewMinFeeProposalRequest(cur realm, newMinFee int64) dao.ProposalRequest {
91 return sysparams.NewSysParamUint64PropRequest(cross(cur), "node", "valoper", "register_fee", uint64(newMinFee))
92}