Skip to content

Commit

Permalink
chore: better ux
Browse files Browse the repository at this point in the history
  • Loading branch information
piux2 committed Mar 7, 2024
1 parent d916cdd commit a638ed3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 81 deletions.
6 changes: 5 additions & 1 deletion loadrunner/cmd/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func broadcast(args []string) error {
close(results)

println()
fmt.Printf("broadcast %d txs in %s/data/txs.db\n", n*numMsgs, RootDir)
fmt.Printf("broadcast %d msgs %d txs in %s/data/txs.db\n", n*numMsgs, n, RootDir)
return nil
}

Expand All @@ -160,10 +160,14 @@ func broadcastTx(info keys.Info , txbase *Txbase)(*ctypes.ResultBroadcastTxCommi
if err != nil {
return nil, fmt.Errorf("remarshaling tx binary bytes %w\n",err)
}

bres, err = cli.BroadcastTxCommit(bz)
if err != nil {
return nil, fmt.Errorf("broadcasting bytes %w\n", err)
}



fmt.Printf("%s GasWanted: %d \tGasUsed: %d\n",addr, bres.DeliverTx.GasWanted,bres.DeliverTx.GasUsed)
// after it broadcast successfully, we delete txs entires
(*txbase).Delete(info.GetAddress())
Expand Down
46 changes: 21 additions & 25 deletions loadrunner/cmd/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"path/filepath"

"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/crypto/keys"

Expand Down Expand Up @@ -74,7 +75,6 @@ type Txbase struct {
}

func NewTxbase(rootDir, name string) (Txbase, error) {

dir := filepath.Join(rootDir, "data")

if err := os.EnsureDir(dir, 0o700); err != nil {
Expand All @@ -90,17 +90,16 @@ func NewTxbase(rootDir, name string) (Txbase, error) {

// the key is signer account address
func (tb Txbase) SetTxs(addr crypto.Address, txs []std.Tx) error {

mtxs,err := amino.MarshalJSON(txs)
if err != nil{

panic("")
}
mtxs, err := amino.MarshalJSON(txs)
if err != nil {
panic("")
}
tb.db.SetSync([]byte(addr.String()), mtxs)

return nil
}
func (tb Txbase) GetTxsByAddrS(addr string )([]std.Tx, error){

func (tb Txbase) GetTxsByAddrS(addr string) ([]std.Tx, error) {
bzTx := tb.db.Get([]byte(addr))
if len(bzTx) == 0 {
return nil, fmt.Errorf("key with address %s not found", addr)
Expand All @@ -112,22 +111,19 @@ func (tb Txbase) GetTxsByAddrS(addr string )([]std.Tx, error){
return nil, err
}
return txs, nil

}

func (tb Txbase) GetTxs(addr crypto.Address) ([]std.Tx, error) {
return tb.GetTxsByAddrS(addr.String())
return tb.GetTxsByAddrS(addr.String())
}
func (tb Txbase) Delete(addr crypto.Address){

func (tb Txbase) Delete(addr crypto.Address) {
tb.db.DeleteSync([]byte(addr.String()))

}

type TxInfo struct{

type TxInfo struct {
addr string
txs []std.Tx

txs []std.Tx
}

func (tb Txbase) List() []TxInfo {
Expand All @@ -137,15 +133,15 @@ func (tb Txbase) List() []TxInfo {
for ; iter.Valid(); iter.Next() {
key := string(iter.Key())

txs, err := tb.GetTxsByAddrS(key)
if err != nil {
continue
}
info := TxInfo{
addr: key,
txs: txs,
}
res = append(res, info)
txs, err := tb.GetTxsByAddrS(key)
if err != nil {
continue
}
info := TxInfo{
addr: key,
txs: txs,
}
res = append(res, info)

}
return res
Expand Down
8 changes: 3 additions & 5 deletions loadrunner/cmd/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

const (
SignerKeyPrefix = "loadrunner"
SignerKeyPrefix = "loadrunner"
encryptPassword = "loadrunner"
)

Expand Down Expand Up @@ -62,10 +62,8 @@ func (k KeyGenTask) Execute() error {
}

func keyGen(args []string) error {
if len(args) == 0{

if len(args) == 0 {
return fmt.Errorf("%s\n", "please specify number of keys to generate.")

}
arg := args[0]
var numWorkers int = 1000
Expand Down Expand Up @@ -104,7 +102,7 @@ func keyGen(args []string) error {
key := SignerKeyPrefix + strconv.Itoa(i)

t := KeyGenTask{
signerkey: key,
signerkey: key,
mnemonic: mnemonic,
bip39Passphrase: bip39Passphrase,
encryptPassword: encryptPassword,
Expand Down
42 changes: 17 additions & 25 deletions loadrunner/cmd/list.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@

package main

import (
"context"
"flag"
"fmt"


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




)

type listCfg struct{}
Expand All @@ -34,31 +28,29 @@ func newListCmd() *commands.Command {
}

func list(args []string) error {
// Txbase store signed Txs before it is broadcasted.
txbase, err := NewTxbase(RootDir,defaultTxDBName)
if err != nil {
return err
}
defer txbase.Close()
// Txbase store signed Txs before it is broadcasted.
txbase, err := NewTxbase(RootDir, defaultTxDBName)
if err != nil {
return err
}
defer txbase.Close()

if len(args) == 0{
txinfos := txbase.List()
fmt.Printf("%d entries in txs.db \n", len(txinfos))
return nil
}
addr := args[0]
if len(args) == 0 {
txinfos := txbase.List()
fmt.Printf("%d entries in txs.db \n", len(txinfos))
return nil
}
addr := args[0]

txs, err:=txbase.GetTxsByAddrS(addr)
if err != nil{
return err
}
txs, err := txbase.GetTxsByAddrS(addr)
if err != nil {
return err
}

fmt.Printf("Address \t\t\t\t\tGas wanted \tFee\n")
for _, tx := range txs{

for _, tx := range txs {
fmt.Printf("%s \t%d \t%s\n", addr, tx.Fee.GasWanted, tx.Fee.GasFee)
}


return nil
}
46 changes: 21 additions & 25 deletions loadrunner/cmd/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (

const (
ChainID = "dev"
numMsgs = 1 // number messages per tx
numMsgs = 5 // number messages per tx
gas = 100
fee = 5
)

type signCfg struct{}
Expand All @@ -43,7 +45,7 @@ func newSignCmd() *commands.Command {
}

type SignTxTask struct {
SignerKey string
SignerKey string
Account std.BaseAccount
encryptPassword string
keybase *EagerKeybase
Expand Down Expand Up @@ -93,16 +95,15 @@ func sign(num string) error {
return nil
}
// check and update each account sequence against the node
signTasks, err := prepareSignTasks(kb,txbase, n)
signTasks, err := prepareSignTasks(kb, txbase, n)
if err != nil {
return err
}

if l :=len(signTasks) ; n > l {
n = l
if l := len(signTasks); n > l {
n = l
}


var wg sync.WaitGroup

tasks := make(chan Task, n)
Expand All @@ -121,9 +122,7 @@ func sign(num string) error {

// jobs
wg.Add(n)
for _, t := range signTasks{


for _, t := range signTasks {
tasks <- t
}

Expand All @@ -138,19 +137,19 @@ func sign(num string) error {

func newTxs() []std.Tx {
// TODO: max gas, max tx size and max msg size
pkgPath := "gno.land/r/x/benchmark/load"
pkgPath := "gno.land/r/load"
fn := "AddPost"
args := []string{"hello","world"}
/*
args := []string{
"Weather Outlook: Nov 1 - Nov 7, 2024: A Week of Changing Skies", "Today's comprehensive weather forecast promises a dynamic and engaging experience for all, blending a mix of atmospheric conditions that cater to a wide array of preferences and activities. As dawn breaks, residents can anticipate a refreshing and crisp morning with temperatures gently rising from a cool 55°F, creating an invigorating start to the day. The early hours will see a soft, dew-kissed breeze whispering through the streets, carrying the fresh scent of blooming flowers and newly cut grass, setting a serene tone for the day ahead.\n\nBy mid-morning, the sun, in its splendid glory, will begin to assert its presence, gradually elevating temperatures to a comfortable 75°F. The skies, adorned with a few scattered clouds, will paint a picturesque backdrop, ideal for outdoor enthusiasts eager to embrace the day's warmth. Whether it's a leisurely stroll in the park, an adventurous hike through nearby trails, or simply enjoying a quiet moment in the sun, the conditions will be perfectly aligned for an array of outdoor pursuits.\n\nAs the day progresses towards noon, expect the gentle morning breeze to evolve into a more pronounced wind, adding a refreshing counterbalance to the midday sun's warmth. This perfect harmony between the breeze and sunlight offers an optimal environment for sailing and kite-flying, providing just the right amount of lift and drift for an exhilarating experience.\n\nThe afternoon promises a continuation of the day's pleasant conditions, with the sun reigning supreme and the temperature peaking at a delightful 80°F. It's an ideal time for community sports, gardening, or perhaps an outdoor picnic, allowing friends and family to gather and make the most of the splendid weather.\n\nHowever, as we transition into the evening, anticipate a slight shift in the atmosphere. The temperature will gently dip, creating a cool and comfortable setting, perfect for al fresco dining or a serene walk under the starlit sky. The night will conclude with a mild 60°F, ensuring a peaceful and restful end to a day filled with diverse weather experiences.\n\nIn summary, today's weather forecast offers something for everyone, from the early risers seeking tranquility in the morning's embrace to the night owls looking to unwind under the cool evening air. It's a day to revel in the outdoors, pursue a myriad of activities, and simply enjoy the natural beauty that surrounds us.",
}
*/
//args := []string{"hello", "world"}

args := []string{
"Weather Outlook: Nov 1 - Nov 7, 2024: A Week of Changing Skies", "Today's comprehensive weather forecast promises a dynamic and engaging experience for all, blending a mix of atmospheric conditions that cater to a wide array of preferences and activities. As dawn breaks, residents can anticipate a refreshing and crisp morning with temperatures gently rising from a cool 55°F, creating an invigorating start to the day. The early hours will see a soft, dew-kissed breeze whispering through the streets, carrying the fresh scent of blooming flowers and newly cut grass, setting a serene tone for the day ahead.\n\nBy mid-morning, the sun, in its splendid glory, will begin to assert its presence, gradually elevating temperatures to a comfortable 75°F. The skies, adorned with a few scattered clouds, will paint a picturesque backdrop, ideal for outdoor enthusiasts eager to embrace the day's warmth. Whether it's a leisurely stroll in the park, an adventurous hike through nearby trails, or simply enjoying a quiet moment in the sun, the conditions will be perfectly aligned for an array of outdoor pursuits.\n\nAs the day progresses towards noon, expect the gentle morning breeze to evolve into a more pronounced wind, adding a refreshing counterbalance to the midday sun's warmth. This perfect harmony between the breeze and sunlight offers an optimal environment for sailing and kite-flying, providing just the right amount of lift and drift for an exhilarating experience.\n\nThe afternoon promises a continuation of the day's pleasant conditions, with the sun reigning supreme and the temperature peaking at a delightful 80°F. It's an ideal time for community sports, gardening, or perhaps an outdoor picnic, allowing friends and family to gather and make the most of the splendid weather.\n\nHowever, as we transition into the evening, anticipate a slight shift in the atmosphere. The temperature will gently dip, creating a cool and comfortable setting, perfect for al fresco dining or a serene walk under the starlit sky. The night will conclude with a mild 60°F, ensuring a peaceful and restful end to a day filled with diverse weather experiences.\n\nIn summary, today's weather forecast offers something for everyone, from the early risers seeking tranquility in the morning's embrace to the night owls looking to unwind under the cool evening air. It's a day to revel in the outdoors, pursue a myriad of activities, and simply enjoy the natural beauty that surrounds us.",
}

msgs := []std.Msg{}
gaswanted := int64(10000000)
gaswanted := int64(gas)
gasfee := std.Coin{
Denom: "ugnot",
Amount: 1,
Amount: fee,
}

msg := vm.MsgCall{
Expand Down Expand Up @@ -229,7 +228,7 @@ func signTx(signer keys.Info, account std.BaseAccount, txs []std.Tx, kb *EagerKe
}

// update sequence number of first n-th accounts
func prepareSignTasks(kb EagerKeybase,txbase Txbase, n int) ([]Task, error) {
func prepareSignTasks(kb EagerKeybase, txbase Txbase, n int) ([]Task, error) {
infos, err := kb.List()
if err != nil {
return nil, err
Expand All @@ -245,8 +244,8 @@ func prepareSignTasks(kb EagerKeybase,txbase Txbase, n int) ([]Task, error) {
for i := 0; i < n; i++ {
// update account's information
key := SignerKeyPrefix + strconv.Itoa(i)
info,err := kb.GetByName(key)
if err != nil{
info, err := kb.GetByName(key)
if err != nil {
continue
}
qopts := &queryOption{
Expand All @@ -267,7 +266,7 @@ func prepareSignTasks(kb EagerKeybase,txbase Txbase, n int) ([]Task, error) {
// create Tasks.
txs := newTxs()
t := SignTxTask{
SignerKey: key,
SignerKey: key,
Account: qret.BaseAccount,
encryptPassword: encryptPassword,
txs: txs,
Expand All @@ -278,9 +277,6 @@ func prepareSignTasks(kb EagerKeybase,txbase Txbase, n int) ([]Task, error) {

}




return tasks, nil
}

Expand Down

0 comments on commit a638ed3

Please sign in to comment.