Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add r/sys/params + params genesis support #3003

Merged
merged 90 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
b930513
feat(tm2/sdk/params): initial version
moul Oct 7, 2024
602245d
feat: inject ParamsKeeper in VMKeeper
moul Oct 9, 2024
783a044
feat: configure params in gno.land
moul Oct 10, 2024
072aa12
Merge branch 'master' into dev/moul/mod-params
moul Oct 20, 2024
89e046c
chore: remove unused param
moul Oct 21, 2024
5d1e36a
chore: disable --flag-config-path
moul Oct 21, 2024
e5a869d
Merge branch 'master' into dev/moul/mod-params
moul Oct 21, 2024
581ef26
chore: fixup
moul Oct 21, 2024
a39d172
chore: fixup
moul Oct 21, 2024
0342b61
chore: fixup
moul Oct 21, 2024
dd8ca08
chore: remove vmkeeper.maxcycles
moul Oct 21, 2024
e573b6a
chore: fixup
moul Oct 21, 2024
993d213
chore: fixup
moul Oct 21, 2024
ee8c778
Merge branch 'dev/moul/remove-max-cycles' into dev/moul/mod-params
moul Oct 21, 2024
95384ae
chore: fixup
moul Oct 22, 2024
a4608eb
chore: fixup
moul Oct 22, 2024
9f18bad
chore: rename config -> param
moul Oct 22, 2024
5ba066e
chore: fixup
moul Oct 22, 2024
4e097fc
Merge remote-tracking branch 'origin/master' into dev/moul/mod-params
moul Oct 22, 2024
5260059
chore: ignore generated files from codecov
moul Oct 22, 2024
309806f
chore: fixup
moul Oct 22, 2024
911c27f
Merge branch 'master' into dev/moul/mod-params
moul Oct 22, 2024
94cf1a4
Merge remote-tracking branch 'origin/master' into dev/moul/mod-params
moul Oct 22, 2024
604466c
chore: fixup
moul Oct 22, 2024
8c5b00a
chore: fixup
moul Oct 22, 2024
4a1c0bb
chore: fixup
moul Oct 22, 2024
86b4fbd
chore: fixup
moul Oct 22, 2024
61839a8
feat: add r/sys/params + params genesis support
moul Oct 22, 2024
be58b92
Merge branch 'dev/moul/mod-params' into dev/moul/r/sys/params
moul Oct 22, 2024
bf94222
chore: fixup
moul Oct 22, 2024
902eb9c
chore: fixup
moul Oct 23, 2024
f4eb4c5
Merge branch 'dev/moul/mod-params' into dev/moul/r/sys/params
moul Oct 23, 2024
cb57a8f
chore: fixup
moul Oct 23, 2024
74025b5
chore: fixup
moul Oct 23, 2024
8f52428
chore: fixup
moul Oct 23, 2024
d38c6b8
chore: fixup
moul Oct 23, 2024
dc37fe0
chore: fixup
moul Oct 23, 2024
4f7c4eb
Merge branch 'dev/moul/mod-params' into dev/moul/r/sys/params
moul Oct 23, 2024
a166760
chore: fixup
moul Oct 23, 2024
e7840ff
chore: fixup
moul Oct 23, 2024
aaa88b6
Merge remote-tracking branch 'origin/master' into dev/moul/r/sys/params
moul Oct 23, 2024
f382771
chore: fixup
moul Oct 23, 2024
d92a959
chore: fixup
moul Oct 23, 2024
2c4c979
chore: fixup
moul Oct 23, 2024
abf1704
chore: fixup
moul Oct 23, 2024
83eae8d
chore: fixup
moul Oct 23, 2024
672fb97
chore: fixup
moul Oct 23, 2024
95c975d
chore: fixup
moul Oct 23, 2024
529c91f
Merge remote-tracking branch 'origin/master' into dev/moul/r/sys/params
moul Oct 23, 2024
9bc2f6e
chore: fixup
moul Oct 23, 2024
af5b313
chore: fixup
moul Oct 23, 2024
9b23068
chore: fixup
moul Oct 24, 2024
f6fc9ae
chore: fixup
moul Oct 24, 2024
18944a2
chore: fixup
moul Oct 24, 2024
9b8958a
chore: fixup
moul Oct 24, 2024
888dfa9
chore: fixup
moul Oct 24, 2024
fcafaed
chore: fixup
moul Oct 24, 2024
e24c553
Merge remote-tracking branch 'origin/master' into dev/moul/r/sys/params
moul Oct 24, 2024
21a3983
chore: fixup
moul Oct 24, 2024
6ab560e
chore: fixup
moul Oct 24, 2024
1dc779b
chore: fixup
moul Oct 25, 2024
5ddb4cb
chore: fixup
moul Oct 25, 2024
4ebb76c
chore: fixup
moul Oct 25, 2024
065842b
chore: fixup
moul Oct 25, 2024
fc3d149
chore: fixup
moul Oct 26, 2024
3ad7ffa
chore: fixup
moul Oct 26, 2024
2eea867
chore: fixup
moul Oct 26, 2024
ae0bd03
chore: fixup
moul Oct 26, 2024
cef75f6
chore: fixup
moul Oct 26, 2024
3d128b4
Merge remote-tracking branch 'origin/master' into dev/moul/r/sys/params
moul Oct 26, 2024
b00abbe
Merge remote-tracking branch 'origin/master' into dev/moul/r/sys/params
moul Oct 31, 2024
12f0140
chore: fixup
moul Oct 31, 2024
ac774bd
chore: fixup
moul Oct 31, 2024
f70a2e0
chore(gno): intended json on filetests's Events: directives
moul Oct 31, 2024
3cce575
Merge branch 'dev/moul/filetest-events-indent' into dev/moul/r/sys/pa…
moul Oct 31, 2024
f9c6d0c
chore: fixup
moul Oct 31, 2024
d31d255
chore: fixup
moul Oct 31, 2024
734157f
Merge branch 'master' into dev/moul/r/sys/params
moul Oct 31, 2024
a9b4429
Merge branch 'master' into dev/moul/r/sys/params
moul Nov 5, 2024
cf701d7
Merge branch 'master' into dev/moul/r/sys/params
thehowl Nov 8, 2024
9ce3bd4
chore: fixup
moul Nov 8, 2024
187d1e5
chore: fixup
moul Nov 9, 2024
0a3ea0e
chore: fixup
moul Nov 9, 2024
23f8ce2
chore: fixup
moul Nov 9, 2024
81a3f56
chore: fixup
moul Nov 9, 2024
6c47366
chore: fixup
moul Nov 9, 2024
fbf4fdb
chore: fixup
moul Nov 9, 2024
6d99f19
chore: fixup
moul Nov 9, 2024
15bacef
Merge branch 'master' into dev/moul/r/sys/params
moul Nov 12, 2024
1ce1a27
Merge branch 'master' into dev/moul/r/sys/params
moul Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions examples/gno.land/r/gov/dao/prop2_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ func init() {
}

