Skip to content

Commit

Permalink
Merge pull request #10 from datachainlab/update-relayer
Browse files Browse the repository at this point in the history
Update relayer to v0.4.19

Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele authored Nov 22, 2023
2 parents edc90b7 + 38acca7 commit 22b74b3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 32 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/ethereum/go-ethereum v1.12.0
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hyperledger-labs/yui-relayer v0.4.17
github.com/hyperledger-labs/yui-relayer v0.4.19
github.com/oasisprotocol/oasis-core/go v0.2201.11
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,8 @@ github.com/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw
github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
github.com/hyperledger-labs/yui-relayer v0.4.17 h1:cjXYvfkTFiJEpXLtaMPQ7Q6Kd3vFvwQ0FAZ3JncoEz0=
github.com/hyperledger-labs/yui-relayer v0.4.17/go.mod h1:Hdc/ERCPDhbipri45/U6+/3kDH7EttIWGdql+Rd3tZg=
github.com/hyperledger-labs/yui-relayer v0.4.19 h1:I139zRG0228bRAyrhEV2Pgdwbv9Fx2vw3azNHhYqnsc=
github.com/hyperledger-labs/yui-relayer v0.4.19/go.mod h1:Hdc/ERCPDhbipri45/U6+/3kDH7EttIWGdql+Rd3tZg=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=
Expand Down
49 changes: 22 additions & 27 deletions relay/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
lcptypes "github.com/datachainlab/lcp-go/light-clients/lcp/types"
Expand Down Expand Up @@ -99,32 +98,42 @@ func (pr *Prover) GetChainID() string {
return pr.originChain.ChainID()
}

// CreateMsgCreateClient creates a CreateClientMsg to this chain
func (pr *Prover) CreateMsgCreateClient(clientID string, dstHeader core.Header, signer sdk.AccAddress) (*clienttypes.MsgCreateClient, error) {
// CreateInitialLightClientState returns a pair of ClientState and ConsensusState based on the state of the self chain at `height`.
// These states will be submitted to the counterparty chain as MsgCreateClient.
// If `height` is nil, the latest finalized height is selected automatically.
func (pr *Prover) CreateInitialLightClientState(height exported.Height) (exported.ClientState, exported.ConsensusState, error) {
if err := pr.initServiceClient(); err != nil {
return nil, err
return nil, nil, err
}
// NOTE: Query the LCP for available keys, but no need to register it into on-chain here
eki, err := pr.selectNewEnclaveKey(context.TODO())
if err != nil {
return nil, err
return nil, nil, err
}
msg, err := pr.originProver.CreateMsgCreateClient(clientID, dstHeader, signer)
originClientState, originConsensusState, err := pr.originProver.CreateInitialLightClientState(height)
if err != nil {
return nil, err
return nil, nil, err
}
anyOriginClientState, err := clienttypes.PackClientState(originClientState)
if err != nil {
return nil, nil, err
}
anyOriginConsensusState, err := clienttypes.PackConsensusState(originConsensusState)
if err != nil {
return nil, nil, err
}
res, err := pr.lcpServiceClient.CreateClient(context.TODO(), &elc.MsgCreateClient{
ClientState: msg.ClientState,
ConsensusState: msg.ConsensusState,
ClientState: anyOriginClientState,
ConsensusState: anyOriginConsensusState,
Signer: eki.EnclaveKeyAddress,
})
if err != nil {
return nil, err
return nil, nil, err
}

// TODO relayer should persist res.ClientId
if pr.config.ElcClientId != res.ClientId {
return nil, fmt.Errorf("you must specify '%v' as elc_client_id, but got %v", res.ClientId, pr.config.ElcClientId)
return nil, nil, fmt.Errorf("you must specify '%v' as elc_client_id, but got %v", res.ClientId, pr.config.ElcClientId)
}

clientState := &lcptypes.ClientState{
Expand All @@ -135,27 +144,13 @@ func (pr *Prover) CreateMsgCreateClient(clientID string, dstHeader core.Header,
AllowedAdvisoryIds: pr.config.AllowedAdvisoryIds,
}
consensusState := &lcptypes.ConsensusState{}

anyClientState, err := clienttypes.PackClientState(clientState)
if err != nil {
return nil, err
}
anyConsensusState, err := clienttypes.PackConsensusState(consensusState)
if err != nil {
return nil, err
}

// NOTE after creates client, register an enclave key into the client state
return &clienttypes.MsgCreateClient{
ClientState: anyClientState,
ConsensusState: anyConsensusState,
Signer: signer.String(),
}, nil
return clientState, consensusState, nil
}

// GetLatestFinalizedHeader returns the latest finalized header on this chain
// The returned header is expected to be the latest one of headers that can be verified by the light client
func (pr *Prover) GetLatestFinalizedHeader() (latestFinalizedHeader core.Header, err error) {
func (pr *Prover) GetLatestFinalizedHeader() (core.Header, error) {
return pr.originProver.GetLatestFinalizedHeader()
}

Expand Down
4 changes: 2 additions & 2 deletions relay/tendermint/cmd/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ func updateLightCmd(ctx *config.Context) *cobra.Command {
return err
}

ah, err := prover.UpdateLightClient()
ah, err := prover.UpdateLightClient(0)
if err != nil {
return err
}

fmt.Printf("Updated light client for %s from height %d -> height %d\n", args[0], bh.Header.Height, ah.(*tmclient.Header).Header.Height)
fmt.Printf("Updated light client for %s from height %d -> height %d\n", args[0], bh.Header.Height, ah.Header.Height)
return nil
},
}
Expand Down

0 comments on commit 22b74b3

Please sign in to comment.