Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
arturrez committed Aug 22, 2024
1 parent bb6d31f commit 8999b67
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 33 deletions.
3 changes: 2 additions & 1 deletion cmd/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewCommand() *cobra.Command {
cmd.PersistentFlags().StringVar(&logDir, "log-dir", "", "log directory")
cmd.PersistentFlags().StringVar(&endpoint, "endpoint", "localhost:8080", "server endpoint")
cmd.PersistentFlags().DurationVar(&dialTimeout, "dial-timeout", 10*time.Second, "server dial timeout")
cmd.PersistentFlags().DurationVar(&requestTimeout, "request-timeout", 300*time.Minute, "client request timeout")
cmd.PersistentFlags().DurationVar(&requestTimeout, "request-timeout", 3*time.Minute, "client request timeout")

cmd.AddCommand(
newRPCVersionCommand(),
Expand Down Expand Up @@ -322,6 +322,7 @@ func startFunc(*cobra.Command, []string) error {

if fuji {
networkID = avagoConstants.FujiID
requestTimeout = 5 * time.Hour // increase timeout for fuji network
}
opts := []client.OpOption{
client.WithNumNodes(numNodes),
Expand Down
17 changes: 4 additions & 13 deletions local/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (ln *localNetwork) getNode() node.Node {
return node
}

func (ln *localNetwork) getValidatorWeight() uint64 {
func (ln *localNetwork) getMinValidatorWeight() uint64 {
switch ln.networkID {
case avagoConstants.FujiID:
return genesis.FujiParams.MinValidatorStake
Expand All @@ -108,18 +108,9 @@ func (ln *localNetwork) getValidatorWeight() uint64 {
}

// get node client URI for an arbitrary node in the network
func (ln *localNetwork) getClientURI() (string, error) {
clientURI := ""
func (ln *localNetwork) getClientURI() (string, error) { //nolint
node := ln.getNode()
switch ln.networkID {
case avagoConstants.FujiID:
// clientURI = constants.FujiAPIEndpoint
clientURI = fmt.Sprintf("http://%s:%d", node.GetURL(), node.GetAPIPort())
case avagoConstants.MainnetID:
return "", fmt.Errorf("not supported")
default:
clientURI = fmt.Sprintf("http://%s:%d", node.GetURL(), node.GetAPIPort())
}
clientURI := fmt.Sprintf("http://%s:%d", node.GetURL(), node.GetAPIPort())
ln.log.Info("getClientURI",
zap.String("nodeName", node.GetName()),
zap.String("uri", clientURI))
Expand Down Expand Up @@ -953,7 +944,7 @@ func (ln *localNetwork) addPrimaryValidators(
NodeID: nodeID,
Start: uint64(time.Now().Add(validationStartOffset).Unix()),
End: uint64(time.Now().Add(validationDuration).Unix()),
Wght: ln.getValidatorWeight(),
Wght: ln.getMinValidatorWeight(),
},
Subnet: ids.Empty,
},
Expand Down
5 changes: 0 additions & 5 deletions local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,6 @@ func NewDefaultConfigNNodes(binaryPath string, numNodes uint32, networkID uint32
if !utils.IsPublicNetwork(networkID) {
nodeConfig.IsBeacon = true
}
/* disable partial sync for now
else {
nodeConfig.Flags[config.PartialSyncPrimaryNetworkKey] = true
}
*/
nodeConfigs = append(nodeConfigs, nodeConfig)
port += 2
}
Expand Down
9 changes: 9 additions & 0 deletions server/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sort"
"strings"
"sync"
"time"

"github.com/ava-labs/avalanche-network-runner/local"
"github.com/ava-labs/avalanche-network-runner/network"
Expand Down Expand Up @@ -846,3 +847,11 @@ func (lc *localNetwork) Stop(ctx context.Context) {
}
})
}

func (lc *localNetwork) GetWaitForHealthyTimeout() time.Duration {
if lc.networkID == avago_constants.FujiID {
return 6 * time.Hour
} else {
return 3 * time.Minute
}
}
24 changes: 11 additions & 13 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ const (
MinNodes uint32 = 1
DefaultNodes uint32 = 5

stopTimeout = 30 * time.Second
defaultStartTimeout = 300 * time.Minute
waitForHealthyTimeout = 300 * time.Minute
stopTimeout = 30 * time.Second

networkRootDirPrefix = "network"
TimeParseLayout = "2006-01-02 15:04:05"
Expand Down Expand Up @@ -367,15 +365,15 @@ func (s *server) Start(_ context.Context, req *rpcpb.StartRequest) (*rpcpb.Start
zap.String("global-node-config", globalNodeConfig),
)

ctx, cancel := context.WithTimeout(context.Background(), waitForHealthyTimeout)
ctx, cancel := context.WithTimeout(context.Background(), s.network.GetWaitForHealthyTimeout())
defer cancel()
if err := s.network.Start(ctx); err != nil {
s.log.Warn("start failed to complete", zap.Error(err))
s.stopAndRemoveNetwork(nil)
return nil, err
}

ctx, cancel = context.WithTimeout(context.Background(), waitForHealthyTimeout)
ctx, cancel = context.WithTimeout(context.Background(), s.network.GetWaitForHealthyTimeout())
defer cancel()
chainIDs, err := s.network.CreateChains(ctx, chainSpecs)
if err != nil {
Expand Down Expand Up @@ -426,7 +424,7 @@ func (s *server) updateClusterInfo() {
func (s *server) WaitForHealthy(ctx context.Context, _ *rpcpb.WaitForHealthyRequest) (*rpcpb.WaitForHealthyResponse, error) {
s.log.Debug("WaitForHealthy")

ctx, cancel := context.WithTimeout(ctx, waitForHealthyTimeout)
ctx, cancel := context.WithTimeout(ctx, s.network.GetWaitForHealthyTimeout())
defer cancel()

for {
Expand Down Expand Up @@ -570,7 +568,7 @@ func (s *server) AddPermissionlessDelegator(
}
}

ctx, cancel := context.WithTimeout(context.Background(), waitForHealthyTimeout)
ctx, cancel := context.WithTimeout(context.Background(), s.network.GetWaitForHealthyTimeout())
defer cancel()
err := s.network.AddPermissionlessDelegators(ctx, delegatorSpecList)
if err != nil {
Expand Down Expand Up @@ -627,7 +625,7 @@ func (s *server) AddPermissionlessValidator(
s.clusterInfo.Healthy = false
s.clusterInfo.CustomChainsHealthy = false

ctx, cancel := context.WithTimeout(context.Background(), waitForHealthyTimeout)
ctx, cancel := context.WithTimeout(context.Background(), s.network.GetWaitForHealthyTimeout())
defer cancel()
err := s.network.AddPermissionlessValidators(ctx, validatorSpecList)

Expand Down Expand Up @@ -685,7 +683,7 @@ func (s *server) AddSubnetValidators(
s.clusterInfo.Healthy = false
s.clusterInfo.CustomChainsHealthy = false

ctx, cancel := context.WithTimeout(context.Background(), waitForHealthyTimeout)
ctx, cancel := context.WithTimeout(context.Background(), s.network.GetWaitForHealthyTimeout())
defer cancel()
err := s.network.AddSubnetValidators(ctx, validatorSpecList)

Expand Down Expand Up @@ -743,7 +741,7 @@ func (s *server) RemoveSubnetValidator(
s.clusterInfo.Healthy = false
s.clusterInfo.CustomChainsHealthy = false

ctx, cancel := context.WithTimeout(context.Background(), waitForHealthyTimeout)
ctx, cancel := context.WithTimeout(context.Background(), s.network.GetWaitForHealthyTimeout())
defer cancel()
err := s.network.RemoveSubnetValidator(ctx, validatorSpecList)

Expand Down Expand Up @@ -801,7 +799,7 @@ func (s *server) TransformElasticSubnets(
s.clusterInfo.Healthy = false
s.clusterInfo.CustomChainsHealthy = false

ctx, cancel := context.WithTimeout(context.Background(), waitForHealthyTimeout)
ctx, cancel := context.WithTimeout(context.Background(), s.network.GetWaitForHealthyTimeout())
defer cancel()
txIDs, assetIDs, err := s.network.TransformSubnets(ctx, elasticSubnetSpecList)

Expand Down Expand Up @@ -852,7 +850,7 @@ func (s *server) CreateSubnets(_ context.Context, req *rpcpb.CreateSubnetsReques
s.clusterInfo.Healthy = false
s.clusterInfo.CustomChainsHealthy = false

ctx, cancel := context.WithTimeout(context.Background(), waitForHealthyTimeout)
ctx, cancel := context.WithTimeout(context.Background(), s.network.GetWaitForHealthyTimeout())
defer cancel()
subnetIDs, err := s.network.CreateSubnets(ctx, subnetSpecs)
if err != nil {
Expand Down Expand Up @@ -1377,7 +1375,7 @@ func (s *server) LoadSnapshot(_ context.Context, req *rpcpb.LoadSnapshotRequest)
return nil, err
}

ctx, cancel := context.WithTimeout(context.Background(), waitForHealthyTimeout)
ctx, cancel := context.WithTimeout(context.Background(), s.network.GetWaitForHealthyTimeout())
defer cancel()
err = s.network.AwaitHealthyAndUpdateNetworkInfo(ctx)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion utils/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ const (
DefaultNetworkID = 1337
DefaultNumNodes = 5
FirstAPIPort = 9650
FujiAPIEndpoint = "https://api.avax-test.network"
)

0 comments on commit 8999b67

Please sign in to comment.