-
Notifications
You must be signed in to change notification settings - Fork 588
/
abci.go
41 lines (36 loc) · 1.5 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
package client
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ibc-go/v2/modules/core/02-client/keeper"
"github.com/cosmos/ibc-go/v2/modules/core/exported"
ibctmtypes "github.com/cosmos/ibc-go/v2/modules/light-clients/07-tendermint/types"
)
// BeginBlocker updates an existing localhost client with the latest block height.
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
plan, found := k.GetUpgradePlan(ctx)
if found {
// Once we are at the last block this chain will commit, set the upgraded consensus state
// so that IBC clients can use the last NextValidatorsHash as a trusted kernel for verifying
// headers on the next version of the chain.
// Set the time to the last block time of the current chain.
// In order for a client to upgrade successfully, the first block of the new chain must be committed
// within the trusting period of the last block time on this chain.
_, exists := k.GetUpgradedClient(ctx, plan.Height)
if exists && ctx.BlockHeight() == plan.Height-1 {
upgradedConsState := &ibctmtypes.ConsensusState{
Timestamp: ctx.BlockTime(),
NextValidatorsHash: ctx.BlockHeader().NextValidatorsHash,
}
bz := k.MustMarshalConsensusState(upgradedConsState)
k.SetUpgradedConsensusState(ctx, plan.Height, bz)
}
}
_, found = k.GetClientState(ctx, exported.Localhost)
if !found {
return
}
// update the localhost client with the latest block height
if err := k.UpdateClient(ctx, exported.Localhost, nil); err != nil {
panic(err)
}
}