Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Dec 19, 2024
1 parent 18f534b commit ca1fd92
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ transfer:
@go run ./testing/demo/pkg/transfer/
.PHONY: transfer

## stop: Stop all processes and removes the tmp directory.
## stop: Stop all processes and remove the tmp directory.
stop:
@echo "--> Stopping all processes"
@docker compose down
@docker compose rm
@echo "--> Clearing tmp directory"
@echo "--> Removing the tmp directory"
@rm -rf .tmp
.PHONY: stop

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ replace (
// Replace ibc-go with the most recent commit on the feat/ibc-eureka branch.
// ea4e73629c55e35537467d9f032da5be8082b468 is the recent commit as of this writing.
// See https://github.com/cosmos/ibc-go/tree/feat/ibc-eureka
// github.com/cosmos/ibc-go/v9 => github.com/cosmos/ibc-go/v9 v9.0.0-20241218142801-ea4e73629c55
github.com/cosmos/ibc-go/v9 => ../../cosmos/ibc-go
github.com/cosmos/ibc-go/v9 => github.com/cosmos/ibc-go/v9 v9.0.0-20241218142801-ea4e73629c55
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fr
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
github.com/cosmos/iavl v1.2.0 h1:kVxTmjTh4k0Dh1VNL046v6BXqKziqMDzxo93oh3kOfM=
github.com/cosmos/iavl v1.2.0/go.mod h1:HidWWLVAtODJqFD6Hbne2Y0q3SdxByJepHUOeoH4LiI=
github.com/cosmos/ibc-go/v9 v9.0.0-20241218142801-ea4e73629c55 h1:tvvb3EXXVrYaCOFGuS1awUBEfoI9a0qjhJaQnbkagZ4=
github.com/cosmos/ibc-go/v9 v9.0.0-20241218142801-ea4e73629c55/go.mod h1:6+3if3nHW38kA8P2Lcb4UIDpt5BIUPbrCGAD8kGIli8=
github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU=
github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0=
github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM=
Expand Down
69 changes: 34 additions & 35 deletions testing/demo/pkg/setup/initialise_groth16_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"errors"
"fmt"
"math/big"
"slices"
Expand All @@ -21,17 +20,15 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
)

// relayer address registered in simapp
const Relayer = "cosmos1ltvzpwf3eg8e9s7wzleqdmw02lesrdex9jgt0q"

var Groth16ClientId string
// relayer is the address registered on simapp
const relayer = "cosmos1ltvzpwf3eg8e9s7wzleqdmw02lesrdex9jgt0q"

