Skip to content
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

feat: Cudos partial balance and delegations movement #387

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ func (app *App) GetSubspace(moduleName string) paramstypes.Subspace {
return subspace
}

func getNetworkInfo(app *App, ctx *sdk.Context, manifest *UpgradeManifest, expectedChainIdOfMergeSourceGenesis string) (*NetworkConfig, error) {
func getNetworkInfo(app *App, ctx sdk.Context, manifest *UpgradeManifest, expectedChainIdOfMergeSourceGenesis string) (*NetworkConfig, error) {
// Load network config from file if given
var networkInfo *NetworkConfig
var err error
Expand Down Expand Up @@ -761,7 +761,7 @@ func getNetworkInfo(app *App, ctx *sdk.Context, manifest *UpgradeManifest, expec
return networkInfo, nil
}

func LoadAndParseMergeSourceInputFiles(app *App, ctx *sdk.Context, manifest *UpgradeManifest) (*GenesisData, *NetworkConfig, error) {
func LoadAndParseMergeSourceInputFiles(app *App, ctx sdk.Context, manifest *UpgradeManifest) (*GenesisData, *NetworkConfig, error) {

cudosJsonData, cudosGenDoc, err := LoadCudosGenesis(app, manifest)

Expand All @@ -776,7 +776,7 @@ func LoadAndParseMergeSourceInputFiles(app *App, ctx *sdk.Context, manifest *Upg

cudosConfig := NewCudosMergeConfig(networkInfo.CudosMerge)

genesisData, err := parseGenesisData(*cudosJsonData, cudosGenDoc, cudosConfig, manifest)
genesisData, err := parseGenesisData(app, ctx, *cudosJsonData, cudosGenDoc, cudosConfig, manifest)
if err != nil {
return nil, nil, fmt.Errorf("failed to parse genesis data: %w", err)
}
Expand All @@ -793,7 +793,7 @@ func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {

manifest := NewUpgradeManifest()

cudosGenesisData, networkInfo, err := LoadAndParseMergeSourceInputFiles(app, &ctx, manifest)
cudosGenesisData, networkInfo, err := LoadAndParseMergeSourceInputFiles(app, ctx, manifest)
if err != nil {
return nil, fmt.Errorf("cudos merge: %w", err)
}
Expand Down
21 changes: 21 additions & 0 deletions app/ordered_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ func (om *OrderedMap[K, V]) MustGet(key K) V {
return value
}

func (om *OrderedMap[K, V]) GetOrSetDefault(key K, defaultValue V) (V, bool) {
if value, exists := om.Get(key); exists {
return value, false
} else {
om.Set(key, defaultValue)
return om.MustGet(key), true
}
}

// Iterate returns a channel that yields key-value pairs in insertion order
func (om *OrderedMap[K, V]) Iterate() <-chan Pair[K, V] {
ch := make(chan Pair[K, V])
go func() {
for _, key := range om.keys {
ch <- Pair[K, V]{Key: key, Value: om.MustGet(key)}
}
close(ch)
}()
return ch
}
Comment on lines +85 to +104
Copy link
Collaborator

@pbukva pbukva Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that this solution does a lot of shuffling data through the tread safe queueue (most probably using mutex) - internally the channel is implemented effectivelly as a thread safe queue.

This involves literally copying value of every single element of a collection the iteration goes through in to the channel (in this case copying every single Pair[K, V] value) over to channel queue ...

Looking at this solely from the performance perspective, it is not worth it.
👉 Though I do understand, that given the resulting performance impact in our use case, it is practivally irrelevant + this approach makes code more lean and so more readable ...


func (om *OrderedMap[K, V]) Has(key K) bool {
_, exists := om.Get(key)
return exists
Expand Down
Loading
Loading