-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reading upgrade-info from file
- Loading branch information
1 parent
2bfd7c1
commit c61ad69
Showing
9 changed files
with
286 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package fetchers | ||
|
||
import ( | ||
"context" | ||
cosmovisorPkg "main/pkg/clients/cosmovisor" | ||
"main/pkg/clients/tendermint" | ||
"main/pkg/constants" | ||
"main/pkg/query_info" | ||
|
||
"go.opentelemetry.io/otel/trace" | ||
|
||
"github.com/rs/zerolog" | ||
) | ||
|
||
type CosmovisorUpgradeInfoFetcher struct { | ||
Cosmovisor *cosmovisorPkg.Cosmovisor | ||
QueryUpgrades bool | ||
Logger zerolog.Logger | ||
Tracer trace.Tracer | ||
} | ||
|
||
func NewCosmovisorUpgradeInfoFetcher( | ||
logger zerolog.Logger, | ||
cosmovisor *cosmovisorPkg.Cosmovisor, | ||
tracer trace.Tracer, | ||
) *CosmovisorUpgradeInfoFetcher { | ||
return &CosmovisorUpgradeInfoFetcher{ | ||
Logger: logger.With().Str("component", "cosmovisor_upgrade_info").Logger(), | ||
Cosmovisor: cosmovisor, | ||
Tracer: tracer, | ||
} | ||
} | ||
|
||
func (n *CosmovisorUpgradeInfoFetcher) Enabled() bool { | ||
return n.Cosmovisor != nil | ||
} | ||
|
||
func (n *CosmovisorUpgradeInfoFetcher) Name() constants.FetcherName { | ||
return constants.FetcherNameCosmovisorUpgradeInfo | ||
} | ||
|
||
func (n *CosmovisorUpgradeInfoFetcher) Dependencies() []constants.FetcherName { | ||
return []constants.FetcherName{constants.FetcherNameNodeStatus} | ||
} | ||
|
||
func (n *CosmovisorUpgradeInfoFetcher) Get(ctx context.Context, data ...interface{}) (interface{}, []query_info.QueryInfo) { | ||
childCtx, span := n.Tracer.Start( | ||
ctx, | ||
"Fetcher "+string(n.Name()), | ||
) | ||
defer span.End() | ||
|
||
if len(data) < 1 { | ||
panic("data is empty") | ||
} | ||
|
||
status, statusConverted := Convert[tendermint.StatusResponse](data[0]) | ||
if !statusConverted { | ||
n.Logger.Trace().Msg("Node status is empty, cannot check if the upgrade-info plan is in the past.") | ||
return nil, []query_info.QueryInfo{} | ||
} | ||
|
||
upgradeInfo, queryInfo, err := n.Cosmovisor.GetUpgradeInfo(childCtx) | ||
if err != nil { | ||
n.Logger.Error().Err(err).Msg("Could not fetch upgrade info") | ||
return nil, []query_info.QueryInfo{queryInfo} | ||
} | ||
|
||
if upgradeInfo == nil { | ||
return nil, []query_info.QueryInfo{} | ||
} | ||
|
||
if upgradeInfo.Height < status.Result.SyncInfo.LatestBlockHeight { | ||
n.Logger.Trace(). | ||
Int64("node_height", status.Result.SyncInfo.LatestBlockHeight). | ||
Int64("upgrade_height", upgradeInfo.Height). | ||
Msg("Cosmovisor upgrade-info is in the past, skipping.") | ||
return nil, []query_info.QueryInfo{queryInfo} | ||
} | ||
|
||
return upgradeInfo, []query_info.QueryInfo{queryInfo} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.