github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/core/02-client/abci.go (about) 1 package client 2 3 import ( 4 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 5 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/02-client/keeper" 6 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/exported" 7 ibctmtypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/light-clients/07-tendermint/types" 8 ) 9 10 // BeginBlocker updates an existing localhost client with the latest block height. 11 func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { 12 plan, found := k.GetUpgradePlan(ctx) 13 if found { 14 // Once we are at the last block this chain will commit, set the upgraded consensus state 15 // so that IBC clients can use the last NextValidatorsHash as a trusted kernel for verifying 16 // headers on the next version of the chain. 17 // Set the time to the last block time of the current chain. 18 // In order for a client to upgrade successfully, the first block of the new chain must be committed 19 // within the trusting period of the last block time on this chain. 20 _, exists := k.GetUpgradedClient(ctx, plan.Height) 21 if exists && ctx.BlockHeight() == plan.Height-1 { 22 upgradedConsState := &ibctmtypes.ConsensusState{ 23 Timestamp: ctx.BlockTime(), 24 NextValidatorsHash: ctx.BlockHeader().NextValidatorsHash, 25 } 26 bz := k.MustMarshalConsensusState(upgradedConsState) 27 k.SetUpgradedConsensusState(ctx, plan.Height, bz) 28 } 29 } 30 31 _, found = k.GetClientState(ctx, exported.Localhost) 32 if !found { 33 return 34 } 35 36 // update the localhost client with the latest block height 37 if err := k.UpdateClient(ctx, exported.Localhost, nil); err != nil { 38 panic(err) 39 } 40 }