-
Notifications
You must be signed in to change notification settings - Fork 11
/
abci.go
44 lines (37 loc) · 1.52 KB
/
abci.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types"
"github.com/persistenceOne/pstake-native/v2/x/ratesync/types"
)
func (k *Keeper) BeginBlock(ctx sdk.Context) {
// perform BeginBlocker tasks for each chain
for _, hc := range k.GetAllHostChain(ctx) {
if !hc.IsActive() {
// don't do anything on inactive chains
continue
}
// attempt to recreate closed ICA channels
k.DoRecreateICA(ctx, hc)
// reset hc before going into next function, as it might have changed in earlier function
// as we do not want to re-write and omit the last write.
}
}
func (k *Keeper) DoRecreateICA(ctx sdk.Context, hc types.HostChain) {
// return early if any of the accounts is currently being recreated
if hc.ICAAccount.ChannelState == liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATING {
return
}
// if the channel is closed, and it is not being recreated, recreate it
portID := types.MustICAPortIDFromOwner(hc.ICAAccount.Owner)
_, isActive := k.icaControllerKeeper.GetOpenActiveChannel(ctx, hc.ConnectionID, portID)
if !isActive {
if err := k.icaControllerKeeper.RegisterInterchainAccount(ctx, hc.ConnectionID, hc.ICAAccount.Owner, ""); err != nil {
k.Logger(ctx).Error("error recreating %s ratesync ica: %w", hc.ChainID, err)
} else {
k.Logger(ctx).Info("Recreating ratesync ICA.", "chain", hc.ChainID)
hc.ICAAccount.ChannelState = liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATING
k.SetHostChain(ctx, hc)
}
}
}