Skip to content

Commit

Permalink
Allow host introspection of its own ConsensusState
Browse files Browse the repository at this point in the history
  • Loading branch information
h5law committed Jul 18, 2023
1 parent 667c062 commit aa8a8ff
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
24 changes: 24 additions & 0 deletions ibc/client/queries.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package client

import (
light_client_types "github.com/pokt-network/pocket/ibc/client/light_clients/types"
"github.com/pokt-network/pocket/ibc/client/types"
"github.com/pokt-network/pocket/ibc/path"
"github.com/pokt-network/pocket/shared/codec"
core_types "github.com/pokt-network/pocket/shared/core/types"
"github.com/pokt-network/pocket/shared/modules"
)
Expand Down Expand Up @@ -32,3 +34,25 @@ func (c *clientManager) GetClientState(identifier string) (modules.ClientState,

return types.GetClientState(clientStore, identifier)
}

// GetHostConsensusState returns the ConsensusState at the given height for the
// host chain, the Pocket network. It then serialises this and packs it into a
// ConsensusState object for use in a WASM client
func (c *clientManager) GetHostConsensusState(height modules.Height) (modules.ConsensusState, error) {
blockStore := c.GetBus().GetPersistenceModule().GetBlockStore()
block, err := blockStore.GetBlock(height.GetRevisionHeight())
if err != nil {
return nil, err
}
pocketConsState := &light_client_types.PocketConsensusState{
Timestamp: block.BlockHeader.Timestamp,
StateHash: block.BlockHeader.StateHash,
StateTreeHashes: block.BlockHeader.StateTreeHashes,
NextValSetHash: block.BlockHeader.NextValSetHash,
}
consBz, err := codec.GetCodec().Marshal(pocketConsState)
if err != nil {
return nil, err
}
return types.NewConsensusState(consBz, uint64(pocketConsState.Timestamp.AsTime().UnixNano())), nil
}
21 changes: 13 additions & 8 deletions shared/modules/ibc_client_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type ClientManagerOption func(ClientManager)

type clientManagerFactory = FactoryWithOptions[ClientManager, ClientManagerOption]

// ClientManager is the interface that defines the methods needed to interact with an IBC light client
// it manages the different lifecycle methods for the different clients
// ClientManager is the interface that defines the methods needed to interact with an
// IBC light client it manages the different lifecycle methods for the different clients
// https://github.com/cosmos/ibc/tree/main/spec/core/ics-002-client-semantics
type ClientManager interface {
Submodule
Expand All @@ -40,12 +40,6 @@ type ClientManager interface {
// the ClientMessage can be verified using the existing ClientState and ConsensusState
UpdateClient(identifier string, clientMessage ClientMessage) error

// GetConsensusState returns the ConsensusState at the given height for the given client
GetConsensusState(identifier string, height Height) (ConsensusState, error)

// GetClientState returns the ClientState for the given client
GetClientState(identifier string) (ClientState, error)

// UpgradeClient upgrades an existing client with the given identifier using the
// ClientState and ConsentusState provided. It can only do so if the new client
// was committed to by the old client at the specified upgrade height
Expand All @@ -54,6 +48,17 @@ type ClientManager interface {
clientState ClientState, consensusState ConsensusState,
proofUpgradeClient, proofUpgradeConsState []byte,
) error

// === Client Queries ===

// GetConsensusState returns the ConsensusState at the given height for the given client
GetConsensusState(identifier string, height Height) (ConsensusState, error)

// GetClientState returns the ClientState for the given client
GetClientState(identifier string) (ClientState, error)

// GetHostConsensusState returns the ConsensusState at the given height for the host chain
GetHostConsensusState(height Height) (ConsensusState, error)
}

// ClientState is an interface that defines the methods required by a clients
Expand Down

0 comments on commit aa8a8ff

Please sign in to comment.