-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prevent incompatible alan version downgrade (#1762)
* draft * get the alan network name from network config only * clean * lint * fix testNetworkName * if config is not found, mark the migration as completed * make alanforkname const
- Loading branch information
1 parent
cc21ab8
commit c77ee4e
Showing
7 changed files
with
85 additions
and
37 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
44 changes: 44 additions & 0 deletions
44
migrations/migration_4_configlock_add_alan_fork_to_network_name.go
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,44 @@ | ||
package migrations | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/ssvlabs/ssv/networkconfig" | ||
"github.com/ssvlabs/ssv/storage/basedb" | ||
) | ||
|
||
// This migration adds the Alan fork name to the network name | ||
var migration_4_configlock_add_alan_fork_to_network_name = Migration{ | ||
Name: "migration_4_configlock_add_alan_fork_to_network_name", | ||
Run: func(ctx context.Context, logger *zap.Logger, opt Options, key []byte, completed CompletedFunc) error { | ||
return opt.Db.Update(func(txn basedb.Txn) error { | ||
nodeStorage, err := opt.nodeStorage(logger) | ||
if err != nil { | ||
return fmt.Errorf("failed to get node storage: %w", err) | ||
} | ||
|
||
config, found, err := nodeStorage.GetConfig(txn) | ||
if err != nil { | ||
return fmt.Errorf("failed to get config: %w", err) | ||
} | ||
|
||
// If config is not found, it means the node is not initialized yet | ||
if found { | ||
networkConfig, err := networkconfig.GetNetworkConfigByName(config.NetworkName) | ||
if err != nil { | ||
return fmt.Errorf("failed to get network config by name: %w", err) | ||
} | ||
|
||
config.NetworkName = networkConfig.AlanForkNetworkName() | ||
if err := nodeStorage.SaveConfig(txn, config); err != nil { | ||
return fmt.Errorf("failed to save config: %w", err) | ||
} | ||
} | ||
|
||
return completed(txn) | ||
}) | ||
}, | ||
} |
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