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: remove monoclock & add tz as chain param #3193

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions contribs/gnodev/cmd/gnodev/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ type devCfg struct {
noReplay bool
maxGas int64
chainId string
chainTz string
serverMode bool
unsafeAPI bool
}

var defaultDevOptions = &devCfg{
chainId: "dev",
chainTz: "UTC",
maxGas: 10_000_000_000,
webListenerAddr: "127.0.0.1:8888",
nodeRPCListenerAddr: "127.0.0.1:26657",
Expand Down Expand Up @@ -203,6 +205,13 @@ func (c *devCfg) RegisterFlags(fs *flag.FlagSet) {
"set node ChainID",
)

fs.StringVar(
&c.chainTz,
"chain-tz",
defaultDevOptions.chainTz,
"set node Chain Timezone",
)

fs.BoolVar(
&c.noWatch,
"no-watch",
Expand Down
2 changes: 1 addition & 1 deletion contribs/gnodev/cmd/gnodev/setup_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func setupDevNodeConfig(
balances gnoland.Balances,
pkgspath []gnodev.PackagePath,
) *gnodev.NodeConfig {
config := gnodev.DefaultNodeConfig(cfg.root)
config := gnodev.DefaultNodeConfig(cfg.root, cfg.chainTz)

config.Logger = logger
config.Emitter = emitter
Expand Down
16 changes: 12 additions & 4 deletions contribs/gnodev/pkg/dev/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ type NodeConfig struct {
NoReplay bool
MaxGasPerBlock int64
ChainID string
ChainTz string
}

func DefaultNodeConfig(rootdir string) *NodeConfig {
func DefaultNodeConfig(rootdir string, tz string) *NodeConfig {
tmc := gnoland.NewDefaultTMConfig(rootdir)
tmc.Consensus.SkipTimeoutCommit = false // avoid time drifting, see issue #1507
tmc.Consensus.WALDisabled = true
Expand All @@ -65,6 +66,7 @@ func DefaultNodeConfig(rootdir string) *NodeConfig {
DefaultDeployer: defaultDeployer,
BalancesList: balances,
ChainID: tmc.ChainID(),
ChainTz: tz,
TMConfig: tmc,
SkipFailingGenesisTxs: true,
MaxGasPerBlock: 10_000_000_000,
Expand Down Expand Up @@ -121,10 +123,16 @@ func NewDevNode(ctx context.Context, cfg *NodeConfig) (*Node, error) {
currentStateIndex: len(cfg.InitialTxs),
}

var tzParam gnoland.Param
_ = tzParam.Parse("gno.land/r/sys/params.vm.chain_tz.string=" + cfg.ChainTz)

// generate genesis state
genesis := gnoland.GnoGenesisState{
Balances: cfg.BalancesList,
Txs: append(pkgsTxs, cfg.InitialTxs...),
Params: []gnoland.Param{
tzParam,
},
}

if err := devnode.rebuildNode(ctx, genesis); err != nil {
Expand Down Expand Up @@ -487,7 +495,7 @@ func (n *Node) rebuildNode(ctx context.Context, genesis gnoland.GnoGenesisState)
}

// Setup node config
nodeConfig := newNodeConfig(n.config.TMConfig, n.config.ChainID, genesis)
nodeConfig := newNodeConfig(n.config.TMConfig, n.config.ChainID, n.config.ChainTz, genesis)
nodeConfig.GenesisTxResultHandler = n.genesisTxResultHandler
// Speed up stdlib loading after first start (saves about 2-3 seconds on each reload).
nodeConfig.CacheStdlibLoad = true
Expand Down Expand Up @@ -566,10 +574,10 @@ func (n *Node) genesisTxResultHandler(ctx sdk.Context, tx std.Tx, res sdk.Result
return
}

func newNodeConfig(tmc *tmcfg.Config, chainid string, appstate gnoland.GnoGenesisState) *gnoland.InMemoryNodeConfig {
func newNodeConfig(tmc *tmcfg.Config, chainid string, chaintz string, appstate gnoland.GnoGenesisState) *gnoland.InMemoryNodeConfig {
// Create Mocked Identity
pv := gnoland.NewMockedPrivValidator()
genesis := gnoland.NewDefaultGenesisConfig(chainid)
genesis := gnoland.NewDefaultGenesisConfig(chainid, chaintz)
genesis.AppState = appstate

// Add self as validator
Expand Down
6 changes: 3 additions & 3 deletions contribs/gnodev/pkg/dev/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestNewNode_NoPackages(t *testing.T) {
logger := log.NewTestingLogger(t)

// Call NewDevNode with no package should work
cfg := DefaultNodeConfig(gnoenv.RootDir())
cfg := DefaultNodeConfig(gnoenv.RootDir(), "UTC")
cfg.Logger = logger
node, err := NewDevNode(ctx, cfg)
require.NoError(t, err)
Expand Down Expand Up @@ -66,7 +66,7 @@ func Render(_ string) string { return "foo" }
logger := log.NewTestingLogger(t)

// Call NewDevNode with no package should work
cfg := DefaultNodeConfig(gnoenv.RootDir())
cfg := DefaultNodeConfig(gnoenv.RootDir(), "UTC")
cfg.PackagesPathList = []PackagePath{pkgpath}
cfg.Logger = logger
node, err := NewDevNode(ctx, cfg)
Expand Down Expand Up @@ -475,7 +475,7 @@ func generateTestingPackage(t *testing.T, nameFile ...string) PackagePath {
}

func createDefaultTestingNodeConfig(pkgslist ...PackagePath) *NodeConfig {
cfg := DefaultNodeConfig(gnoenv.RootDir())
cfg := DefaultNodeConfig(gnoenv.RootDir(), "UTC")
cfg.PackagesPathList = pkgslist
return cfg
}
Expand Down
49 changes: 10 additions & 39 deletions examples/gno.land/r/demo/boards/z_4_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -309,36 +309,16 @@ func main() {
// c[f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:131]={
// "Fields": [
// {
// "N": "AAAAgJSeXbo=",
// "T": {
// "@type": "/gno.PrimitiveType",
// "value": "65536"
// }
// },
// {
// "N": "AbSNdvQQIhE=",
// "N": "0vknwQ4AAAA=",
// "T": {
// "@type": "/gno.PrimitiveType",
// "value": "1024"
// }
// },
// {
// "T": {
// "@type": "/gno.PointerType",
// "Elt": {
// "@type": "/gno.RefType",
// "ID": "time.Location"
// }
// },
// "V": {
// "@type": "/gno.PointerValue",
// "Base": {
// "@type": "/gno.RefValue",
// "Escaped": true,
// "ObjectID": "336074805fc853987abe6f7fe3ad97a6a6f3077a:2"
// },
// "Index": "182",
// "TV": null
// "@type": "/gno.PrimitiveType",
// "value": "512"
// }
// }
// ],
Expand All @@ -354,22 +334,13 @@ func main() {
// {
// "T": {
// "@type": "/gno.PrimitiveType",
// "value": "65536"
// }
// },
// {
// "T": {
// "@type": "/gno.PrimitiveType",
// "value": "1024"
// }
// },
// {
// "T": {
// "@type": "/gno.PointerType",
// "Elt": {
// "@type": "/gno.RefType",
// "ID": "time.Location"
// }
// "@type": "/gno.PrimitiveType",
// "value": "512"
// }
// }
// ],
Expand Down Expand Up @@ -498,7 +469,7 @@ func main() {
// },
// "V": {
// "@type": "/gno.RefValue",
// "Hash": "0fd3352422af0a56a77ef2c9e88f479054e3d51f",
// "Hash": "55cc9b7009f66b35f15d34ceed3fa25c9e36d54d",
// "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:131"
// }
// },
Expand All @@ -509,7 +480,7 @@ func main() {
// },
// "V": {
// "@type": "/gno.RefValue",
// "Hash": "bed4afa8ffdbbf775451c947fc68b27a345ce32a",
// "Hash": "d8d66a5855b0427c262cfce9891c88d469ab2351",
// "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:132"
// }
// }
Expand All @@ -535,7 +506,7 @@ func main() {
// },
// "V": {
// "@type": "/gno.RefValue",
// "Hash": "c45bbd47a46681a63af973db0ec2180922e4a8ae",
// "Hash": "6b2cd34f216499f59540555be3fe11f40a67baa1",
// "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:127"
// }
// }
Expand Down Expand Up @@ -786,7 +757,7 @@ func main() {
// },
// "V": {
// "@type": "/gno.RefValue",
// "Hash": "a416a751c3a45a1e5cba11e737c51340b081e372",
// "Hash": "ed9d8105a90a05bc8d953538dd8810201e26ec6d",
// "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:86"
// }
// },
Expand All @@ -804,7 +775,7 @@ func main() {
// },
// "V": {
// "@type": "/gno.RefValue",
// "Hash": "36299fccbc13f2a84c4629fad4cb940f0bd4b1c6",
// "Hash": "ef78d14dccddfaa802727058e543d3ecc87157f0",
// "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:87"
// }
// },
Expand Down
6 changes: 2 additions & 4 deletions examples/gno.land/r/demo/groups/z_1_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@ func main() {
//
// Group Creator: gnouser0
//
// Group createdAt: 2009-02-13 23:31:30 +0000 UTC m=+1234567890.000000001
// Group createdAt: 2009-02-13 23:31:30 +0000 UTC
//
// Group Last MemberID: 0000000001
//
// Group Members:
//
// [0000000000, g1vahx7atnv4erxh6lta047h6lta047h6ll85gpy, 32, i am from UAE, 2009-02-13 23:31:30 +0000 UTC m=+1234567890.000000001],
//
//
// [0000000000, g1vahx7atnv4erxh6lta047h6lta047h6ll85gpy, 32, i am from UAE, 2009-02-13 23:31:30 +0000 UTC],
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/groups/z_2_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func main() {
//
// Group Creator: gnouser0
//
// Group createdAt: 2009-02-13 23:31:30 +0000 UTC m=+1234567890.000000001
// Group createdAt: 2009-02-13 23:31:30 +0000 UTC
//
// Group Last MemberID: 0000000001
//
Expand Down
1 change: 1 addition & 0 deletions examples/gno.land/r/demo/timetest/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/demo/timetest
13 changes: 13 additions & 0 deletions examples/gno.land/r/demo/timetest/test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package timetest

import (
"std"
"time"
)

func Render(path string) string {
time2 := time.Now()
tz := std.GetChainTz()

return time2.String() + " | " + tz
}
6 changes: 0 additions & 6 deletions examples/gno.land/r/gnoland/events/events.gno
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,5 @@ func parseTimes(startTime, endTime string) (time.Time, time.Time, error) {
return time.Time{}, time.Time{}, ErrEndBeforeStart
}

_, stOffset := st.Zone()
_, etOffset := et.Zone()
if stOffset != etOffset {
return time.Time{}, time.Time{}, ErrStartEndTimezonemMismatch
}

return st, et, nil
}
3 changes: 0 additions & 3 deletions examples/gno.land/r/gnoland/events/events_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ func TestParseTimes(t *testing.T) {

_, _, err = parseTimes("2009-02-13T23:30:30Z", "2009-02-13T21:30:30Z")
uassert.ErrorContains(t, err, ErrEndBeforeStart.Error())

_, _, err = parseTimes("2009-02-10T23:30:30+02:00", "2009-02-13T21:30:33+05:00")
uassert.ErrorContains(t, err, ErrStartEndTimezonemMismatch.Error())
}

func TestRenderEventWidget(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions examples/gno.land/r/gnoland/monit/monit_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ status=KO`
Incr()
{
expected := `counter=3
last update=2009-02-13 23:31:30 +0000 UTC m=+1234567890.000000001
last update=2009-02-13 23:31:30 +0000 UTC
last caller=g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
status=OK`
got := Render("")
Expand All @@ -35,7 +35,7 @@ status=OK`
use std.TestSkipTime(time.Hour)
{
expected := `counter=3
last update=2009-02-13 22:31:30 +0000 UTC m=+1234564290.000000001
last update=2009-02-13 22:31:30 +0000 UTC
last caller=g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
status=KO`
got := Render("")
Expand All @@ -46,7 +46,7 @@ status=OK`
Incr()
{
expected := `counter=4
last update=2009-02-13 23:31:30 +0000 UTC m=+1234567890.000000001
last update=2009-02-13 23:31:30 +0000 UTC
last caller=g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
status=OK`
got := Render("")
Expand Down
12 changes: 11 additions & 1 deletion gno.land/cmd/gnoland/testdata/genesis_params.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# test for https://github.com/gnolang/gno/pull/3003
# Test for #3003, #2911, #3193.

gnoland start

# Query and validate official parameters.
# These parameters should ideally be tested in a txtar format to ensure that a
# default initialization of "gnoland" provides the expected default values.

# Verify the default chain domain parameter for Gno.land
gnokey query params/vm/gno.land/r/sys/params.vm.chain_tz.string
stdout 'data: "UTC"$'

# Test custom parameters to confirm they return the expected values and types.

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
Expand Down
26 changes: 13 additions & 13 deletions gno.land/genesis/genesis_params.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

## 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
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 = ""
chain_tz.string = "UTC"
# TODO: chain_domain.string = "gno.land"
# TODO: max_gas.int64 = 100_000_000
# TODO: default_storage_allowance.string = ""

## tm2
["gno.land/r/sys/params.tm2"]
Expand All @@ -22,8 +22,8 @@
## 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
foo.string = "bar"
foo.int64 = -1337
foo.uint64 = 42
foo.bool = true
#foo.bytes = todo
Loading
Loading