Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 225-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
holisticode committed Aug 16, 2022
2 parents 11b925f + 259e95e commit ca3fb42
Show file tree
Hide file tree
Showing 15 changed files with 486 additions and 429 deletions.
23 changes: 16 additions & 7 deletions api/eth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,35 @@ type EthClient interface {
// ethClient websocket ethclient.Client with mutexed api calls and lazy conn (on first call)
// All calls are wrapped in a mutex, and try to create a connection if it doesn't exist yet
type ethClient struct {
ipAddr string
port uint
client ethclient.Client
lock sync.Mutex
ipAddr string
chainID string
port uint
client ethclient.Client
lock sync.Mutex
}

// NewEthClient mainly takes ip/port info for usage in future calls
// Connection can't be initialized in constructor because node is not ready when the constructor is called
// It follows convention of most avalanchego api constructors that can be called without having a ready node
func NewEthClient(ipAddr string, port uint) EthClient {
// default to using the C chain
return NewEthClientWithChainID(ipAddr, port, "C")
}

// NewEthClientWithChainID creates an EthClient initialized to connect to
// ipAddr/port and communicate with the given chainID.
func NewEthClientWithChainID(ipAddr string, port uint, chainID string) EthClient {
return &ethClient{
ipAddr: ipAddr,
port: port,
ipAddr: ipAddr,
port: port,
chainID: chainID,
}
}

// connect attempts to connect with websocket ethclient API
func (c *ethClient) connect() error {
if c.client == nil {
client, err := ethclient.Dial(fmt.Sprintf("ws://%s:%d/ext/bc/C/ws", c.ipAddr, c.port))
client, err := ethclient.Dial(fmt.Sprintf("ws://%s:%d/ext/bc/%s/ws", c.ipAddr, c.port, c.chainID))
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func (c *client) RestartNode(ctx context.Context, name string, opts ...OpOption)
if ret.whitelistedSubnets != "" {
req.WhitelistedSubnets = &ret.whitelistedSubnets
}
req.ChainConfigs = ret.chainConfigs

c.log.Info("restart node %q", name)
return c.controlc.RestartNode(ctx, req)
Expand Down
22 changes: 20 additions & 2 deletions cmd/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,12 @@ func newRestartNodeCommand() *cobra.Command {
"",
"whitelisted subnets (comma-separated)",
)
cmd.PersistentFlags().StringVar(
&chainConfigs,
"chain-configs",
"",
"[optional] JSON string of map that maps from chain id to its config file contents",
)
return cmd
}

Expand All @@ -582,12 +588,24 @@ func restartNodeFunc(cmd *cobra.Command, args []string) error {
}
defer cli.Close()

opts := []client.OpOption{
client.WithExecPath(avalancheGoBinPath),
client.WithWhitelistedSubnets(whitelistedSubnets),
}

if chainConfigs != "" {
chainConfigsMap := make(map[string]string)
if err := json.Unmarshal([]byte(chainConfigs), &chainConfigsMap); err != nil {
return err
}
opts = append(opts, client.WithChainConfigs(chainConfigsMap))
}

ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
info, err := cli.RestartNode(
ctx,
nodeName,
client.WithExecPath(avalancheGoBinPath),
client.WithWhitelistedSubnets(whitelistedSubnets),
opts...,
)
cancel()
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions examples/local/fivenodenetwork/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ava-labs/avalanche-network-runner/local"
"github.com/ava-labs/avalanche-network-runner/network"
"github.com/ava-labs/avalanchego/utils/logging"
"go.uber.org/zap"
)

const (
Expand All @@ -31,9 +32,9 @@ func shutdownOnSignal(
closedOnShutdownChan chan struct{},
) {
sig := <-signalChan
log.Info("got OS signal %s", sig)
log.Info("got OS signal", zap.Stringer("signal", sig))
if err := n.Stop(context.Background()); err != nil {
log.Info("error stopping network: %s", err)
log.Info("error stopping network", zap.Error(err))
}
signal.Reset()
close(signalChan)
Expand All @@ -60,7 +61,7 @@ func main() {
}
binaryPath := fmt.Sprintf("%s%s", goPath, "/src/github.com/ava-labs/avalanchego/build/avalanchego")
if err := run(log, binaryPath); err != nil {
log.Fatal("%s", err)
log.Fatal("fatal error", zap.Error(err))
os.Exit(1)
}
}
Expand All @@ -73,7 +74,7 @@ func run(log logging.Logger, binaryPath string) error {
}
defer func() { // Stop the network when this function returns
if err := nw.Stop(context.Background()); err != nil {
log.Info("error stopping network: %s", err)
log.Info("error stopping network", zap.Error(err))
}
}()

Expand Down
17 changes: 9 additions & 8 deletions examples/local/indepth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/staking"
"github.com/ava-labs/avalanchego/utils/logging"
"go.uber.org/zap"
)

const (
Expand All @@ -34,9 +35,9 @@ func shutdownOnSignal(
closedOnShutdownChan chan struct{},
) {
sig := <-signalChan
log.Info("got OS signal %s", sig)
log.Info("got OS signal", zap.Stringer("signal", sig))
if err := n.Stop(context.Background()); err != nil {
log.Info("error stopping network: %s", err)
log.Info("error stopping network", zap.Error(err))
}
signal.Reset()
close(signalChan)
Expand Down Expand Up @@ -65,7 +66,7 @@ func main() {
}
binaryPath := fmt.Sprintf("%s%s", goPath, "/src/github.com/ava-labs/avalanchego/build/avalanchego")
if err := run(log, binaryPath); err != nil {
log.Fatal("%s", err)
log.Fatal("fatal error", zap.Error(err))
os.Exit(1)
}
}
Expand All @@ -78,7 +79,7 @@ func run(log logging.Logger, binaryPath string) error {
}
defer func() { // Stop the network when this function returns
if err := nw.Stop(context.Background()); err != nil {
log.Info("error stopping network: %s", err)
log.Info("error stopping network", zap.Error(err))
}
}()

Expand All @@ -104,7 +105,7 @@ func run(log logging.Logger, binaryPath string) error {
if err != nil {
return err
}
log.Info("current network's nodes: %s", nodeNames)
log.Info("current network's nodes", zap.Strings("nodes", nodeNames))

// Get one node
node1, err := nw.GetNode(nodeNames[0])
Expand All @@ -117,7 +118,7 @@ func run(log logging.Logger, binaryPath string) error {
if err != nil {
return err
}
log.Info("one node's ID is: %s", node1ID)
log.Info("one node's ID is", zap.Stringer("nodeID", node1ID))

// Add a new node with generated cert/key/nodeid
stakingCert, stakingKey, err := staking.NewCertAndKeyBytes()
Expand All @@ -142,7 +143,7 @@ func run(log logging.Logger, binaryPath string) error {

// Remove one node
nodeToRemove := nodeNames[3]
log.Info("removing node %q", nodeToRemove)
log.Info("removing node", zap.String("name", nodeToRemove))
removeNodeCtx, removeNodeCtxCancel := context.WithTimeout(context.Background(), removeNodeTimeout)
defer removeNodeCtxCancel()
if err := nw.RemoveNode(removeNodeCtx, nodeToRemove); err != nil {
Expand All @@ -163,7 +164,7 @@ func run(log logging.Logger, binaryPath string) error {
return err
}
// Will have the new node but not the removed one
log.Info("updated network's nodes: %s", nodeNames)
log.Info("updated network's nodes", zap.Strings("nodes", nodeNames))
log.Info("Network will run until you CTRL + C to exit...")
// Wait until done shutting down network after SIGINT/SIGTERM
<-closedOnShutdownCh
Expand Down
43 changes: 22 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@ module github.com/ava-labs/avalanche-network-runner
go 1.18

require (
github.com/ava-labs/avalanchego v1.7.16
github.com/ava-labs/coreth v0.8.14-rc.0
github.com/ava-labs/avalanchego v1.7.17
github.com/ava-labs/coreth v0.8.15-rc.2
github.com/ethereum/go-ethereum v1.10.20
github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.3
github.com/onsi/ginkgo/v2 v2.1.3
github.com/onsi/ginkgo/v2 v2.1.4
github.com/onsi/gomega v1.19.0
github.com/otiai10/copy v1.7.0
github.com/prometheus/client_golang v1.12.2
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/spf13/cobra v1.3.0
github.com/stretchr/testify v1.7.2
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
google.golang.org/genproto v0.0.0-20220602131408-e326c6e8e9c8
google.golang.org/genproto v0.0.0-20220712132514-bdd2acd4974d
google.golang.org/grpc v1.47.0
google.golang.org/protobuf v1.28.0
)

require (
github.com/Microsoft/go-winio v0.4.16 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/VictoriaMetrics/fastcache v1.10.0 // indirect
github.com/aead/siphash v1.0.1 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
Expand All @@ -47,7 +46,7 @@ require (
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
github.com/golang/mock v1.6.0 // indirect
Expand All @@ -60,8 +59,8 @@ require (
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/hashicorp/go-bexpr v0.1.10 // indirect
github.com/hashicorp/go-hclog v1.0.0 // indirect
github.com/hashicorp/go-plugin v1.4.3 // indirect
github.com/hashicorp/go-hclog v1.2.2 // indirect
github.com/hashicorp/go-plugin v1.4.4 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce // indirect
Expand All @@ -77,19 +76,20 @@ require (
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/kkdai/bstream v1.0.0 // indirect
github.com/linxGnu/grocksdb v1.6.34 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/pointerstructure v1.2.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
Expand All @@ -99,29 +99,30 @@ require (
github.com/rjeczalik/notify v0.9.2 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.10.0 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/tyler-smith/go-bip39 v1.0.2 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect
golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b // indirect
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
gonum.org/v1/gonum v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gonum.org/v1/gonum v0.11.0 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/urfave/cli.v1 v1.20.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit ca3fb42

Please sign in to comment.