Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/interchaincmd/relayercmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,15 @@ func CallDeploy(_ []string, flags DeployFlags, network models.Network) error {
if len(configSpec.sources) > 0 && len(configSpec.destinations) > 0 {
// relayer fails for empty configs
binPath, err := relayer.DeployRelayer(
app,
flags.Version,
flags.BinPath,
app.GetICMRelayerBinDir(),
configPath,
logPath,
runFilePath,
storageDir,
network,
)
if err != nil {
if bs, err := os.ReadFile(logPath); err == nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/interchaincmd/relayercmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ func CallStart(_ []string, flags StartFlags, network models.Network) error {
if !utils.FileExists(relayerConfigPath) {
return fmt.Errorf("there is no relayer configuration available")
} else if binPath, err := relayer.DeployRelayer(
app,
flags.Version,
flags.BinPath,
app.GetICMRelayerBinDir(),
relayerConfigPath,
app.GetLocalRelayerLogPath(network.Kind),
app.GetLocalRelayerRunPath(network.Kind),
app.GetLocalRelayerStorageDir(network.Kind),
network,
); err != nil {
return err
} else if network.Kind == models.Local {
Expand Down
2 changes: 2 additions & 0 deletions cmd/networkcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ func Start(flags StartFlags, printEndpoints bool) error {
relayerBinPath = extraLocalNetworkData.RelayerPath
}
if relayerBinPath, err := relayer.DeployRelayer(
app,
flags.RelayerVersion,
relayerBinPath,
app.GetICMRelayerBinDir(),
relayerConfigPath,
app.GetLocalRelayerLogPath(models.Local),
app.GetLocalRelayerRunPath(models.Local),
app.GetLocalRelayerStorageDir(models.Local),
models.NewLocalNetwork(),
); err != nil {
return err
} else if err := localnet.WriteExtraLocalNetworkData(app, "", relayerBinPath, "", ""); err != nil {
Expand Down
36 changes: 15 additions & 21 deletions pkg/application/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,32 +76,26 @@ func (d downloader) DownloadWithTee(url string, path string) ([]byte, error) {
}

func (d downloader) DownloadWithCache(url string, path string, duration time.Duration) ([]byte, error) {
var data []byte
var useCache bool

// Check if cache file exists and is recent
if fileInfo, err := os.Stat(path); err == nil {
data, err := d.Download(url)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making downloading from git the first approach so that users always get newest version. If it fails we will default to cache

if err != nil {
// if we can't download url due to too many requests err, check our cache
// Check if cache file exists and is recent
fileInfo, err := os.Stat(path)
if err != nil {
return nil, fmt.Errorf("unable to download or read from cache for %s", url)
}
if time.Since(fileInfo.ModTime()) < duration {
// Cache is valid, read from it
data, err = os.ReadFile(path)
if err == nil {
useCache = true
if err != nil {
return nil, fmt.Errorf("unable to read from cache for path %s", path)
}
return data, nil
}
}

// If cache is not valid or doesn't exist, download
if !useCache {
var err error
data, err = d.Download(url)
if err != nil {
return nil, err
}

// Save to cache
if err := os.MkdirAll(filepath.Dir(path), constants.DefaultPerms755); err == nil {
_ = os.WriteFile(path, data, constants.WriteReadReadPerms)
}
// Save to cache
if err := os.MkdirAll(filepath.Dir(path), constants.DefaultPerms755); err == nil {
_ = os.WriteFile(path, data, constants.WriteReadReadPerms)
}

return data, nil
Expand Down Expand Up @@ -213,7 +207,7 @@ func (downloader) doAPIRequest(url, token string) (io.ReadCloser, error) {
if resp.StatusCode != http.StatusOK {
// http.StatusForbidden is also obtained when hitting github API rate limits
if resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode == http.StatusForbidden {
if retries <= 5 {
if retries <= 10 {
retries++
toSleep := time.Duration(retries) * 10 * time.Second
time.Sleep(toSleep)
Expand Down
3 changes: 2 additions & 1 deletion pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const (
LatestPreReleaseVersionTag = "latest-prerelease"
LatestReleaseVersionTag = "latest"
DefaultAvalancheGoVersion = LatestReleaseVersionTag
DefaultRelayerVersion = LatestPreReleaseVersionTag
DefaultRelayerVersion = LatestReleaseVersionTag
DefaultSignatureAggregatorVersion = LatestReleaseVersionTag

FujiAPIEndpoint = "https://api.avax-test.network"
Expand Down Expand Up @@ -238,6 +238,7 @@ const (

ICMKeyName = "cli-teleporter-deployer"
ICMRelayerKeyName = "cli-awm-relayer"
RelayerRepoName = "relayer"
DefaultRelayerAmount = float64(10)

// to not interfere with other node services
Expand Down
2 changes: 2 additions & 0 deletions pkg/dependencies/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func GetLatestCLISupportedDependencyVersion(app *application.Avalanche, dependen
return parsedDependency.SubnetEVM[networkName].LatestVersion, nil
case constants.SignatureAggregatorRepoName:
return parsedDependency.SignatureAggregator[networkName].LatestVersion, nil
case constants.RelayerRepoName:
return parsedDependency.Relayer[networkName].LatestVersion, nil
default:
return "", fmt.Errorf("unsupported dependency: %s", dependencyName)
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/interchain/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"syscall"
"time"

"github.com/ava-labs/avalanche-cli/pkg/dependencies"

"github.com/ava-labs/avalanche-cli/pkg/application"
"github.com/ava-labs/avalanche-cli/pkg/binutils"
"github.com/ava-labs/avalanche-cli/pkg/constants"
Expand Down Expand Up @@ -97,20 +99,22 @@ type relayerRunFile struct {
}

func DeployRelayer(
app *application.Avalanche,
version string,
binPath string,
binDir string,
configPath string,
logFilePath string,
runFilePath string,
storageDir string,
network models.Network,
) (string, error) {
if err := RelayerCleanup(runFilePath, logFilePath, storageDir); err != nil {
return "", err
}
if binPath == "" {
var err error
binPath, err = InstallRelayer(binDir, version)
binPath, err = InstallRelayer(app, binDir, version, network)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -230,17 +234,16 @@ func GetLatestRelayerPreReleaseVersion() (string, error) {
)
}

func InstallRelayer(binDir, version string) (string, error) {
func InstallRelayer(app *application.Avalanche, binDir, version string, network models.Network) (string, error) {
var err error
if version == "" || version == constants.LatestPreReleaseVersionTag {
var err error
version, err = GetLatestRelayerPreReleaseVersion()
if err != nil {
return "", err
}
}
if version == constants.LatestReleaseVersionTag {
var err error
version, err = GetLatestRelayerReleaseVersion()
version, err = dependencies.GetLatestCLISupportedDependencyVersion(app, constants.RelayerRepoName, network, nil)
if err != nil {
return "", err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/localnet/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,15 @@ func MigrateANRToTmpNet(
if utils.FileExists(relayerConfigPath) {
printFunc("Restarting relayer")
if _, err := relayer.DeployRelayer(
app,
constants.DefaultRelayerVersion,
relayerBinPath,
app.GetICMRelayerBinDir(),
relayerConfigPath,
app.GetLocalRelayerLogPath(clusterToReloadNetwork.Kind),
app.GetLocalRelayerRunPath(clusterToReloadNetwork.Kind),
app.GetLocalRelayerStorageDir(clusterToReloadNetwork.Kind),
clusterToReloadNetwork,
); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/models/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ type CLIDependencyMap struct {
SubnetEVM map[string]NetworkVersion `json:"subnet-evm"`
AvalancheGo map[string]NetworkVersion `json:"avalanchego"`
SignatureAggregator map[string]NetworkVersion `json:"signature-aggregator"`
Relayer map[string]NetworkVersion `json:"relayer"`
}
Loading