Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gnolang/gno into dev/morgan/big-t…
Browse files Browse the repository at this point in the history
…est-refactor
  • Loading branch information
thehowl committed Nov 25, 2024
2 parents f1cfc8e + f27b182 commit 37eecb1
Show file tree
Hide file tree
Showing 186 changed files with 4,239 additions and 2,242 deletions.
1 change: 1 addition & 0 deletions .github/workflows/autocounterd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
push:
paths:
- misc/autocounterd
- misc/loop
- .github/workflows/autocounterd.yml
branches:
- "master"
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/fossa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ name: Dependency License Scanning

on:
workflow_dispatch:
pull_request:
paths:
- ".github/.fossa.yml"
- ".github/workflows/fossa.yml"
schedule:
- cron: '0 0 * * 6' # At 00:00 on saturdays

permissions:
contents: read
Expand Down Expand Up @@ -47,4 +41,3 @@ jobs:
run: fossa test
env:
FOSSA_API_KEY: "${{secrets.FOSSA_API_KEY}}"

20 changes: 9 additions & 11 deletions .github/workflows/misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ on:
jobs:
main:
strategy:
fail-fast: false
matrix:
# fixed list because we have some non go programs on that misc folder
program:
- autocounterd
# - devdeps
- docker-integration
- genproto
- genstd
- goscan
- loop
fail-fast: false
matrix:
# fixed list because we have some non go programs on that misc folder
program:
- autocounterd
- genproto
- genstd
- goscan
- loop
name: Run Main
uses: ./.github/workflows/main_template.yml
with:
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/portal-loop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ jobs:
- name: "Checkout"
uses: actions/checkout@v4

- name: "Setup the images"
- name: "Setup The portal loop docker compose"
run: |
cd misc/loop
docker compose build
docker compose pull
docker compose up -d
echo "Making docker compose happy"
touch .env
make docker.ci
- name: "Test1 - Portal loop start gnoland"
run: |
Expand Down
17 changes: 17 additions & 0 deletions contribs/gnohealth/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
rundep := go run -modfile ../../misc/devdeps/go.mod
golangci_lint := $(rundep) github.com/golangci/golangci-lint/cmd/golangci-lint


.PHONY: install
install:
go install .

.PHONY: build
build:
go build -o build/gnohealth .

lint:
$(golangci_lint) --config ../../.github/golangci.yml run ./...

test:
@echo "XXX: add tests"
46 changes: 46 additions & 0 deletions contribs/gnohealth/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module github.com/gnolang/gno/contribs/gnohealth

go 1.22.4

replace github.com/gnolang/gno => ../..

require github.com/gnolang/gno v0.0.0-00010101000000-000000000000

require (
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/btcsuite/btcd/btcutil v1.1.6 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/peterbourgon/ff/v3 v3.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
199 changes: 199 additions & 0 deletions contribs/gnohealth/go.sum

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions contribs/gnohealth/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"github.com/gnolang/gno/contribs/gnohealth/internal/timestamp"
"github.com/gnolang/gno/tm2/pkg/commands"
)

func newHealthCmd(io commands.IO) *commands.Command {
cmd := commands.NewCommand(
commands.Metadata{
ShortUsage: "<subcommand> [flags] [<arg>...]",
ShortHelp: "gno health check suite",
LongHelp: "Gno health check suite, to verify that different parts of Gno are working correctly",
},
commands.NewEmptyConfig(),
commands.HelpExec,
)

cmd.AddSubCommands(
timestamp.NewTimestampCmd(io),
)

return cmd
}
166 changes: 166 additions & 0 deletions contribs/gnohealth/internal/timestamp/timestamp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package timestamp

import (
"context"
"flag"
"fmt"
"time"

rpcClient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client"
"github.com/gnolang/gno/tm2/pkg/commands"
)

const (
defaultRemoteAddress = "http://127.0.0.1:26657"
defaultWebSocket = true
defaultCheckDuration = 30 * time.Second
defaultCheckInterval = 50 * time.Millisecond
defaultMaxDelta = 10 * time.Second
defaultVerbose = false
)

type timestampCfg struct {
remoteAddress string
webSocket bool
checkDuration time.Duration
checkInterval time.Duration
maxDelta time.Duration
verbose bool
}

