From ba9c4f82e0c706761e5b4be5a4fbc270357e09e1 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Fri, 7 Apr 2023 13:15:32 +0200 Subject: [PATCH] ICS 02: remove concept of client type (#956) --- .../ics-006-solo-machine-client/README.md | 13 +++++---- .../ics-007-tendermint-client/README.md | 27 +++++++------------ spec/client/ics-009-loopback-cilent/README.md | 10 +++---- spec/core/ics-002-client-semantics/README.md | 20 ++++++-------- spec/core/ics-024-host-requirements/README.md | 1 - spec/core/ics-026-routing-module/README.md | 4 +-- 6 files changed, 30 insertions(+), 45 deletions(-) diff --git a/spec/client/ics-006-solo-machine-client/README.md b/spec/client/ics-006-solo-machine-client/README.md index 6e1ba5d48..968dda901 100644 --- a/spec/client/ics-006-solo-machine-client/README.md +++ b/spec/client/ics-006-solo-machine-client/README.md @@ -131,12 +131,11 @@ interface Signature { The solo machine client `initialise` function starts an unfrozen client with the initial consensus state. ```typescript -function initialise(identifier: Identifier, consensusState: ConsensusState): ClientState { +function initialise(identifier: Identifier, clientState: ClientState, consensusState: ConsensusState) { + assert(clientState.consensusState === consensusState) + + provableStore.set("clients/{identifier}/clientState", clientState) provableStore.set("clients/{identifier}/consensusStates/{height}", consensusState) - return ClientState{ - frozen: false, - consensusState - } } ``` @@ -234,7 +233,7 @@ function updateState(clientMessage: ClientMessage) { clientState.consensusState.diversifier = header.newDiversifier clientState.consensusState.timestamp = header.timestamp clientState.consensusState.sequence++ - provableStore.set("clients/{identifier}/clientState", clientState) + provableStore.set("clients/{clientMsg.identifier}/clientState", clientState) } ``` @@ -245,7 +244,7 @@ function updateStateOnMisbehaviour(clientMessage: ClientMessage) { clientState = provableStore.get("clients/{clientMsg.identifier}/clientState") // freeze the client clientState.frozen = true - provableStore.set("clients/{identifier}/clientState", clientState) + provableStore.set("clients/{clientMsg.identifier}/clientState", clientState) } ``` diff --git a/spec/client/ics-007-tendermint-client/README.md b/spec/client/ics-007-tendermint-client/README.md index 9337488d8..a06c17c35 100644 --- a/spec/client/ics-007-tendermint-client/README.md +++ b/spec/client/ics-007-tendermint-client/README.md @@ -170,25 +170,16 @@ Tendermint client initialisation requires a (subjectively chosen) latest consens ```typescript function initialise( - identifier: Identifier, chainID: string, consensusState: ConsensusState, - trustLevel: Fraction, height: Height, trustingPeriod: uint64, unbondingPeriod: uint64, - upgradePath: []string, maxClockDrift: uint64, proofSpecs: []ProofSpec -): ClientState { - assert(trustingPeriod < unbondingPeriod) - assert(height > 0) - assert(trustLevel >= 1/3 && trustLevel <= 1) + identifier: Identifier, + clientState: ClientState, + consensusState: ConsensusState +) { + assert(clientState.trustingPeriod < clientState.unbondingPeriod) + assert(clientState.height > 0) + assert(clientState.trustLevel >= 1/3 && clientState.trustLevel <= 1) + + provableStore.set("clients/{identifier}/clientState", clientState) provableStore.set("clients/{identifier}/consensusStates/{height}", consensusState) - return ClientState{ - chainID, - trustLevel, - latestHeight: height, - trustingPeriod, - unbondingPeriod, - frozenHeight: null, - upgradePath, - maxClockDrift, - proofSpecs - } } ``` diff --git a/spec/client/ics-009-loopback-cilent/README.md b/spec/client/ics-009-loopback-cilent/README.md index 3b271f4ba..2832b2d3e 100644 --- a/spec/client/ics-009-loopback-cilent/README.md +++ b/spec/client/ics-009-loopback-cilent/README.md @@ -87,11 +87,11 @@ Implementations **may** choose to implement loopback such that the next message Loopback client initialisation requires the latest height of the local ledger. ```typescript -function initialise(height: Height): ClientState { - assert(height > 0) - return ClientState{ - latestHeight: height - } +function initialise(identifier: Identifier, clientState: ClientState, consensusState: ConsensusState) { + assert(clientState.latestHeight > 0) + assert(consensusState === nil) + + provableStore.set("clients/{identifier}/clientState", clientState) } ``` diff --git a/spec/core/ics-002-client-semantics/README.md b/spec/core/ics-002-client-semantics/README.md index 0fdc4e767..1a3c28e6e 100644 --- a/spec/core/ics-002-client-semantics/README.md +++ b/spec/core/ics-002-client-semantics/README.md @@ -221,10 +221,10 @@ but they must expose this common set of query functions to the IBC handler. type ClientState = bytes ``` -Client types MUST define a method to initialise a client state with the provided client identifier and consensus state, writing to internal state as appropriate. +Client types MUST define a method to initialise a client state with the provided client identifier, client state and consensus state, writing to internal state as appropriate. ```typescript -type initialise = (identifier: Identifier, consensusState: ConsensusState) => ClientState +type initialise = (identifier: Identifier, clientState: ClientState, consensusState: ConsensusState) => Void ``` Client types MUST define a method to fetch the current height (height of the most recent validated state update). @@ -549,18 +549,14 @@ logical correctness. #### Create -Calling `createClient` with the client type and initial consensus state creates a new client. +Calling `createClient` with the client state and initial consensus state creates a new client. ```typescript -function createClient( - clientType: ClientType, - consensusState: ConsensusState) { - // implementations may define a identifier generation function - identifier = generateClientIdentifier() - abortTransactionUnless(provableStore.get(clientStatePath(identifier)) === null) - abortSystemUnless(provableStore.get(clientTypePath(identifier)) === null) - clientType.initialise(identifier, consensusState) - provableStore.set(clientTypePath(identifier), clientType) +function createClient(clientState: clientState, consensusState: ConsensusState) { + // implementations may define a identifier generation function + identifier = generateClientIdentifier() + abortTransactionUnless(provableStore.get(clientStatePath(identifier)) === null) + initialise(identifier, clientState, consensusState) } ``` diff --git a/spec/core/ics-024-host-requirements/README.md b/spec/core/ics-024-host-requirements/README.md index 1ea34f774..70bf67e77 100644 --- a/spec/core/ics-024-host-requirements/README.md +++ b/spec/core/ics-024-host-requirements/README.md @@ -118,7 +118,6 @@ Note that the client-related paths listed below reflect the Tendermint client as | Store | Path format | Value type | Defined in | | -------------- | ------------------------------------------------------------------------------ | ----------------- | ---------------------- | -| provableStore | "clients/{identifier}/clientType" | ClientType | [ICS 2](../ics-002-client-semantics) | | provableStore | "clients/{identifier}/clientState" | ClientState | [ICS 2](../ics-002-client-semantics) | | provableStore | "clients/{identifier}/consensusStates/{height}" | ConsensusState | [ICS 7](../../client/ics-007-tendermint-client) | | privateStore | "clients/{identifier}/connections | []Identifier | [ICS 3](../ics-003-connection-semantics) | diff --git a/spec/core/ics-026-routing-module/README.md b/spec/core/ics-026-routing-module/README.md index 70b107f6e..e39d86606 100644 --- a/spec/core/ics-026-routing-module/README.md +++ b/spec/core/ics-026-routing-module/README.md @@ -263,14 +263,14 @@ No message signatures or data validity checks are assumed beyond those which are ```typescript interface ClientCreate { identifier: Identifier - type: ClientType + clientState: ClientState consensusState: ConsensusState } ``` ```typescript function handleClientCreate(datagram: ClientCreate) { - handler.createClient(datagram.type, datagram.consensusState) + handler.createClient(datagram.clientState, datagram.consensusState) } ```