-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(misc/autocounterd): init autocounterd (#1612)
A demo is currently running on the portal loop you can check https://portal.gnoteam.com/r/portal/counter close: #1443 <details><summary>Contributors' checklist...</summary> - [ ] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: Miloš Živković <[email protected]> Co-authored-by: Hariom Verma <[email protected]>
- Loading branch information
1 parent
7286ca7
commit 2a9a8f5
Showing
9 changed files
with
586 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: autocounterd | ||
|
||
on: | ||
push: | ||
paths: | ||
- misc/autocounterd | ||
- .github/workflows/autocounterd.yml | ||
branches: | ||
- "master" | ||
- "misc/autocounterd" | ||
tags: | ||
- "v*" | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
jobs: | ||
autocounterd: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Docker metadata autcounterd | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ghcr.io/${{ github.repository }}/autcounterd | ||
tags: | | ||
type=raw,value=latest | ||
type=semver,pattern=v{{version}} | ||
- name: Build and push | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ./misc/autocounterd | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
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,16 @@ | ||
FROM golang:alpine AS builder | ||
|
||
COPY . /go/src/github.com/gnolang/gno/misc/autocounterd | ||
|
||
WORKDIR /go/src/github.com/gnolang/gno/misc/autocounterd | ||
|
||
RUN go build -o /build/autocounterd ./cmd | ||
|
||
# Final image for autocounterd | ||
FROM alpine AS autocounterd | ||
|
||
COPY --from=builder /build/autocounterd /usr/bin/autocounterd | ||
|
||
ENTRYPOINT [ "/usr/bin/autocounterd" ] | ||
CMD [ "start" ] | ||
|
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,13 @@ | ||
# Autocounterd | ||
|
||
## What is it? | ||
|
||
`autcounterd` is a simple binary that increments a simple counter every x seconds to analyse and test a network. | ||
|
||
## How to use | ||
|
||
Start it with: | ||
|
||
``` sh | ||
$ docker compose up -d | ||
``` |
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,100 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/gnolang/gno/gno.land/pkg/gnoclient" | ||
rpcclient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client" | ||
"github.com/gnolang/gno/tm2/pkg/commands" | ||
) | ||
|
||
type startCfg struct { | ||
rpcURL string | ||
chainID string | ||
mnemonic string | ||
realmPath string | ||
incrementInterval time.Duration | ||
} | ||
|
||
func (cfg *startCfg) Validate() error { | ||
switch { | ||
case cfg.rpcURL == "": | ||
return fmt.Errorf("rpc url cannot be empty") | ||
case cfg.chainID == "": | ||
return fmt.Errorf("chainID cannot be empty") | ||
case cfg.mnemonic == "": | ||
return fmt.Errorf("mnemonic cannot be empty") | ||
case cfg.realmPath == "": | ||
return fmt.Errorf("realmPath cannot be empty") | ||
case cfg.incrementInterval == 0: | ||
return fmt.Errorf("interval cannot be empty") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func NewStartCmd(io commands.IO) *commands.Command { | ||
cfg := &startCfg{} | ||
|
||
return commands.NewCommand( | ||
commands.Metadata{ | ||
Name: "start", | ||
ShortUsage: "start [flags]", | ||
ShortHelp: "Runs the linter for the specified packages", | ||
}, | ||
cfg, | ||
func(_ context.Context, args []string) error { | ||
return execStart(cfg, args, io) | ||
}, | ||
) | ||
} | ||
|
||
func (c *startCfg) RegisterFlags(fs *flag.FlagSet) { | ||
fs.StringVar(&c.rpcURL, "rpc", "127.0.0.1:26657", "rpc url endpoint") | ||
fs.StringVar(&c.chainID, "chain-id", "dev", "chain-id") | ||
fs.StringVar(&c.mnemonic, "mnemonic", "", "mnemonic") | ||
fs.StringVar(&c.realmPath, "realm", "gno.land/r/portal/counter", "realm path") | ||
fs.DurationVar(&c.incrementInterval, "interval", 15*time.Second, "Increment counter interval") | ||
} | ||
|
||
func execStart(cfg *startCfg, args []string, io commands.IO) error { | ||
if err := cfg.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
signer, err := gnoclient.SignerFromBip39(cfg.mnemonic, cfg.chainID, "", uint32(0), uint32(0)) | ||
if err != nil { | ||
return err | ||
} | ||
if err := signer.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
rpcClient := rpcclient.NewHTTP(cfg.rpcURL, "/websocket") | ||
|
||
client := gnoclient.Client{ | ||
Signer: signer, | ||
RPCClient: rpcClient, | ||
} | ||
|
||
for { | ||
res, err := client.Call(gnoclient.CallCfg{ | ||
PkgPath: cfg.realmPath, | ||
FuncName: "Incr", | ||
GasFee: "10000000ugnot", | ||
GasWanted: 800000, | ||
Args: nil, | ||
}) | ||
_ = res | ||
|
||
if err != nil { | ||
fmt.Printf("[ERROR] Failed to call Incr on %s, %+v\n", cfg.realmPath, err.Error()) | ||
} else { | ||
fmt.Println("[INFO] Counter incremented with success") | ||
} | ||
time.Sleep(cfg.incrementInterval) | ||
} | ||
} |
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 := NewStartCmd(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: "3" | ||
services: | ||
autocounterd: | ||
image: ghcr.io/gnolang/gno/autocounterd | ||
build: | ||
context: . | ||
restart: unless-stopped | ||
environment: | ||
COUNTER_MNEMONIC: "source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast" | ||
COUNTER_RPC: "http://127.0.0.1:26657" | ||
COUNTER_CHAIN_ID: "dev" | ||
COUNTER_INTERVAL: "5s" | ||
COUNTER_REALM: "gno.land/r/portal/counter" |
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,52 @@ | ||
module loop | ||
|
||
go 1.21 | ||
|
||
require github.com/gnolang/gno v0.0.0-20240125181217-b6193518e278 | ||
|
||
require ( | ||
dario.cat/mergo v1.0.0 // indirect | ||
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect | ||
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect | ||
github.com/cespare/xxhash v1.1.0 // indirect | ||
github.com/cespare/xxhash/v2 v2.1.1 // indirect | ||
github.com/cockroachdb/apd/v3 v3.2.1 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect | ||
github.com/dgraph-io/badger/v3 v3.2103.5 // indirect | ||
github.com/dgraph-io/ristretto v0.1.1 // indirect | ||
github.com/dustin/go-humanize v1.0.0 // indirect | ||
github.com/gnolang/goleveldb v0.0.9 // indirect | ||
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect | ||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/golang/snappy v0.0.4 // indirect | ||
github.com/google/flatbuffers v1.12.1 // indirect | ||
github.com/gorilla/websocket v1.5.1 // indirect | ||
github.com/jaekwon/testify v1.6.1 // indirect | ||
github.com/jmhodges/levigo v1.0.0 // indirect | ||
github.com/klauspost/compress v1.12.3 // indirect | ||
github.com/libp2p/go-buffer-pool v0.1.0 // indirect | ||
github.com/linxGnu/grocksdb v1.8.11 // indirect | ||
github.com/pelletier/go-toml v1.9.5 // indirect | ||
github.com/peterbourgon/ff/v3 v3.4.0 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rs/cors v1.10.1 // indirect | ||
github.com/stretchr/testify v1.8.4 // indirect | ||
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect | ||
go.etcd.io/bbolt v1.3.8 // indirect | ||
go.opencensus.io v0.22.5 // indirect | ||
go.uber.org/multierr v1.10.0 // indirect | ||
golang.org/x/crypto v0.18.0 // indirect | ||
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect | ||
golang.org/x/mod v0.14.0 // indirect | ||
golang.org/x/net v0.20.0 // indirect | ||
golang.org/x/sys v0.16.0 // indirect | ||
golang.org/x/term v0.16.0 // indirect | ||
golang.org/x/tools v0.17.0 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.