// NewTimestampCmd creates the gnohealth timestamp subcommand
func NewTimestampCmd(io commands.IO) *commands.Command {
cfg := &timestampCfg{}

return commands.NewCommand(
commands.Metadata{
Name: "timestamp",
ShortUsage: "[flags]",
ShortHelp: "check if block timestamps are drifting",
LongHelp: "This command checks if block timestamps are drifting on a blockchain by connecting to a specified node via RPC.",
},
cfg,
func(_ context.Context, _ []string) error {
return execTimestamp(cfg, io)
},
)
}

// RegisterFlags registers command-line flags for the timestamp command
func (c *timestampCfg) RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(
&c.remoteAddress,
"remote",
defaultRemoteAddress,
"the remote address of the node to connect to via RPC",
)

fs.BoolVar(
&c.webSocket,
"ws",
defaultWebSocket,
"flag indicating whether to use the WebSocket protocol for RPC",
)

fs.DurationVar(
&c.checkDuration,
"duration",
defaultCheckDuration,
"duration for which checks should be performed",
)

fs.DurationVar(
&c.checkInterval,
"interval",
defaultCheckInterval,
"interval between consecutive checks",
)

fs.DurationVar(
&c.maxDelta,
"max-delta",
defaultMaxDelta,
"maximum allowable time difference between the current time and the last block time",
)

fs.BoolVar(
&c.verbose,
"verbose",
defaultVerbose,
"flag indicating whether to enable verbose logging",
)
}

func execTimestamp(cfg *timestampCfg, io commands.IO) error {
var (
client *rpcClient.RPCClient
err error
lastChecked int64
count uint64
totalDelta time.Duration
)

// Init RPC client
if cfg.webSocket {
if client, err = rpcClient.NewWSClient(cfg.remoteAddress); err != nil {
return fmt.Errorf("unable to create WS client: %w", err)
}
} else {
if client, err = rpcClient.NewHTTPClient(cfg.remoteAddress); err != nil {
return fmt.Errorf("unable to create HTTP client: %w", err)
}
}

// Create a ticker for check interval
ticker := time.NewTicker(cfg.checkInterval)
defer ticker.Stop()

// Create a context that will stop this check when specified duration is elapsed
ctx, cancel := context.WithTimeout(context.Background(), cfg.checkDuration)
defer cancel()

for {
select {
case <-ctx.Done():
average := totalDelta / time.Duration(count)
io.Printf("no timestamp drifted beyond the maximum delta (average %s)\n", average)
return nil

case <-ticker.C:
// Fetch the latest block number from the chain
status, err := client.Status()
if err != nil {
return fmt.Errorf("unable to fetch latest block number: %w", err)
}

latest := status.SyncInfo.LatestBlockHeight

// Check if there have been blocks since the last check
if lastChecked == latest {
continue
}

// Fetch the latest block from the chain
lastBlock, err := client.Block(&latest)
if err != nil {
return fmt.Errorf("unable to fetch latest block content: %w", err)
}

// Check if the last block timestamp is not drifting
delta := time.Until(lastBlock.Block.Time).Abs()
if delta > cfg.maxDelta {
return fmt.Errorf("block %d drifted of %s (max %s): KO", latest, delta, cfg.maxDelta)
}

// Increment counters to calculate average on exit
count += 1
totalDelta += delta

// Update the last checked block number
lastChecked = latest
if cfg.verbose {
io.Printf("block %d drifted of %s (max %s): OK\n", latest, delta, cfg.maxDelta)
}
}
}
}
14 changes: 14 additions & 0 deletions contribs/gnohealth/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"context"
"os"

"github.com/gnolang/gno/tm2/pkg/commands"
)

func main() {
cmd := newHealthCmd(commands.NewDefaultIO())

cmd.Execute(context.Background(), os.Args[1:])
}
2 changes: 1 addition & 1 deletion docs/reference/stdlibs/std/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Should be used in combination with [`NewUserRealm`](#newuserrealm) &
#### Usage
```go
addr := std.Address("g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec")
std.TestSetRealm(std.NewUserRealm(""))
std.TestSetRealm(std.NewUserRealm(addr))
// or
std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/users"))
```
Expand Down
21 changes: 0 additions & 21 deletions examples/gno.land/p/demo/int256/LICENSE

This file was deleted.

6 changes: 0 additions & 6 deletions examples/gno.land/p/demo/int256/README.md

This file was deleted.

Loading

0 comments on commit 37eecb1

Please sign in to comment.