Skip to content

Commit

Permalink
Merge branch 'main' into minh/send-ibc-token
Browse files Browse the repository at this point in the history
  • Loading branch information
phamminh0811 authored Oct 18, 2023
2 parents 1530bee + 7521baa commit 2710d3c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
54 changes: 32 additions & 22 deletions x/interchainstaking/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,39 @@ func (k *Keeper) BeginBlocker(ctx sdk.Context) {
}

connection, found := k.IBCKeeper.ConnectionKeeper.GetConnection(ctx, zone.ConnectionId)
if found {
consState, found := k.IBCKeeper.ClientKeeper.GetLatestClientConsensusState(ctx, connection.GetClientID())
if found {
tmConsState, ok := consState.(*tmtypes.ConsensusState)
if ok {
if len(zone.IbcNextValidatorsHash) == 0 || !bytes.Equal(zone.IbcNextValidatorsHash, tmConsState.NextValidatorsHash.Bytes()) {
k.Logger(ctx).Info("IBC ValSet has changed; requerying valset")
// trigger valset update.
period := int64(k.GetParam(ctx, types.KeyValidatorSetInterval))
query := stakingTypes.QueryValidatorsRequest{}
err := k.EmitValSetQuery(ctx, zone.ConnectionId, zone.ChainId, query, sdkmath.NewInt(period))
if err != nil {
k.Logger(ctx).Error("unable to trigger valset update query", "error", err.Error())
// failing to emit the valset update is not terminal but constitutes
// an error, as if this starts happening frequent it is something
// we should investigate.
}
zone.IbcNextValidatorsHash = tmConsState.NextValidatorsHash.Bytes()
k.SetZone(ctx, zone)
}
}
}
if !found {
return false
}

consState, found := k.IBCKeeper.ClientKeeper.GetLatestClientConsensusState(ctx, connection.GetClientID())
if !found {
return false
}

tmConsState, ok := consState.(*tmtypes.ConsensusState)
if !ok {
return false
}

changedValSet := len(zone.IbcNextValidatorsHash) == 0 || !bytes.Equal(zone.IbcNextValidatorsHash, tmConsState.NextValidatorsHash.Bytes())
if !changedValSet {
return false
}

k.Logger(ctx).Info("IBC ValSet has changed; requerying valset")
// trigger valset update.
period := int64(k.GetParam(ctx, types.KeyValidatorSetInterval))
query := stakingTypes.QueryValidatorsRequest{}
err := k.EmitValSetQuery(ctx, zone.ConnectionId, zone.ChainId, query, sdkmath.NewInt(period))
if err != nil {
k.Logger(ctx).Error("unable to trigger valset update query", "error", err.Error())
// failing to emit the valset update is not terminal but constitutes
// an error, as if this starts happening frequent it is something
// we should investigate.
}

zone.IbcNextValidatorsHash = tmConsState.NextValidatorsHash.Bytes()
k.SetZone(ctx, zone)
return false
})
}
3 changes: 2 additions & 1 deletion x/interchainstaking/keeper/address_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ func (k Keeper) IterateUserMappedAccounts(ctx sdk.Context, localAddress []byte,
defer iterator.Close()

i := int64(0)
remoteAddrPrefixLen := len(types.GetRemoteAddressPrefix(localAddress))
for ; iterator.Valid(); iterator.Next() {
value := iterator.Value()
key := iterator.Key()
chainIDBytes := key[len(types.GetRemoteAddressPrefix(localAddress)):]
chainIDBytes := key[remoteAddrPrefixLen:]
stop := fn(i, string(chainIDBytes), value)
if stop {
break
Expand Down
2 changes: 0 additions & 2 deletions x/interchainstaking/keeper/ibc_packet_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,10 @@ func (k *Keeper) HandleWithdrawForUser(ctx sdk.Context, zone *types.Zone, msg *b

if len(dlist) > 0 {
newDist := make([]*types.Distribution, 0)
i := 0
for idx := range withdrawalRecord.Distribution {
if _, remove := dlist[idx]; !remove {
newDist = append(newDist, withdrawalRecord.Distribution[idx])
}
i++
}
k.Logger(ctx).Info("found matching withdrawal; awaiting additional messages")
withdrawalRecord.Distribution = newDist
Expand Down

0 comments on commit 2710d3c

Please sign in to comment.