mExec := govdao.NewPropExecutor(membersFn)

comment := "adding someone to vote"

id := govdao.Propose(comment, mExec)

govdao.ExecuteProposal(id)

executor := proposal.NewCtxExecutor(func(ctx context.Context) error {
Expand Down
95 changes: 95 additions & 0 deletions examples/gno.land/r/gov/dao/prop3_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package main

import (
"std"

govdao "gno.land/r/gov/dao"
"gno.land/r/sys/params"
)

func init() {
{ // prop0
membersFn := func() []std.Address {
return []std.Address{
std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"),
}
}
mExec := govdao.NewPropExecutor(membersFn)
comment := "adding someone to vote"
id := govdao.Propose(comment, mExec)
govdao.ExecuteProposal(id)
}

{ // prop1
mExec := params.NewStringPropExecutor("prop1.string", "value1")
comment := "setting prop1.string param"
id := govdao.Propose(comment, mExec)
}

{ // prop2
mExec := params.NewInt64PropExecutor("prop2.int64", 12345)
comment := "setting prop2.int64 param"
id := govdao.Propose(comment, mExec)
}
}

func main() {
println("--")
println(govdao.Render(""))
println("--")
println(govdao.Render("1"))
println("--")
govdao.VoteOnProposal(1, "YES")
println("--")
println(govdao.Render("1"))
println("--")
govdao.ExecuteProposal(1)
println("--")
println(govdao.Render("1"))
}

// Events:
// [{"type":"set","attrs":[{"key":"k","value":"prop1.string"}],"pkg_path":"gno.land/r/sys/params","func":""}]

// Output:
// --
// - [0](/r/gov/dao:0) - adding someone to vote (**succeeded**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
// - [1](/r/gov/dao:1) - setting prop1.string param (**active**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
// - [2](/r/gov/dao:2) - setting prop2.int64 param (**active**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
//
// --
// # Prop #1
//
// setting prop1.string param
//
// Status: active
//
// Voting status: YES: 0, NO: 0, percent: 0, members: 1
//
// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
//
//
// --
// --
// # Prop #1
//
// setting prop1.string param
//
// Status: accepted
//
// Voting status: YES: 1, NO: 0, percent: 100, members: 1
//
// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
//
//
// --
// --
// # Prop #1
//
// setting prop1.string param
//
// Status: succeeded
//
// Voting status: YES: 1, NO: 0, percent: 100, members: 1
//
// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
3 changes: 3 additions & 0 deletions examples/gno.land/r/sys/params/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module gno.land/r/sys/params

require gno.land/p/gov/proposal v0.0.0-latest
43 changes: 43 additions & 0 deletions examples/gno.land/r/sys/params/params.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package params
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved

import (
"std"

"gno.land/p/gov/proposal"
)

const daoPkgPath = "gno.land/r/gov/dao"

func NewStringPropExecutor(key string, value string) proposal.Executor {
return newPropExecutor(key, func() { std.SetParamString(key, value) })
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
}

func NewInt64PropExecutor(key string, value int64) proposal.Executor {
return newPropExecutor(key, func() { std.SetParamInt64(key, value) })
}

func NewUint64PropExecutor(key string, value uint64) proposal.Executor {
return newPropExecutor(key, func() { std.SetParamUint64(key, value) })
}

func NewBoolPropExecutor(key string, value bool) proposal.Executor {
return newPropExecutor(key, func() { std.SetParamBool(key, value) })
}

func NewBytesPropExecutor(key string, value []byte) proposal.Executor {
return newPropExecutor(key, func() { std.SetParamBytes(key, value) })
}

func newPropExecutor(key string, fn func()) proposal.Executor {
callback := func() error {
if std.PrevRealm().PkgPath() != daoPkgPath {
panic("should be executed from govdao")
}
std.Emit("set",
"k", key,
)
fn()
return nil
}
return proposal.NewExecutor(callback)
}
14 changes: 14 additions & 0 deletions gno.land/cmd/gnoland/testdata/genesis_params.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# test for https://github.com/gnolang/gno/pull/3003

gnoland start

gnokey query params/vm/gno.land/r/sys/params.test.foo.string
stdout 'data: "bar"$'
gnokey query params/vm/gno.land/r/sys/params.test.foo.int64
stdout 'data: "-1337"'
gnokey query params/vm/gno.land/r/sys/params.test.foo.uint64
stdout 'data: "42"'
gnokey query params/vm/gno.land/r/sys/params.test.foo.bool
stdout 'data: true'
# XXX: bytes
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved

29 changes: 29 additions & 0 deletions gno.land/genesis/genesis_params.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

## gno.land
["gno.land/r/sys/params.sys"]
users_pkgpath.string = "gno.land/r/sys/users" # if empty, no namespace support.
# TODO: validators_pkgpath.string = "gno.land/r/sys/validators"
# TODO: rewards_pkgpath.string = "gno.land/r/sys/rewards"
# TODO: token_lock.bool = true

## gnovm
["gno.land/r/sys/params.vm"]
# TODO: chain_domain.string = "gno.land"
# TODO: max_gas.int64 = 100_000_000
# TODO: chain_tz.string = "UTC"
# TODO: default_storage_allowance.string = ""

## tm2
["gno.land/r/sys/params.tm2"]

## misc
["gno.land/r/sys/params.mix"]

## testing
# do not remove these lines. they are needed for a txtar integration test.
["gno.land/r/sys/params.test"]
foo.string = "bar"
foo.int64 = -1337
foo.uint64 = 42
foo.bool = true
#foo.bytes = todo
8 changes: 7 additions & 1 deletion gno.land/pkg/gnoland/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (cfg InitChainerConfig) loadAppState(ctx sdk.Context, appState any) ([]abci
return nil, fmt.Errorf("invalid AppState of type %T", appState)
}

// Parse and set genesis state balances
// Apply genesis balances.
for _, bal := range state.Balances {
acc := cfg.acctKpr.NewAccountWithAddress(ctx, bal.Address)
cfg.acctKpr.SetAccount(ctx, acc)
Expand All @@ -300,6 +300,12 @@ func (cfg InitChainerConfig) loadAppState(ctx sdk.Context, appState any) ([]abci
}
}

// Apply genesis params.
for _, param := range state.Params {
param.Register(ctx, cfg.paramsKpr)
}

// Replay genesis txs.
txResponses := make([]abci.ResponseDeliverTx, 0, len(state.Txs))
// Run genesis txs
for _, tx := range state.Txs {
Expand Down
28 changes: 28 additions & 0 deletions gno.land/pkg/gnoland/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ func TestNewAppWithOptions(t *testing.T) {
Signatures: []std.Signature{{}}, // one empty signature
},
},
Params: []Param{
{key: "foo", kind: "string", value: "hello"},
{key: "foo", kind: "int64", value: int64(-42)},
{key: "foo", kind: "uint64", value: uint64(1337)},
{key: "foo", kind: "bool", value: true},
{key: "foo", kind: "bytes", value: []byte{0x48, 0x69, 0x21}},
},
},
})
require.True(t, resp.IsOK(), "InitChain response: %v", resp)
Expand All @@ -84,6 +91,27 @@ func TestNewAppWithOptions(t *testing.T) {
Tx: tx,
})
require.True(t, dtxResp.IsOK(), "DeliverTx response: %v", dtxResp)

