Skip to content

Commit

Permalink
ICS 02: remove concept of client type (#956)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Rodriguez authored Apr 7, 2023
1 parent 62fe483 commit ba9c4f8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 45 deletions.
13 changes: 6 additions & 7 deletions spec/client/ics-006-solo-machine-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
```

Expand Down Expand Up @@ -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)
}
```

Expand All @@ -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)
}
```

Expand Down
27 changes: 9 additions & 18 deletions spec/client/ics-007-tendermint-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
```

Expand Down
10 changes: 5 additions & 5 deletions spec/client/ics-009-loopback-cilent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
```

Expand Down
20 changes: 8 additions & 12 deletions spec/core/ics-002-client-semantics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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)
}
```

Expand Down
1 change: 0 additions & 1 deletion spec/core/ics-024-host-requirements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
4 changes: 2 additions & 2 deletions spec/core/ics-026-routing-module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
```

Expand Down

0 comments on commit ba9c4f8

Please sign in to comment.