Skip to content

Commit

Permalink
Merge branch 'main' into dong/TestRemoveZoneAndAssociatedRecords
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Oct 27, 2023
2 parents 193bd9a + 8d361ad commit 1db39f4
Show file tree
Hide file tree
Showing 15 changed files with 1,244 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CODEOWNERS: https://help.github.com/articles/about-codeowners/

# Primary repo maintainers
* @joe-bowman @ajansari95 @muku314115 @ThanhNhann @faddat @sontrinh16 @anhductn2001
* @joe-bowman @ThanhNhann @faddat @sontrinh16 @anhductn2001
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
4 changes: 2 additions & 2 deletions x/interchainstaking/keeper/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func DepositIntervalCallback(k *Keeper, ctx sdk.Context, args []byte, query icqt
for _, txn := range txs.TxResponses {
req := tx.GetTxRequest{Hash: txn.TxHash}
hashBytes := k.cdc.MustMarshal(&req)
_, found = k.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, txn.TxHash))
_, found = k.GetReceipt(ctx, zone.ChainId, txn.TxHash)
if found {
k.Logger(ctx).Debug("Found previously handled tx. Ignoring.", "txhash", txn.TxHash)
continue
Expand Down Expand Up @@ -443,7 +443,7 @@ func DepositTxCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes.Q
return fmt.Errorf("invalid tx for query - expected %s, got %s", queryRequest.Hash, hashStr)
}

_, found = k.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, hashStr))
_, found = k.GetReceipt(ctx, zone.ChainId, hashStr)
if found {
k.Logger(ctx).Info("Found previously handled tx. Ignoring.", "txhash", hashStr)
return nil
Expand Down
Loading

0 comments on commit 1db39f4

Please sign in to comment.