func InitializeGroth16LightClientOnSimapp() error {
fmt.Println("Initializing the groth16 light client")
fmt.Println("Initializing the Groth16 light client on simapp...")

ethClient, err := ethclient.Dial("http://localhost:8545")
if err != nil {
return fmt.Errorf("failed to connect to ethereum client: %v", err)
return fmt.Errorf("failed to connect to Ethereum client: %v", err)
}

genesisBlock, latestBlock, err := getGenesisAndLatestBlock(ethClient)
Expand All @@ -49,15 +46,14 @@ func InitializeGroth16LightClientOnSimapp() error {
return fmt.Errorf("failed to setup client context: %v", err)
}

if err := createClientOnSimapp(clientCtx, clientState, consensusState); err != nil {
clientId, err := createClientOnSimapp(clientCtx, clientState, consensusState)
if err != nil {
return err
}
fmt.Println("Groth16 client created successfully on simapp")

if err := createChannelOnSimapp(clientCtx); err != nil {
if err := createChannelOnSimapp(clientCtx, clientId); err != nil {
return err
}
fmt.Println("Channel created successfully on simapp")

return nil
}
Expand Down Expand Up @@ -93,66 +89,69 @@ func getGenesisAndLatestBlock(ethClient *ethclient.Client) (*ethtypes.Block, *et
return genesisBlock, latestBlock, nil
}

func createClientOnSimapp(clientCtx client.Context, clientState, consensusState *cdctypes.Any) error {
func createClientOnSimapp(clientCtx client.Context, clientState, consensusState *cdctypes.Any) (clientId string, err error) {
createClientMsg := &clienttypes.MsgCreateClient{
ClientState: clientState,
ConsensusState: consensusState,
Signer: Relayer,
Signer: relayer,
}

if clientState.GetCachedValue().(*groth16.ClientState).ClientType() != consensusState.GetCachedValue().(*groth16.ConsensusState).ClientType() {
fmt.Println("Client and consensus state client types do not match")
}

createClientMsgResponse, err := utils.BroadcastMessages(clientCtx, Relayer, 200_000, createClientMsg)
createClientMsgResponse, err := utils.BroadcastMessages(clientCtx, relayer, 200_000, createClientMsg)
if err != nil {
return fmt.Errorf("failed to broadcast the initial client creation message: %v", err)
return "", fmt.Errorf("failed to broadcast the initial client creation message: %v", err)
}

if createClientMsgResponse.Code != 0 {
return fmt.Errorf("failed to create client: %v", createClientMsgResponse.RawLog)
return "", fmt.Errorf("failed to create client: %v", createClientMsgResponse.RawLog)
}

Groth16ClientId, err = ParseClientIDFromEvents(createClientMsgResponse.Events)
clientId, err = parseClientIDFromEvents(createClientMsgResponse.Events)
if err != nil {
return fmt.Errorf("failed to parse client id from events: %v", err)
return "", fmt.Errorf("failed to parse client id from events: %v", err)
}

return nil
fmt.Printf("Created Groth16 client with clientId %v on simapp.\n", clientId)
return clientId, nil
}

func createChannelOnSimapp(clientCtx client.Context) error {
func createChannelOnSimapp(clientCtx client.Context, clientId string) error {
cosmosMerklePathPrefix := commitmenttypesv2.NewMerklePath([]byte("simd"))
msgCreateChannelResp, err := utils.BroadcastMessages(clientCtx, Relayer, 200_000, &channeltypesv2.MsgCreateChannel{
ClientId: Groth16ClientId,
msg := channeltypesv2.MsgCreateChannel{
ClientId: clientId,
MerklePathPrefix: cosmosMerklePathPrefix,
Signer: Relayer,
})
Signer: relayer,
}
response, err := utils.BroadcastMessages(clientCtx, relayer, 200_000, &msg)
if err != nil {
return fmt.Errorf("failed to create channel: %v", err)
}
if msgCreateChannelResp.Code != 0 {
return fmt.Errorf("failed to create channel: %v", msgCreateChannelResp.RawLog)
if response.Code != 0 {
return fmt.Errorf("failed to create channel: %v", response.RawLog)
}

fmt.Println("Created channel on simapp.")
return nil
}

// ParseClientIDFromEvents parses events emitted from a MsgCreateClient and returns the
// client identifier.
func ParseClientIDFromEvents(events []abci.Event) (string, error) {
for _, ev := range events {
if ev.Type == clienttypes.EventTypeCreateClient {
if attribute, found := attributeByKey(ev.Attributes, clienttypes.AttributeKeyClientID); found {
// parseClientIDFromEvents parses events emitted from a MsgCreateClient and
// returns the client identifier.
func parseClientIDFromEvents(events []abci.Event) (string, error) {
for _, event := range events {
if event.Type == clienttypes.EventTypeCreateClient {
if attribute, isFound := getAttributeByKey(event.Attributes, clienttypes.AttributeKeyClientID); isFound {
return attribute.Value, nil
}
}
}
return "", errors.New("client identifier event attribute not found")
return "", fmt.Errorf("client identifier event attribute not found")
}

// attributeByKey returns the event attribute's value keyed by the given key and a boolean indicating its presence in the given attributes.
func attributeByKey(attributes []abci.EventAttribute, key string) (abci.EventAttribute, bool) {
// getAttributeByKey returns the first even attribute with the given key.
func getAttributeByKey(attributes []abci.EventAttribute, key string) (ea abci.EventAttribute, isFound bool) {
idx := slices.IndexFunc(attributes, func(a abci.EventAttribute) bool { return a.Key == key })
if idx == -1 {
return abci.EventAttribute{}, false
Expand Down
13 changes: 6 additions & 7 deletions testing/demo/pkg/setup/initialise_sp1tm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ContractAddresses struct {
}

func InitializeSp1TendermintLightClientOnReth() error {
fmt.Println("Deploying IBC smart contracts on the reth node...")
fmt.Println("Deploying IBC smart contracts on reth node...")

if err := runDeploymentCommand(); err != nil {
return err
Expand All @@ -51,7 +51,7 @@ func InitializeSp1TendermintLightClientOnReth() error {
if err != nil {
return err
}
fmt.Println("Contract Addresses:", addresses)
fmt.Printf("Contract Addresses: %v\n", addresses)

ethClient, err := ethclient.Dial("http://localhost:8545")
if err != nil {
Expand All @@ -61,13 +61,13 @@ func InitializeSp1TendermintLightClientOnReth() error {
if err := createChannelAndCounterpartyOnReth(addresses, ethClient); err != nil {
return err
}
fmt.Println("Channel and counterparty created successfully on reth node")
fmt.Println("Created channel and counterparty on reth node.")

if err := createCounterpartyOnSimapp(); err != nil {
return err
}
fmt.Println("Counterparty created successfully on simapp")

fmt.Println("Created counterparty on simapp.")
return nil

}
Expand Down Expand Up @@ -179,10 +179,10 @@ func createCounterpartyOnSimapp() error {
return fmt.Errorf("failed to setup client context: %v", err)
}

registerCounterPartyResp, err := utils.BroadcastMessages(clientCtx, Relayer, 200_000, &channeltypesv2.MsgRegisterCounterparty{
registerCounterPartyResp, err := utils.BroadcastMessages(clientCtx, relayer, 200_000, &channeltypesv2.MsgRegisterCounterparty{
ChannelId: channelId,
CounterpartyChannelId: TendermintLightClientID,
Signer: Relayer,
Signer: relayer,
})
if err != nil {
return fmt.Errorf("failed to register counterparty: %v", err)
Expand Down Expand Up @@ -233,7 +233,6 @@ func GetTxReceipt(ctx context.Context, ethClient *ethclient.Client, hash ethcomm
if err != nil {
panic(err)
}
fmt.Println("made it here")
return receipt
}

Expand Down

0 comments on commit ca1fd92

Please sign in to comment.