-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:gnolang/gno into dev/morgan/big-t…
…est-refactor
- Loading branch information
Showing
186 changed files
with
4,239 additions
and
2,242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 := ×tampCfg{} | ||
|
||
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) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.