Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][IBC] Implement ICS-02 Client Semantics #916

Draft
wants to merge 23 commits into
base: ibc/proto-exploration-ics23
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement CreateClient method
  • Loading branch information
h5law committed Jul 24, 2023
commit ec954e765f41d3dfdb9669418955c92763df89b4
45 changes: 44 additions & 1 deletion ibc/client/submodule.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package client

import (
"fmt"

"github.com/pokt-network/pocket/ibc/path"
"github.com/pokt-network/pocket/shared/modules"
"github.com/pokt-network/pocket/shared/modules/base_modules"
)

var _ modules.ClientManager = &clientManager{}
var (
_ modules.ClientManager = &clientManager{}
allowedClientTypes = make(map[string]struct{}, 0)
)

func init() {
allowedClientTypes["08-wasm"] = struct{}{}
}

type clientManager struct {
base_modules.IntegrableModule
@@ -49,7 +58,34 @@ func (c *clientManager) GetModuleName() string { return modules.ClientManagerMod
func (c *clientManager) CreateClient(
clientState modules.ClientState, consensusState modules.ConsensusState,
) (string, error) {
// Check if the client type is allowed
if !isAllowedClientType(clientState.ClientType()) {
return "", fmt.Errorf("client type %s is not supported", clientState.ClientType())
}

// Generate a unique identifier for the client
identifier := path.GenerateClientIdentifier()

// Retrieve the client store
clientStore, err := c.GetBus().GetIBCHost().GetProvableStore(path.KeyClientStorePrefix)
if err != nil {
return "", err
}

// Initialise the client with the clientState provided
if err := clientState.Initialise(clientStore, consensusState); err != nil {
c.logger.Error().Err(err).Str("identifier", identifier).Msg("failed to initialize client")
return "", err
}

c.logger.Info().Str("identifier", identifier).Str("height", clientState.GetLatestHeight().String()).Msg("client created at height")

// Emit the create client event to the event logger
if err := c.emitCreateClientEvent(identifier, clientState); err != nil {
c.logger.Error().Err(err).Str("identifier", identifier).Msg("failed to emit client created event")
return "", err
}

return identifier, nil
}

@@ -81,3 +117,10 @@ func (c *clientManager) SubmitMisbehaviour(
) error {
return nil
}

func isAllowedClientType(clientType string) bool {
if _, ok := allowedClientTypes[clientType]; ok {
return true
}
return false
}