From cb165d7d45ab0118d3244ddeb2890cbe5bade0b3 Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Thu, 23 Nov 2023 23:31:30 +0900 Subject: [PATCH 1/2] update README Signed-off-by: Jun Kimura --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fb188d..61fa55a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ lcp-go includes the followings: - [lcp v0.2.2](https://github.com/datachainlab/lcp/releases/tag/v0.2.2) - [ibc-go v7.2](https://github.com/cosmos/ibc-go/releases/tag/v7.2.0) -- [yui-relayer v0.4.17](https://github.com/hyperledger-labs/yui-relayer/releases/tag/v0.4.17) +- [yui-relayer v0.4.19](https://github.com/hyperledger-labs/yui-relayer/releases/tag/v0.4.19) ## How to run tests From a84ba513f501d4a1718c8df9d90c8602bde2507f Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Thu, 23 Nov 2023 23:31:49 +0900 Subject: [PATCH 2/2] add `height` option to `restore` command Signed-off-by: Jun Kimura --- relay/cmd.go | 15 ++++++++++++--- relay/restore.go | 18 +++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/relay/cmd.go b/relay/cmd.go index 9b52e61..99296d6 100644 --- a/relay/cmd.go +++ b/relay/cmd.go @@ -10,7 +10,8 @@ import ( ) const ( - flagSrc = "src" + flagSrc = "src" + flagHeight = "height" ) func LCPCmd(ctx *config.Context) *cobra.Command { @@ -111,7 +112,7 @@ func restoreELCStateCmd(ctx *config.Context) *cobra.Command { verifier = c[src] } prover := target.Prover.(*Prover) - if err := prover.restoreELCState(context.TODO(), verifier); err != nil { + if err := prover.restoreELCState(context.TODO(), verifier, viper.GetUint64(flagHeight)); err != nil { return err } if err := prover.removeEnclaveKeyInfos(context.TODO()); err != nil { @@ -120,7 +121,7 @@ func restoreELCStateCmd(ctx *config.Context) *cobra.Command { return nil }, } - return srcFlag(cmd) + return heightFlag(srcFlag(cmd)) } func removeEnclaveKeyInfoCmd(ctx *config.Context) *cobra.Command { @@ -153,3 +154,11 @@ func srcFlag(cmd *cobra.Command) *cobra.Command { } return cmd } + +func heightFlag(cmd *cobra.Command) *cobra.Command { + cmd.Flags().Uint64P(flagHeight, "", 0, "a height to restore") + if err := viper.BindPFlag(flagHeight, cmd.Flags().Lookup(flagHeight)); err != nil { + panic(err) + } + return cmd +} diff --git a/relay/restore.go b/relay/restore.go index 8b7701f..56aa3f0 100644 --- a/relay/restore.go +++ b/relay/restore.go @@ -14,7 +14,7 @@ import ( "github.com/hyperledger-labs/yui-relayer/core" ) -func (pr *Prover) restoreELCState(ctx context.Context, counterparty core.FinalityAwareChain) error { +func (pr *Prover) restoreELCState(ctx context.Context, counterparty core.FinalityAwareChain, height uint64) error { if err := pr.initServiceClient(); err != nil { return err } @@ -31,7 +31,6 @@ func (pr *Prover) restoreELCState(ctx context.Context, counterparty core.Finalit if err != nil { return err } - counterpartyClientRes, err := counterparty.QueryClientState(core.NewQueryContext(context.TODO(), cplatestHeight)) if err != nil { return err @@ -41,7 +40,16 @@ func (pr *Prover) restoreELCState(ctx context.Context, counterparty core.Finalit return err } - counterpartyConsRes, err := counterparty.QueryClientConsensusState(core.NewQueryContext(context.TODO(), cplatestHeight), cs.GetLatestHeight()) + var restoreHeight ibcexported.Height + if height == 0 { + restoreHeight = cs.GetLatestHeight() + } else { + restoreHeight = clienttypes.NewHeight(cs.GetLatestHeight().GetRevisionNumber(), height) + } + + log.Printf("try to restore ELC state: height=%v", restoreHeight) + + counterpartyConsRes, err := counterparty.QueryClientConsensusState(core.NewQueryContext(context.TODO(), cplatestHeight), restoreHeight) if err != nil { return err } @@ -109,8 +117,8 @@ func (pr *Prover) restoreELCState(ctx context.Context, counterparty core.Finalit if !ucc.NewStateID.EqualBytes(consensusState.StateId) { return fmt.Errorf("unexpected state id: expected %v, but got %v", ucc.NewStateID, consensusState.StateId) } - if !ucc.NewHeight.EQ(clientState.LatestHeight) { - return fmt.Errorf("unexpected height: expected %v, but got %v", ucc.NewHeight, clientState.LatestHeight) + if !ucc.NewHeight.EQ(restoreHeight) { + return fmt.Errorf("unexpected height: expected %v, but got %v", restoreHeight, ucc.NewHeight) } // TODO relayer should update res.ClientId in the config