-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(store/v2): don't delete future version when calling LoadVersion #22681
Changes from 3 commits
c379dcf
6a086bd
824ab15
7c0c71d
1e2f13f
91128cd
deeb32d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,7 +250,7 @@ | |
return err | ||
} | ||
|
||
return s.loadVersion(lv, nil) | ||
return s.loadVersion(lv, nil, false) | ||
} | ||
|
||
func (s *Store) LoadVersion(version uint64) error { | ||
|
@@ -259,7 +259,16 @@ | |
defer s.telemetry.MeasureSince(now, "root_store", "load_version") | ||
} | ||
|
||
return s.loadVersion(version, nil) | ||
return s.loadVersion(version, nil, false) | ||
} | ||
|
||
func (s *Store) LoadVersionForOverwriting(version uint64) error { | ||
if s.telemetry != nil { | ||
now := time.Now() | ||
Check warning Code scanning / CodeQL Calling the system time Warning
Calling the system time may be a possible source of non-determinism
|
||
defer s.telemetry.MeasureSince(now, "root_store", "load_version_for_overwriting") | ||
} | ||
|
||
return s.loadVersion(version, nil, true) | ||
} | ||
|
||
// LoadVersionAndUpgrade implements the UpgradeableStore interface. | ||
|
@@ -278,7 +287,7 @@ | |
return errors.New("cannot upgrade while migrating") | ||
} | ||
|
||
if err := s.loadVersion(version, upgrades); err != nil { | ||
if err := s.loadVersion(version, upgrades, true); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -294,12 +303,18 @@ | |
return nil | ||
} | ||
|
||
func (s *Store) loadVersion(v uint64, upgrades *corestore.StoreUpgrades) error { | ||
func (s *Store) loadVersion(v uint64, upgrades *corestore.StoreUpgrades, overrideAfter bool) error { | ||
s.logger.Debug("loading version", "version", v) | ||
|
||
if upgrades == nil { | ||
if err := s.stateCommitment.LoadVersion(v); err != nil { | ||
return fmt.Errorf("failed to load SC version %d: %w", v, err) | ||
if !overrideAfter { | ||
if err := s.stateCommitment.LoadVersion(v); err != nil { | ||
return fmt.Errorf("failed to load SC version %d: %w", v, err) | ||
} | ||
} else { | ||
if err := s.stateCommitment.LoadVersionForOverwriting(v); err != nil { | ||
return fmt.Errorf("failed to load SC version %d: %w", v, err) | ||
} | ||
Comment on lines
+306
to
+317
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid using boolean parameters to control function behavior The Suggestion: Consider refactoring the function to eliminate the boolean parameter. One approach is to split
Refactored code: func (s *Store) loadVersion(v uint64, upgrades *corestore.StoreUpgrades) error {
// Existing behavior without overwriting
// ...
}
func (s *Store) loadVersionForOverwriting(v uint64, upgrades *corestore.StoreUpgrades) error {
// Behavior that allows overwriting future versions
// ...
} This separation enhances clarity by making the function's purpose explicit and aligns with best practices. |
||
} | ||
} else { | ||
// if upgrades are provided, we need to load the version and apply the upgrades | ||
|
Check warning
Code scanning / CodeQL
Iteration over map Warning