Skip to content

Commit

Permalink
feat: IIBC 36 Implement client library (#36)
Browse files Browse the repository at this point in the history
* Add Java classes to parse JSON versions of IBC proto messages

* Add Java classes to represent messages from [ICS-26](https://github.com/cosmos/ibc/tree/main/spec/core/ics-026-routing-module#datagram-handlers-write)
Translated from interperation done in https://github.com/hyperledger-labs/yui-ibc-solidity/blob/main/contracts/core/25-handler/IBCMsgs.sol

* Add Java classes to parse JSON versions of IBC proto messages

Add RLP encoding to proto messages used in storage

* downrgrade javaeeUnittestVersion from 0.10.0 to 0.9.7

* feat: implement create keys for signing transaction  (#27)

fezt : Create keys

Co-authored-by: hemz10 <sph2740@example.com>

* feat: implement callrequest storage (#24)

* chore: add boilerplate for cosmwasm-contracts

* update cargo

* test: add unit-test setup

* test: setup mock env

* update test

* update test setup, cargo

* add call service message

* chore: inital ibc impl for xcall

* chore:  refactor message and address

* chore: implement state for xcall

* chore: update call service  message

* chore: add call message request storage

* chore: add call message response storage

* chore: add rust rlp library

* chore: update cargo

* remove admin and owner

* add storage key enum

* update types

* remove admin and owner management

* chore : restructure contract state and update methods

* update admin and owner store

* add storage key for cosmwasm persistant storage

* add rollback message

* Initial commit

* removed encodable and decodable

* format code

* format code

* chore: remove rollback

---------

Co-authored-by: shreyasbhat0 <shreyas.ks@hugobyte.com>
Co-authored-by: Shreyas S Bhat <35568964+shreyasbhat0@users.noreply.github.com>

* Feature/add gradle properties for version in java contracts (#28)

* chore: upgrade gradle version to 8.0

Signed-off-by: Night Owl <nightowl121@protonmail.com>

* chore: add common version of java libraries for smart contracts

Signed-off-by: Night Owl <nightowl121@protonmail.com>

---------

Signed-off-by: Night Owl <nightowl121@protonmail.com>

* Add ci to run while updating java contracts (#29)

* chore: add ci to run while updating java contracts

checks will run unit tests and optimize jar tasks

Signed-off-by: Night Owl <nightowl121@protonmail.com>

* fix: fix command location for testing java contracts

Signed-off-by: Night Owl <nightowl121@protonmail.com>

---------

Signed-off-by: Night Owl <nightowl121@protonmail.com>

* docs: ADR for relay (#21)

* feat: implement call message response storage (#18)

* chore: add boilerplate for cosmwasm-contracts

* update cargo

* test: add unit-test setup

* test: setup mock env

* update test

* update test setup, cargo

* add call service message

* chore: inital ibc impl for xcall

* chore:  refactor message and address

* chore: implement state for xcall

* chore: update call service  message

* chore: add call message request storage

* chore: add call message response storage

* chore: add rust rlp library

* chore: update cargo

* remove admin and owner

* add storage key enum

* update types

* remove admin and owner management

* chore : restructure contract state and update methods

* update admin and owner store

* add storage key for cosmwasm persistant storage

* update rlp cargo

* implement request methods

* init rlp encode and decode for messages

* chore: cargo clippy

* chore: update owner and admin

* chore: add unit test

* chore: add unit test for request

---------

Co-authored-by: Muhammed Irfan <50794925+MuhammedIrfan@users.noreply.github.com>

* downrgrade javaeeUnittestVersion from 0.10.0 to 0.9.7

* fix: fix folder name to run github actions

Signed-off-by: Night Owl <nightowl121@protonmail.com>

* Import correct Version class in message classes

* modify gradle files and CI workflow to allow for CI builds

* Implement Client interferface/library for ICON handler
 * add to and from bytes to channel and connection end classes
 * add light client interface
 * add simple store class to use for now
 * add compare methods to height class

* Implement IBC handler message definitions as java classes (#32)

* Add Java classes to parse JSON versions of IBC proto messages

* Add Java classes to represent messages from [ICS-26](https://github.com/cosmos/ibc/tree/main/spec/core/ics-026-routing-module#datagram-handlers-write)
Translated from interperation done in https://github.com/hyperledger-labs/yui-ibc-solidity/blob/main/contracts/core/25-handler/IBCMsgs.sol

* feat: implement create keys for signing transaction  (#27)

fezt : Create keys

Co-authored-by: hemz10 <sph2740@example.com>

* feat: implement callrequest storage (#24)

* chore: add boilerplate for cosmwasm-contracts

* update cargo

* test: add unit-test setup

* test: setup mock env

* update test

* update test setup, cargo

* add call service message

* chore: inital ibc impl for xcall

* chore:  refactor message and address

* chore: implement state for xcall

* chore: update call service  message

* chore: add call message request storage

* chore: add call message response storage

* chore: add rust rlp library

* chore: update cargo

* remove admin and owner

* add storage key enum

* update types

* remove admin and owner management

* chore : restructure contract state and update methods

* update admin and owner store

* add storage key for cosmwasm persistant storage

* add rollback message

* Initial commit

* removed encodable and decodable

* format code

* format code

* chore: remove rollback

---------

Co-authored-by: shreyasbhat0 <shreyas.ks@hugobyte.com>
Co-authored-by: Shreyas S Bhat <35568964+shreyasbhat0@users.noreply.github.com>

* Feature/add gradle properties for version in java contracts (#28)

* chore: upgrade gradle version to 8.0

Signed-off-by: Night Owl <nightowl121@protonmail.com>

* chore: add common version of java libraries for smart contracts

Signed-off-by: Night Owl <nightowl121@protonmail.com>

---------

Signed-off-by: Night Owl <nightowl121@protonmail.com>

* Add ci to run while updating java contracts (#29)

* chore: add ci to run while updating java contracts

checks will run unit tests and optimize jar tasks

Signed-off-by: Night Owl <nightowl121@protonmail.com>

* fix: fix command location for testing java contracts

Signed-off-by: Night Owl <nightowl121@protonmail.com>

---------

Signed-off-by: Night Owl <nightowl121@protonmail.com>

* docs: ADR for relay (#21)

* feat: implement call message response storage (#18)

* chore: add boilerplate for cosmwasm-contracts

* update cargo

* test: add unit-test setup

* test: setup mock env

* update test

* update test setup, cargo

* add call service message

* chore: inital ibc impl for xcall

* chore:  refactor message and address

* chore: implement state for xcall

* chore: update call service  message

* chore: add call message request storage

* chore: add call message response storage

* chore: add rust rlp library

* chore: update cargo

* remove admin and owner

* add storage key enum

* update types

* remove admin and owner management

* chore : restructure contract state and update methods

* update admin and owner store

* add storage key for cosmwasm persistant storage

* update rlp cargo

* implement request methods

* init rlp encode and decode for messages

* chore: cargo clippy

* chore: update owner and admin

* chore: add unit test

* chore: add unit test for request

---------

Co-authored-by: Muhammed Irfan <50794925+MuhammedIrfan@users.noreply.github.com>

* downrgrade javaeeUnittestVersion from 0.10.0 to 0.9.7

* fix: fix folder name to run github actions

Signed-off-by: Night Owl <nightowl121@protonmail.com>

* Import correct Version class in message classes

* modify gradle files and CI workflow to allow for CI builds

---------

Signed-off-by: Night Owl <nightowl121@protonmail.com>
Co-authored-by: Hemanth Kumar <96766939+hemz10@users.noreply.github.com>
Co-authored-by: hemz10 <sph2740@example.com>
Co-authored-by: Prathiksha-Nataraja <90592522+Prathiksha-Nataraja@users.noreply.github.com>
Co-authored-by: shreyasbhat0 <shreyas.ks@hugobyte.com>
Co-authored-by: Shreyas S Bhat <35568964+shreyasbhat0@users.noreply.github.com>
Co-authored-by: Night Owl <91905208+nightowl121@users.noreply.github.com>
Co-authored-by: viveksharmapoudel <viveksharmapoudel@gmail.com>
Co-authored-by: Muhammed Irfan <50794925+MuhammedIrfan@users.noreply.github.com>
Co-authored-by: Night Owl <nightowl121@protonmail.com>

* Add inital unittest, ignoring commitments

* IIBC 37 Implement connection library (#38)

* Add inital implementation of the Connection library for IBC Handler

* add connection unit tests, ignoring commitments and storage assertions

* IIBC 38 implement channel library (#39)

* Add inital implementation of the Connection library for IBC Handler

* Add inital implementation of the Channel library for IBC Handler

* Add inital unittest, ignoring commitments

* feat: implementing rollback message (#14)

* chore: add boilerplate for cosmwasm-contracts

* update cargo

* test: add unit-test setup

* test: setup mock env

* update test

* update test setup, cargo

* add call service message

* chore: inital ibc impl for xcall

* chore:  refactor message and address

* Initial commit

* chore: implement state for xcall

* Initial commit

* chore: update call service  message

* chore: add call message request storage

* chore: add call message response storage

* added methods

* implimenting rollback

* Added unit test case and code refactor

* code format

* updated testcase

* format new line

* chore: fix test rollback

* refactor function names

---------

Co-authored-by: shreyasbhat0 <shreyas.ks@hugobyte.com>
Co-authored-by: Shreyas S Bhat <35568964+shreyasbhat0@users.noreply.github.com>
Co-authored-by: Muhammed Irfan <50794925+MuhammedIrfan@users.noreply.github.com>

* add connection unit tests, ignoring commitments and storage assertions

* Add channel handler and  send/recv package unit tests. Ignored commitments

* Apply commitments for IBC host branch

* add packet RLP encoding

* style: Apply style formatting by IDE

Signed-off-by: Night Owl <nightowl121@protonmail.com>

* refactor: remove source set definition for build files

Signed-off-by: Night Owl <nightowl121@protonmail.com>

* refactor: reduce DB reads

Signed-off-by: Night Owl <nightowl121@protonmail.com>

---------

Signed-off-by: Night Owl <nightowl121@protonmail.com>
Co-authored-by: Prathiksha-Nataraja <90592522+Prathiksha-Nataraja@users.noreply.github.com>
Co-authored-by: shreyasbhat0 <shreyas.ks@hugobyte.com>
Co-authored-by: Shreyas S Bhat <35568964+shreyasbhat0@users.noreply.github.com>
Co-authored-by: Muhammed Irfan <50794925+MuhammedIrfan@users.noreply.github.com>
Co-authored-by: Night Owl <nightowl121@protonmail.com>

* style: add IDE formatting

Signed-off-by: Night Owl <nightowl121@protonmail.com>

---------

Signed-off-by: Night Owl <nightowl121@protonmail.com>
Co-authored-by: Hemanth Kumar <96766939+hemz10@users.noreply.github.com>
Co-authored-by: hemz10 <sph2740@example.com>
Co-authored-by: Prathiksha-Nataraja <90592522+Prathiksha-Nataraja@users.noreply.github.com>
Co-authored-by: shreyasbhat0 <shreyas.ks@hugobyte.com>
Co-authored-by: Shreyas S Bhat <35568964+shreyasbhat0@users.noreply.github.com>
Co-authored-by: Night Owl <91905208+nightowl121@users.noreply.github.com>
Co-authored-by: viveksharmapoudel <viveksharmapoudel@gmail.com>
Co-authored-by: Muhammed Irfan <50794925+MuhammedIrfan@users.noreply.github.com>
Co-authored-by: Night Owl <nightowl121@protonmail.com>
  • Loading branch information
10 people authored Mar 9, 2023
1 parent 55a1192 commit 8cf16fa
Show file tree
Hide file tree
Showing 32 changed files with 3,073 additions and 59 deletions.
1 change: 1 addition & 0 deletions contracts/javascore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ subprojects {
}
apply plugin: 'java'
apply plugin: 'foundation.icon.javaee'
apply plugin: 'jacoco'

java {
sourceCompatibility = JavaVersion.VERSION_11
Expand Down
3 changes: 2 additions & 1 deletion contracts/javascore/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ iconsdkVersion=2.3.0
jupiterApiVersion=5.9.2
jupiterParamsVersion=5.9.2
jupiterEngineVersion=5.9.2
javaeePluginVersion=0.8.2
javaeePluginVersion=0.8.2
mockitoCoreVersion=4.5.1
17 changes: 16 additions & 1 deletion contracts/javascore/ibc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,30 @@ dependencies {
implementation project(':lib')
implementation project(':score-util')

testImplementation("org.mockito:mockito-core:$mockitoCoreVersion")
testImplementation("foundation.icon:javaee-unittest:$javaeeUnittestVersion")
testAnnotationProcessor("foundation.icon:javaee-score-client:$scoreClientVersion")
testImplementation project(':test-lib')
testImplementation("foundation.icon:javaee-score-client:$scoreClientVersion")
testImplementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
testImplementation("foundation.icon:icon-sdk:$iconsdkVersion")
testImplementation("org.junit.jupiter:junit-jupiter-api:$jupiterApiVersion")
testImplementation("org.junit.jupiter:junit-jupiter-params:$jupiterParamsVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterEngineVersion")
}

test{
test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

jacocoTestReport {
dependsOn test
reports {
xml.required = false
csv.required = false
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
}

optimizedJar {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package ibc.ics02.client;

import ibc.icon.interfaces.IIBCClient;
import ibc.icon.interfaces.ILightClient;
import ibc.icon.score.util.Logger;
import ibc.icon.score.util.NullChecker;
import ibc.icon.structs.messages.MsgCreateClient;
import ibc.icon.structs.messages.MsgUpdateClient;
import ibc.ics24.host.IBCStore;
import ibc.icon.structs.messages.*;
import ibc.ics24.host.IBCCommitment;
import ibc.ics24.host.IBCHost;
import score.Address;
import score.Context;
import score.annotation.External;

import java.math.BigInteger;

public class IBCClient extends IBCStore {
public class IBCClient extends IBCHost implements IIBCClient {

Logger logger = new Logger("ibc-core");

Expand All @@ -22,35 +25,48 @@ public class IBCClient extends IBCStore {
*/
@External
public void registerClient(String clientType, Address lightClient) {
NullChecker.requireNotNull(clientRegistry.get(clientType), "Already registered");
Context.require(clientRegistry.get(clientType) == null, "Already registered.");
clientRegistry.set(clientType, lightClient);
}

@External
public void createClient(MsgCreateClient msg) {
public String createClient(MsgCreateClient msg) {
String clientType = msg.clientType;
NullChecker.requireNotNull(clientType, "Client Type cannot be null");

Address lightClientAddr = clientRegistry.get(clientType);
NullChecker.requireNotNull(clientType, "Register client before creation.");
NullChecker.requireNotNull(lightClientAddr, "Register client before creation.");

String clientId = generateClientIdentifier(clientType);
logger.println("Create Client: ", " clientId: ", clientId);

clientTypes.set(clientId, msg.clientType);
clientImplementations.set(clientId, lightClientAddr);
ILightClient client = getClient(clientId);
CreateClientResponse response = client.createClient(clientId, msg.clientState, msg.consensusState);
Context.require(response.ok);

//
// update commitments
commitments.set(IBCCommitment.clientStateCommitmentKey(clientId), response.clientStateCommitment);
byte[] consensusKey = IBCCommitment.consensusStateCommitmentKey(clientId,
response.update.height.getRevisionNumber(), response.update.height.getRevisionHeight());
commitments.set(consensusKey, response.update.consensusStateCommitment);

return clientId;
}

@External
public void updateClient(MsgUpdateClient msg) {
String clientId = msg.clientId;
NullChecker.requireNotNull(clientId, "ClientId cannot be null");
ILightClient client = getClient(clientId);

Address lightClientAddr = clientImplementations.get(clientId);
NullChecker.requireNotNull(lightClientAddr, "Invalid client id");
Context.require(commitments.get(IBCCommitment.clientStateCommitmentKey(clientId)) != null);
UpdateClientResponse response = client.updateClient(clientId, msg.clientMessage);
Context.require(response.ok);

//
// update commitments
commitments.set(IBCCommitment.clientStateCommitmentKey(clientId), response.clientStateCommitment);
for (ConsensusStateUpdate update : response.updates) {
byte[] consensusKey = IBCCommitment.consensusStateCommitmentKey(clientId, update.height.getRevisionNumber(),
update.height.getRevisionHeight());
commitments.set(consensusKey, update.consensusStateCommitment);
}
}

private String generateClientIdentifier(String clientType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,262 @@
package ibc.ics03.connection;

public class IBCConnection {
import ibc.icon.interfaces.IIBCConnection;
import ibc.icon.interfaces.ILightClient;
import ibc.icon.score.util.Logger;
import ibc.icon.structs.messages.MsgConnectionOpenAck;
import ibc.icon.structs.messages.MsgConnectionOpenConfirm;
import ibc.icon.structs.messages.MsgConnectionOpenInit;
import ibc.icon.structs.messages.MsgConnectionOpenTry;
import ibc.icon.structs.proto.core.client.Height;
import ibc.icon.structs.proto.core.commitment.MerklePrefix;
import ibc.icon.structs.proto.core.connection.ConnectionEnd;
import ibc.icon.structs.proto.core.connection.Counterparty;
import ibc.icon.structs.proto.core.connection.Version;
import ibc.ics02.client.IBCClient;
import ibc.ics24.host.IBCCommitment;
import score.Context;

import java.math.BigInteger;

public class IBCConnection extends IBCClient implements IIBCConnection {
public static final String v1Identifier = "1";
public static final String[] supportedV1Features = new String[]{"ORDER_ORDERED", "ORDER_UNORDERED"};
public static final String commitmentPrefix = "ibc";

Logger logger = new Logger("ibc-core");

public String connectionOpenInit(MsgConnectionOpenInit msg) {
String connectionId = generateConnectionIdentifier();
Context.require(connections.get(connectionId) == null, "connectionId already exists");
ILightClient client = getClient(msg.clientId);
Context.require(client.getClientState(msg.clientId) != null, "Client state not found");

ConnectionEnd connection = new ConnectionEnd();
connection.setClientId(msg.clientId);
connection.setVersions(getSupportedVersions());
connection.setState(ConnectionEnd.State.STATE_INIT);
connection.setDelayPeriod(msg.delayPeriod);
connection.setCounterparty(msg.counterparty);

updateConnectionCommitment(connectionId, connection);
connections.set(connectionId, connection);

return connectionId;
}

public String connectionOpenTry(MsgConnectionOpenTry msg) {
// TODO: investigate need to self client validation
Context.require(msg.counterpartyVersions.length > 0, "counterpartyVersions length must be greater than 0");

String connectionId = generateConnectionIdentifier();
Context.require(connections.get(connectionId) == null, "connectionId already exists");

ConnectionEnd connection = new ConnectionEnd();
connection.setClientId(msg.clientId);
connection.setVersions(getSupportedVersions());
connection.setState(ConnectionEnd.State.STATE_TRYOPEN);
connection.setDelayPeriod(msg.delayPeriod);
connection.setCounterparty(msg.counterparty);

MerklePrefix prefix = new MerklePrefix();
prefix.setKeyPrefix(commitmentPrefix);

Counterparty expectedCounterparty = new Counterparty();
expectedCounterparty.setClientId(msg.clientId);
expectedCounterparty.setConnectionId("");
expectedCounterparty.setPrefix(prefix);

ConnectionEnd expectedConnection = new ConnectionEnd();
expectedConnection.setClientId(msg.counterparty.getClientId());
expectedConnection.setVersions(msg.counterpartyVersions);
expectedConnection.setState(ConnectionEnd.State.STATE_INIT);
expectedConnection.setDelayPeriod(msg.delayPeriod);
expectedConnection.setCounterparty(expectedCounterparty);

verifyConnectionState(connection, msg.proofHeight, msg.proofInit, msg.counterparty.getConnectionId(),
expectedConnection);

verifyClientState(
connection,
msg.proofHeight,
IBCCommitment.clientStatePath(connection.counterparty.getClientId()),
msg.proofClient,
msg.clientStateBytes);
// TODO we should also verify a consensus state

updateConnectionCommitment(connectionId, connection);
connections.set(connectionId, connection);

return connectionId;
}

public void connectionOpenAck(MsgConnectionOpenAck msg) {
ConnectionEnd connection = connections.get(msg.connectionId);
Context.require(connection != null, "connection does not exist");
ConnectionEnd.State state = connection.getState();
// TODO should we allow the state to be TRY_OPEN?
Context.require(state.equals(ConnectionEnd.State.STATE_INIT) || state.equals(ConnectionEnd.State.STATE_TRYOPEN),
"connection state is not INIT or TRYOPEN");
if (state.equals(ConnectionEnd.State.STATE_INIT)) {
Context.require(isSupportedVersion(msg.version),
"connection state is in INIT but the provided version is not supported");
} else {
Context.require(connection.versions.length == 1 && connection.versions[0].equals(msg.version),
"connection state is in TRYOPEN but the provided version is not set in the previous connection " +
"versions");
}

// TODO: investigate need to self client validation
// require(validateSelfClient(msg.clientStateBytes), "failed to validate self
// client state");

MerklePrefix prefix = new MerklePrefix();
prefix.setKeyPrefix(commitmentPrefix);

Counterparty expectedCounterparty = new Counterparty();
expectedCounterparty.setClientId(connection.getClientId());
expectedCounterparty.setConnectionId(msg.connectionId);
expectedCounterparty.setPrefix(prefix);

ConnectionEnd expectedConnection = new ConnectionEnd();
expectedConnection.setClientId(connection.getClientId());
expectedConnection.setVersions(new Version[]{msg.version});
expectedConnection.setState(ConnectionEnd.State.STATE_TRYOPEN);
expectedConnection.setDelayPeriod(connection.delayPeriod);
expectedConnection.setCounterparty(expectedCounterparty);

verifyConnectionState(connection, msg.proofHeight, msg.proofTry, msg.counterpartyConnectionID,
expectedConnection);

verifyClientState(
connection,
msg.proofHeight,
IBCCommitment.clientStatePath(connection.counterparty.getClientId()),
msg.proofClient,
msg.clientStateBytes);

// TODO: we should also verify a consensus state

connection.setState(ConnectionEnd.State.STATE_OPEN);
connection.setVersions(expectedConnection.versions);
connection.counterparty.setConnectionId(msg.counterpartyConnectionID);

updateConnectionCommitment(msg.connectionId, connection);
connections.set(msg.connectionId, connection);

}

public void connectionOpenConfirm(MsgConnectionOpenConfirm msg) {
ConnectionEnd connection = connections.get(msg.connectionId);
Context.require(connection != null, "connection does not exist");
ConnectionEnd.State state = connection.getState();
Context.require(state.equals(ConnectionEnd.State.STATE_TRYOPEN), "connection state is not TRYOPEN");

MerklePrefix prefix = new MerklePrefix();
prefix.setKeyPrefix(commitmentPrefix);

Counterparty expectedCounterparty = new Counterparty();
expectedCounterparty.setClientId(connection.getClientId());
expectedCounterparty.setConnectionId(msg.connectionId);
expectedCounterparty.setPrefix(prefix);

ConnectionEnd expectedConnection = new ConnectionEnd();
expectedConnection.setClientId(connection.getCounterparty().getClientId());
expectedConnection.setVersions(connection.getVersions());
expectedConnection.setState(ConnectionEnd.State.STATE_OPEN);
expectedConnection.setDelayPeriod(connection.delayPeriod);
expectedConnection.setCounterparty(expectedCounterparty);

verifyConnectionState(connection, msg.proofHeight, msg.proofAck, connection.getCounterparty().getConnectionId(),
expectedConnection);

connection.setState(ConnectionEnd.State.STATE_OPEN);

updateConnectionCommitment(msg.connectionId, connection);
connections.set(msg.connectionId, connection);
}

/* Verification functions */

private void verifyClientState(ConnectionEnd connection, Height height, byte[] path, byte[] proof,
byte[] clientStatebytes) {
ILightClient client = getClient(connection.getClientId());
boolean ok = client.verifyMembership(
connection.getClientId(),
height,
BigInteger.ZERO,
BigInteger.ZERO,
proof,
connection.getCounterparty().getPrefix().getKeyPrefix(),
path,
clientStatebytes);
Context.require(ok, "failed to verify clientState");
}

private void verifyClientConsensusState(ConnectionEnd connection, Height height, Height consensusHeight,
byte[] proof, byte[] consensusStateBytes) {
byte[] consensusPath = IBCCommitment.consensusStatePath(connection.getCounterparty().getClientId(),
consensusHeight.getRevisionNumber(),
consensusHeight.getRevisionHeight());

ILightClient client = getClient(connection.getClientId());
boolean ok = client.verifyMembership(
connection.getClientId(),
height,
BigInteger.ZERO,
BigInteger.ZERO,
proof,
connection.getCounterparty().getPrefix().getKeyPrefix(),
consensusPath,
consensusStateBytes);
Context.require(ok, "failed to verify consensus state");

}

private void verifyConnectionState(ConnectionEnd connection, Height height, byte[] proof, String connectionId,
ConnectionEnd counterpartyConnection) {
ILightClient client = getClient(connection.getClientId());
boolean ok = client.verifyMembership(
connection.getClientId(),
height,
BigInteger.ZERO,
BigInteger.ZERO,
proof,
connection.getCounterparty().getPrefix().getKeyPrefix(),
IBCCommitment.connectionPath(connectionId),
counterpartyConnection.toBytes());
Context.require(ok, "failed to verify connection state");
}

/* Internal functions */

private String generateConnectionIdentifier() {
BigInteger currConnectionSequence = nextConnectionSequence.getOrDefault(BigInteger.ZERO);
String identifier = "connection-" + currConnectionSequence.toString();
nextConnectionSequence.set(currConnectionSequence.add(BigInteger.ONE));

return identifier;
}

/**
* {@code @dev} getSupportedVersions return the supported versions.
*/
private Version[] getSupportedVersions() {
Version version = new Version();
version.setFeatures(supportedV1Features);
version.setIdentifier(v1Identifier);

return new Version[]{version};
}

// TODO implement
private boolean isSupportedVersion(Version version) {
return true;
}

private void updateConnectionCommitment(String connectionId, ConnectionEnd connection) {
commitments.set(IBCCommitment.connectionCommitmentKey(connectionId),
IBCCommitment.keccak256(connection.toBytes()));
}

}
Loading

0 comments on commit 8cf16fa

Please sign in to comment.