Skip to content

Commit

Permalink
fix: account for both mainnet and fairground versions
Browse files Browse the repository at this point in the history
Signed-off-by: Elias Van Ootegem <elias@vega.xyz>
  • Loading branch information
EVODelavega committed Apr 18, 2024
1 parent fcdbccf commit 9791054
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/execution/future/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ func (m *Market) PostRestore(ctx context.Context) error {
}

// Disposal slippage was set as part of this upgrade, send event to ensure datanode is updated.
if vegacontext.InProgressUpgradeFrom(ctx, "v0.75.8") {
if vegacontext.InProgressUpgradeFromMultiple(ctx, "v0.75.8", "v0.75.7") {
m.broker.Send(events.NewMarketUpdatedEvent(ctx, *m.mkt))
}

Expand Down
6 changes: 3 additions & 3 deletions core/governance/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (e *Engine) OnStateLoaded(ctx context.Context) error {
}

// update market events may require updating to set the liquidation strategy slippage
if vgcontext.InProgressUpgradeFrom(ctx, "v0.75.8") {
if vgcontext.InProgressUpgradeFromMultiple(ctx, "v0.75.8", "v0.75.7") {
evts := make([]events.Event, 0, len(e.activeProposals)/2)
for _, p := range e.activeProposals {
if !p.Proposal.IsMarketUpdate() {
Expand Down Expand Up @@ -277,7 +277,7 @@ func (e *Engine) restoreActiveProposals(ctx context.Context, active *types.Gover
vevts := []events.Event{}
e.log.Debug("restoring active proposals snapshot", logging.Int("nproposals", len(active.Proposals)))
for _, p := range active.Proposals {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.75.8") {
if vgcontext.InProgressUpgradeFromMultiple(ctx, "v0.75.8", "v0.75.7") {
if p.Proposal.IsNewMarket() || p.Proposal.IsMarketUpdate() {
setLiquidationSlippage(p.Proposal)
}
Expand Down Expand Up @@ -350,7 +350,7 @@ func (e *Engine) restoreBatchActiveProposals(ctx context.Context, active *types.

evts = append(evts, events.NewProposalEventFromProto(ctx, bp.BatchProposal.ToProto()))
for _, p := range bp.BatchProposal.Proposals {
if vgcontext.InProgressUpgradeFrom(ctx, "v0.75.8") {
if vgcontext.InProgressUpgradeFromMultiple(ctx, "v0.75.8", "v0.75.7") {
if p.IsMarketUpdate() || p.IsNewMarket() {
setLiquidationSlippage(p)
}
Expand Down
20 changes: 20 additions & 0 deletions libs/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ func InProgressUpgradeFrom(ctx context.Context, from string) bool {
return from == si.version && si.upgrade
}

// InProgressUpgradeFromMultiple returns whether the data in the contexts tells us that the
// node is restoring from a snapshot taken for a protocol-upgrade by one of the given versions.
// This can be useful in situations where mainnet and fairground are running different versions.
func InProgressUpgradeFromMultiple(ctx context.Context, versions ...string) bool {
v := ctx.Value(snapshotKey)
if v == nil {
return false
}
si, ok := v.(snapshotInfo)
if !ok || !si.upgrade {
return false
}
for _, from := range versions {
if from == si.version {
return true
}
}
return false
}

// InProgressUpgrade returns whether the data in the contexts tells us that the
// node is restoring from a snapshot taken for a protocol-upgrade.
func InProgressUpgrade(ctx context.Context) bool {
Expand Down

0 comments on commit 9791054

Please sign in to comment.