Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ava-labs/subnet-evm into geth-v1.…
Browse files Browse the repository at this point in the history
…12.2-x
  • Loading branch information
darioush committed Feb 26, 2024
2 parents 7c77dff + 0c3802c commit 23dfdc4
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 101 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ The Subnet EVM runs in a separate process from the main AvalancheGo process and
[v0.5.9] [email protected] (Protocol Version: 30)
[v0.5.10] [email protected] (Protocol Version: 30)
[v0.5.11] [email protected] (Protocol Version: 31)
[v0.6.0] [email protected] (Protocol Version: 33)
[v0.6.1] [email protected] (Protocol Version: 33)
```

## API
Expand Down
40 changes: 22 additions & 18 deletions cmd/simulator/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
TimeoutKey = "timeout"
BatchSizeKey = "batch-size"
MetricsPortKey = "metrics-port"
MetricsOutputKey = "metrics-output"
)

var (
Expand All @@ -37,28 +38,30 @@ var (
)

type Config struct {
Endpoints []string `json:"endpoints"`
MaxFeeCap int64 `json:"max-fee-cap"`
MaxTipCap int64 `json:"max-tip-cap"`
Workers int `json:"workers"`
TxsPerWorker uint64 `json:"txs-per-worker"`
KeyDir string `json:"key-dir"`
Timeout time.Duration `json:"timeout"`
BatchSize uint64 `json:"batch-size"`
MetricsPort uint64 `json:"metrics-port"`
Endpoints []string `json:"endpoints"`
MaxFeeCap int64 `json:"max-fee-cap"`
MaxTipCap int64 `json:"max-tip-cap"`
Workers int `json:"workers"`
TxsPerWorker uint64 `json:"txs-per-worker"`
KeyDir string `json:"key-dir"`
Timeout time.Duration `json:"timeout"`
BatchSize uint64 `json:"batch-size"`
MetricsPort uint64 `json:"metrics-port"`
MetricsOutput string `json:"metrics-output"`
}

func BuildConfig(v *viper.Viper) (Config, error) {
c := Config{
Endpoints: v.GetStringSlice(EndpointsKey),
MaxFeeCap: v.GetInt64(MaxFeeCapKey),
MaxTipCap: v.GetInt64(MaxTipCapKey),
Workers: v.GetInt(WorkersKey),
TxsPerWorker: v.GetUint64(TxsPerWorkerKey),
KeyDir: v.GetString(KeyDirKey),
Timeout: v.GetDuration(TimeoutKey),
BatchSize: v.GetUint64(BatchSizeKey),
MetricsPort: v.GetUint64(MetricsPortKey),
Endpoints: v.GetStringSlice(EndpointsKey),
MaxFeeCap: v.GetInt64(MaxFeeCapKey),
MaxTipCap: v.GetInt64(MaxTipCapKey),
Workers: v.GetInt(WorkersKey),
TxsPerWorker: v.GetUint64(TxsPerWorkerKey),
KeyDir: v.GetString(KeyDirKey),
Timeout: v.GetDuration(TimeoutKey),
BatchSize: v.GetUint64(BatchSizeKey),
MetricsPort: v.GetUint64(MetricsPortKey),
MetricsOutput: v.GetString(MetricsOutputKey),
}
if len(c.Endpoints) == 0 {
return c, ErrNoEndpoints
Expand Down Expand Up @@ -122,4 +125,5 @@ func addSimulatorFlags(fs *pflag.FlagSet) {
fs.String(LogLevelKey, "info", "Specify the log level to use in the simulator")
fs.Uint64(BatchSizeKey, 100, "Specify the batchsize for the worker to issue and confirm txs")
fs.Uint64(MetricsPortKey, 8082, "Specify the port to use for the metrics server")
fs.String(MetricsOutputKey, "", "Specify the file to write metrics in json format, or empy to write to stdout (defaults to stdout)")
}
15 changes: 10 additions & 5 deletions cmd/simulator/load/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ func ExecuteLoader(ctx context.Context, config config.Config) error {
}()

m := metrics.NewDefaultMetrics()
ms := m.Serve(ctx, strconv.Itoa(int(config.MetricsPort)), MetricsEndpoint)
metricsCtx := context.Background()
ms := m.Serve(metricsCtx, strconv.Itoa(int(config.MetricsPort)), MetricsEndpoint)
defer ms.Shutdown()

// Construct the arguments for the load simulator
Expand Down Expand Up @@ -186,13 +187,13 @@ func ExecuteLoader(ctx context.Context, config config.Config) error {
// to fund gas for all of their transactions.
maxFeeCap := new(big.Int).Mul(big.NewInt(params.GWei), big.NewInt(config.MaxFeeCap))
minFundsPerAddr := new(big.Int).Mul(maxFeeCap, big.NewInt(int64(config.TxsPerWorker*params.TxGas)))

fundStart := time.Now()
log.Info("Distributing funds", "numTxsPerWorker", config.TxsPerWorker, "minFunds", minFundsPerAddr)
keys, err = DistributeFunds(ctx, clients[0], keys, config.Workers, minFundsPerAddr, m)
if err != nil {
return err
}
log.Info("Distributed funds successfully")
log.Info("Distributed funds successfully", "time", time.Since(fundStart))

pks := make([]*ecdsa.PrivateKey, 0, len(keys))
senders := make([]common.Address, 0, len(keys))
Expand Down Expand Up @@ -225,18 +226,22 @@ func ExecuteLoader(ctx context.Context, config config.Config) error {
Value: common.Big0,
})
}

txSequenceStart := time.Now()
txSequences, err := txs.GenerateTxSequences(ctx, txGenerator, clients[0], pks, config.TxsPerWorker, false)
if err != nil {
return err
}
log.Info("Created transaction sequences successfully", "time", time.Since(txSequenceStart))

workers := make([]txs.Worker[*types.Transaction], 0, len(clients))
for i, client := range clients {
workers = append(workers, NewSingleAddressTxWorker(ctx, client, ethcrypto.PubkeyToAddress(pks[i].PublicKey)))
}
loader := New(workers, txSequences, config.BatchSize, m)
err = loader.Execute(ctx)
ms.Print() // Print regardless of execution error
prerr := m.Print(config.MetricsOutput) // Print regardless of execution error
if prerr != nil {
log.Warn("Failed to print metrics", "error", prerr)
}
return err
}
44 changes: 27 additions & 17 deletions cmd/simulator/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ package metrics

import (
"context"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"strings"
"os"

"github.com/ethereum/go-ethereum/log"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -108,22 +108,32 @@ func (ms *MetricsServer) Shutdown() {
<-ms.stopCh
}

func (ms *MetricsServer) Print() {
// Get response from server
resp, err := http.Get(fmt.Sprintf("http://localhost:%s%s", ms.metricsPort, ms.metricsEndpoint))
func (m *Metrics) Print(outputFile string) error {
metrics, err := m.reg.Gather()
if err != nil {
log.Error("cannot get response from metrics servers", "err", err)
return
return err
}
// Read response body
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Error("cannot read response body", "err", err)
return
}
// Print out formatted individual metrics
parts := strings.Split(string(respBody), "\n")
for _, s := range parts {
fmt.Printf(" \t\t\t%s\n", s)

if outputFile == "" {
// Printout to stdout
fmt.Println("*** Metrics ***")
for _, mf := range metrics {
for _, m := range mf.GetMetric() {
fmt.Printf("Type: %s, Name: %s, Description: %s, Values: %s\n", mf.GetType().String(), mf.GetName(), mf.GetHelp(), m.String())
}
}
fmt.Println("***************")
} else {
jsonFile, err := os.Create(outputFile)
if err != nil {
return err
}
defer jsonFile.Close()

if err := json.NewEncoder(jsonFile).Encode(metrics); err != nil {
return err
}
}

return nil
}
2 changes: 2 additions & 0 deletions compatibility.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"rpcChainVMProtocolVersion": {
"v0.6.1": 33,
"v0.6.0": 33,
"v0.5.11": 31,
"v0.5.10": 30,
"v0.5.9": 30,
Expand Down
2 changes: 1 addition & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func SetupGenesisBlock(
if compatErr != nil && ((height != 0 && compatErr.RewindToBlock != 0) || (timestamp != 0 && compatErr.RewindToTime != 0)) {
storedData, _ := storedcfg.ToWithUpgradesJSON().MarshalJSON()
newData, _ := newcfg.ToWithUpgradesJSON().MarshalJSON()
log.Error("found mismatch between config on database vs. new config", "storedConfig", string(storedData), "newConfig", string(newData))
log.Error("found mismatch between config on database vs. new config", "storedConfig", string(storedData), "newConfig", string(newData), "err", compatErr)
return newcfg, stored, compatErr
}
}
Expand Down
15 changes: 3 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.21

require (
github.com/VictoriaMetrics/fastcache v1.10.0
github.com/ava-labs/avalanche-network-runner v1.7.4-rc.0
github.com/ava-labs/avalanchego v1.11.0-rc.2
github.com/ava-labs/avalanche-network-runner v1.7.6
github.com/ava-labs/avalanchego v1.11.1
github.com/cespare/cp v0.1.0
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set/v2 v2.1.0
Expand Down Expand Up @@ -57,7 +57,7 @@ require (
github.com/DataDog/zstd v1.5.2 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/ava-labs/coreth v0.12.11-rc.3.0.20240211224816-78730e9c0d5a // indirect
github.com/ava-labs/coreth v0.13.0-rc.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.7.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
Expand All @@ -73,7 +73,6 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/deepmap/oapi-codegen v1.8.2 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/ethereum/c-kzg-4844 v0.3.1 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
Expand All @@ -83,7 +82,6 @@ require (
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.3.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand All @@ -93,14 +91,10 @@ require (
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/google/renameio/v2 v2.0.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/graph-gophers/graphql-go v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/influxdata/influxdb-client-go/v2 v2.4.0 // indirect
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c // indirect
github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 // indirect
github.com/jackpal/gateway v1.0.6 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/klauspost/compress v1.15.15 // indirect
Expand All @@ -114,11 +108,9 @@ require (
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/otiai10/copy v1.11.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 // indirect
github.com/pires/go-proxyproto v0.6.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down Expand Up @@ -156,7 +148,6 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.3 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
Expand Down
Loading

0 comments on commit 23dfdc4

Please sign in to comment.