cres := bapp.Commit()
require.NotNil(t, cres)

tcs := []struct {
path string
expectedVal string
}{
{"params/vm/foo.string", `"hello"`},
{"params/vm/foo.int64", `"-42"`},
{"params/vm/foo.uint64", `"1337"`},
{"params/vm/foo.bool", `true`},
{"params/vm/foo.bytes", `"SGkh"`}, // XXX: make this test more readable
}
for _, tc := range tcs {
qres := bapp.Query(abci.RequestQuery{
Path: tc.path,
})
require.True(t, qres.IsOK())
assert.Equal(t, qres.Data, []byte(tc.expectedVal))
}
}

func TestNewAppWithOptions_ErrNoDB(t *testing.T) {
Expand Down
37 changes: 37 additions & 0 deletions gno.land/pkg/gnoland/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"github.com/gnolang/gno/tm2/pkg/crypto"
osm "github.com/gnolang/gno/tm2/pkg/os"
"github.com/gnolang/gno/tm2/pkg/std"
"github.com/pelletier/go-toml"
)

// LoadGenesisBalancesFile loads genesis balances from the provided file path.
Expand Down Expand Up @@ -58,6 +59,42 @@
return balances, nil
}

// LoadGenesisParamsFile loads genesis params from the provided file path.
func LoadGenesisParamsFile(path string) ([]Param, error) {
// each param is in the form: key.kind=value
content := osm.MustReadFile(path)
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved

m := map[string] /*category*/ map[string] /*key*/ map[string] /*kind*/ interface{} /*value*/ {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type Category, Key, Kind = string, string, string

map[Category]map[Key]map[Kind]interface{}

err := toml.Unmarshal(content, &m)
if err != nil {
return nil, err
}

Check warning on line 71 in gno.land/pkg/gnoland/genesis.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/genesis.go#L63-L71

Added lines #L63 - L71 were not covered by tests

params := make([]Param, 0)
for category, keys := range m {
for key, kinds := range keys {
for kind, val := range kinds {
param := Param{
key: category + "." + key,
kind: kind,
}
switch kind {
case "uint64": // toml
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
param.value = uint64(val.(int64))
default:
param.value = val

Check warning on line 85 in gno.land/pkg/gnoland/genesis.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/genesis.go#L73-L85

Added lines #L73 - L85 were not covered by tests
}
if err := param.Verify(); err != nil {
return nil, err
}
params = append(params, param)

Check warning on line 90 in gno.land/pkg/gnoland/genesis.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/genesis.go#L87-L90

Added lines #L87 - L90 were not covered by tests
}
}
}

return params, nil

Check warning on line 95 in gno.land/pkg/gnoland/genesis.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/genesis.go#L95

Added line #L95 was not covered by tests
}

// LoadGenesisTxsFile loads genesis transactions from the provided file path.
// XXX: Improve the way we generate and load this file
func LoadGenesisTxsFile(path string, chainID string, genesisRemote string) ([]std.Tx, error) {
Expand Down
Loading
Loading