From 5b31ec1916a0b2fd10229ed989a673073c1dd01a Mon Sep 17 00:00:00 2001 From: adriantpaez Date: Thu, 14 Sep 2023 09:01:30 +0000 Subject: [PATCH] refactor: minor refactor --- cli/update.go | 17 +++++++++++++++++ pkg/daemon/daemon.go | 23 ++++++++++++++++------- pkg/daemon/egn_daemon.go | 37 +++++++++++++++++++++++-------------- 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/cli/update.go b/cli/update.go index 0f5617fc..9c2e4223 100644 --- a/cli/update.go +++ b/cli/update.go @@ -7,6 +7,7 @@ import ( "github.com/NethermindEth/eigenlayer/cli/prompter" "github.com/NethermindEth/eigenlayer/pkg/daemon" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -20,10 +21,14 @@ func UpdateCmd(d daemon.Daemon, p prompter.Prompter) *cobra.Command { cmd := cobra.Command{ Use: "update", RunE: func(cmd *cobra.Command, args []string) error { + log.Info("Pulling package...") pullResult, err := d.PullUpdate(instanceID, url, daemon.PullTarget{Version: version, Commit: commit}) if err != nil { return err } + log.Info("Package pulled successfully") + logVersionChange(pullResult.OldVersion, pullResult.NewVersion) + logCommitChange(pullResult.OldCommit, pullResult.NewCommit) printOptionsTable(cmd.OutOrStdout(), pullResult.OldOptions, pullResult.MergedOptions) return err }, @@ -37,6 +42,18 @@ func UpdateCmd(d daemon.Daemon, p prompter.Prompter) *cobra.Command { return &cmd } +func logVersionChange(oldVersion, newVersion string) { + if newVersion != "" { + log.Infof("Package version changed: %s -> %s", oldVersion, newVersion) + } +} + +func logCommitChange(oldCommit, newCommit string) { + if newCommit != "" { + log.Infof("Package commit changed from %s -> %s", oldCommit, newCommit) + } +} + type tableOptionItem struct { name string old string diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index 6e59a69c..7c553b54 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -15,6 +15,8 @@ type Daemon interface { // calling Pull all is ready to call Install. Pull(url string, ref PullTarget, force bool) (PullResult, error) + // PullUpdate downloads a node software package from the given URL and returns + // the result of merging both packages configs. PullUpdate(instanceID string, url string, ref PullTarget) (PullUpdateResult, error) // Install downloads and installs a node software package using the provided options, @@ -150,23 +152,30 @@ type PullResult struct { } type PullUpdateResult struct { - // Version is the version of the pulled package. - Version string + // OldVersion is the version of the old package. + OldVersion string - // SpecVersion is the version of the Eigenlayer AVS Node Specification the instance - // targets. The version must match the regex `^\d+\.\d+\.\d+$`. - SpecVersion string + // NweVersion is the version of the new package. + NewVersion string - // Commit hash of the pulled package. - Commit string + // OldCommit is the commit hash of the old package. + OldCommit string + + // NewCommit is the commit hash of the new package. + NewCommit string // HasPlugin is true if the package has a plugin. HasPlugin bool + // OldOptions is the list of options of the old package. OldOptions []Option + // NewOptions is the list of options of the new package. NewOptions []Option + // MergedOptions is the list of options of the new package merged with the + // old package. These options the ones that will be used for the new instance + // and should be filled by the user. MergedOptions []Option // HardwareRequirements is the hardware requirements specified in the package manifest. diff --git a/pkg/daemon/egn_daemon.go b/pkg/daemon/egn_daemon.go index 1c9d1baf..7cf2bbf7 100644 --- a/pkg/daemon/egn_daemon.go +++ b/pkg/daemon/egn_daemon.go @@ -361,20 +361,8 @@ func (d *EgnDaemon) PullUpdate(instanceID string, url string, ref PullTarget) (P if err != nil { return PullUpdateResult{}, err } - ok, err := pkgHandler.CommitPrecedence(instance.Commit, ref.Commit) - if err != nil { - return PullUpdateResult{}, err - } - if !ok { - return PullUpdateResult{}, fmt.Errorf("%w: current commit %s is not previous to the update commit %s", ErrInvalidUpdateCommit, instance.Commit, ref.Commit) - } - err = pkgHandler.CheckoutCommit(ref.Commit) - if err != nil { - return PullUpdateResult{}, err - } } else { - var latestVersion string - latestVersion, err = pkgHandler.LatestVersion() + latestVersion, err := pkgHandler.LatestVersion() if err != nil { return PullUpdateResult{}, err } @@ -386,6 +374,24 @@ func (d *EgnDaemon) PullUpdate(instanceID string, url string, ref PullTarget) (P return PullUpdateResult{}, err } } + // Get new commit hash + newCommit, err := pkgHandler.CurrentCommitHash() + if err != nil { + return PullUpdateResult{}, err + } + // Check commit precedence + ok, err := pkgHandler.CommitPrecedence(instance.Commit, newCommit) + if err != nil { + return PullUpdateResult{}, err + } + if !ok { + return PullUpdateResult{}, fmt.Errorf("%w: current commit %s is not previous to the update commit %s", ErrInvalidUpdateCommit, instance.Commit, ref.Commit) + } + // Get new version + newVersion, err := pkgHandler.CurrentVersion() + if err != nil { + return PullUpdateResult{}, err + } // Get new options profileNew, err := pkgHandler.Profile(instance.Profile) @@ -426,7 +432,10 @@ func (d *EgnDaemon) PullUpdate(instanceID string, url string, ref PullTarget) (P } return PullUpdateResult{ - Version: ref.Version, + OldVersion: instance.Version, + NewVersion: newVersion, + OldCommit: instance.Commit, + NewCommit: newCommit, OldOptions: optionsOld, NewOptions: optionsNew, MergedOptions: mergedOptions,