Skip to content

Commit

Permalink
only modify the store if there is a change.. add more robust logging …
Browse files Browse the repository at this point in the history
…so we can see what exactly is happening.
  • Loading branch information
dekm committed Mar 19, 2024
1 parent 75c0694 commit 720c0f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions x/gridnode/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (k Keeper) QueryAllDelegations(ctx context.Context) ([]types.DelegationInfo
var delegationData types.DelegationData
err := json.Unmarshal(value, &delegationData)
if err != nil {
fmt.Printf("Error unmarshalling delegation data: %v\n", err)
fmt.Printf("Error unmarshalling delegation data: %v. Raw data: %x\n", err, value)
return // or return an error
}

Expand Down Expand Up @@ -395,7 +395,7 @@ func (k Keeper) SetDelegatedAmount(ctx context.Context, delegator sdk.AccAddress
// Handle negative amounts, perhaps log an error or panic
}
store.Set(k.keyForDelegator(delegator), amount.BigInt().Bytes())
//fmt.Println("Set delegated amount for address", delegator, "to:", amount)
fmt.Println("Set delegated amount for address", delegator, "to:", amount)
}

// AddUnbondingEntry adds a new unbonding entry for a given account.
Expand Down
31 changes: 18 additions & 13 deletions x/gridnode/module/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func BeginBlocker(goCtx context.Context, k keeper.Keeper) {
continue
}

var entriesChanged bool

// Filter out entries that have completed unbonding
newEntries := make([]types.UnbondingEntry, 0, len(entries))
for _, entry := range entries {
Expand Down Expand Up @@ -85,27 +87,30 @@ func BeginBlocker(goCtx context.Context, k keeper.Keeper) {
sdk.NewAttribute(types.AttributeKeyAmount, strconv.FormatInt(entry.Amount, 10)),
),
)
entriesChanged = true
} else {
newEntries = append(newEntries, entry)
}
}

// Update the store with the new list of unbonding entries
if len(newEntries) == 0 {
fmt.Printf("All unbonding entries processed for key: %s. Deleting key from store.\n", key)
store.Delete(key)
} else {
newBz, err := json.Marshal(newEntries)
if err != nil {
fmt.Printf("Error marshalling new entries for key %x: %v\n", key, err)
continue
}
if entriesChanged {
if len(newEntries) == 0 {
fmt.Printf("All unbonding entries processed for key: %s. Deleting key from store.\n", key)
store.Delete(key)
} else {
newBz, err := json.Marshal(newEntries)
if err != nil {
fmt.Printf("Error marshalling new entries for key %x: %v\n", key, err)
continue
}

// Log the data that is about to be stored
fmt.Printf("Updating store for key %x with data: %s\n", key, string(newBz))
// Log the data that is about to be stored
fmt.Printf("Updating store for key %x with data: %s\n", key, string(newBz))

store.Set(key, newBz)
fmt.Printf("Updated store for key %x\n", key)
store.Set(key, newBz)
fmt.Printf("Updated store for key %x\n", key)
}
}
}

Expand Down

0 comments on commit 720c0f0

Please sign in to comment.