From e73877c9e993e4963e92cbff173cf15793c76a2c Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Mon, 16 Oct 2023 19:28:10 +0900 Subject: [PATCH 1/2] fix empty proof bug Signed-off-by: Masanori Yoshida --- core/query.go | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/core/query.go b/core/query.go index 14e6cb47..942bbc38 100644 --- a/core/query.go +++ b/core/query.go @@ -20,13 +20,15 @@ func QueryClientStatePair( ) (srcCsRes, dstCsRes *clienttypes.QueryClientStateResponse, err error) { var eg = new(errgroup.Group) eg.Go(func() error { + var err error srcCsRes, err = src.QueryClientState(srcCtx) if err != nil { return err } if prove { path := host.FullClientStatePath(src.Path().ClientID) - value, err := src.Codec().Marshal(srcCsRes.ClientState) + var value []byte + value, err = src.Codec().Marshal(srcCsRes.ClientState) if err != nil { return err } @@ -35,13 +37,15 @@ func QueryClientStatePair( return err }) eg.Go(func() error { + var err error dstCsRes, err = dst.QueryClientState(dstCtx) if err != nil { return err } if prove { path := host.FullClientStatePath(dst.Path().ClientID) - value, err := dst.Codec().Marshal(dstCsRes.ClientState) + var value []byte + value, err = dst.Codec().Marshal(dstCsRes.ClientState) if err != nil { return err } @@ -66,13 +70,15 @@ func QueryClientConsensusStatePair( ) (srcCsRes, dstCsRes *clienttypes.QueryConsensusStateResponse, err error) { var eg = new(errgroup.Group) eg.Go(func() error { + var err error srcCsRes, err = src.QueryClientConsensusState(srcCtx, srcClientConsH) if err != nil { return err } if prove { path := host.FullConsensusStatePath(src.Path().ClientID, srcClientConsH) - value, err := src.Codec().Marshal(srcCsRes.ConsensusState) + var value []byte + value, err = src.Codec().Marshal(srcCsRes.ConsensusState) if err != nil { return err } @@ -81,13 +87,15 @@ func QueryClientConsensusStatePair( return err }) eg.Go(func() error { + var err error dstCsRes, err = dst.QueryClientConsensusState(dstCtx, dstClientConsH) if err != nil { return err } if prove { path := host.FullConsensusStatePath(dst.Path().ClientID, dstClientConsH) - value, err := dst.Codec().Marshal(dstCsRes.ConsensusState) + var value []byte + value, err = dst.Codec().Marshal(dstCsRes.ConsensusState) if err != nil { return err } @@ -110,6 +118,7 @@ func QueryConnectionPair( ) (srcConn, dstConn *conntypes.QueryConnectionResponse, err error) { var eg = new(errgroup.Group) eg.Go(func() error { + var err error srcConn, err = src.QueryConnection(srcCtx) if err != nil { return err @@ -118,7 +127,8 @@ func QueryConnectionPair( } if prove { path := host.ConnectionPath(src.Path().ConnectionID) - value, err := src.Codec().Marshal(srcConn.Connection) + var value []byte + value, err = src.Codec().Marshal(srcConn.Connection) if err != nil { return err } @@ -127,6 +137,7 @@ func QueryConnectionPair( return err }) eg.Go(func() error { + var err error dstConn, err = dst.QueryConnection(dstCtx) if err != nil { return err @@ -135,7 +146,8 @@ func QueryConnectionPair( } if prove { path := host.ConnectionPath(dst.Path().ConnectionID) - value, err := dst.Codec().Marshal(dstConn.Connection) + var value []byte + value, err = dst.Codec().Marshal(dstConn.Connection) if err != nil { return err } @@ -154,6 +166,7 @@ func QueryChannelPair(srcCtx, dstCtx QueryContext, src, dst interface { }, prove bool) (srcChan, dstChan *chantypes.QueryChannelResponse, err error) { var eg = new(errgroup.Group) eg.Go(func() error { + var err error srcChan, err = src.QueryChannel(srcCtx) if err != nil { return err @@ -162,7 +175,8 @@ func QueryChannelPair(srcCtx, dstCtx QueryContext, src, dst interface { } if prove { path := host.ChannelPath(src.Path().PortID, src.Path().ChannelID) - value, err := src.Codec().Marshal(srcChan.Channel) + var value []byte + value, err = src.Codec().Marshal(srcChan.Channel) if err != nil { return err } @@ -171,6 +185,7 @@ func QueryChannelPair(srcCtx, dstCtx QueryContext, src, dst interface { return err }) eg.Go(func() error { + var err error dstChan, err = dst.QueryChannel(dstCtx) if err != nil { return err @@ -179,7 +194,8 @@ func QueryChannelPair(srcCtx, dstCtx QueryContext, src, dst interface { } if prove { path := host.ChannelPath(dst.Path().PortID, dst.Path().ChannelID) - value, err := dst.Codec().Marshal(dstChan.Channel) + var value []byte + value, err = dst.Codec().Marshal(dstChan.Channel) if err != nil { return err } From 17b6fcdd12ee1b5a3b5f8291ec80321e88ae6e33 Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Mon, 16 Oct 2023 19:58:05 +0900 Subject: [PATCH 2/2] tendermint: fix `waitForCommit` to avoid empty proof error at `ProveState` Signed-off-by: Masanori Yoshida --- chains/tendermint/chain.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/chains/tendermint/chain.go b/chains/tendermint/chain.go index c16d7a37..853f1fba 100644 --- a/chains/tendermint/chain.go +++ b/chains/tendermint/chain.go @@ -276,6 +276,15 @@ func (c *Chain) waitForCommit(txHash string) (*coretypes.ResultTx, error) { return retry.Unrecoverable(err) } } + // In a tendermint chain, when the latest height of the chain is N+1, + // proofs of states updated up to height N are available. + // In order to make the proof of the state updated by a tx available just after `sendMsgs`, + // `waitForCommit` must wait until the latest height is greater than the tx height. + if height, err := c.LatestHeight(); err != nil { + return fmt.Errorf("failed to obtain latest height: %v", err) + } else if height.GetRevisionHeight() <= uint64(resTx.Height) { + return fmt.Errorf("latest_height(%v) is less than or equal to tx_height(%v) yet", height, resTx.Height) + } return nil }, retry.Attempts(maxRetry), retry.Delay(retryInterval), rtyErr); err != nil { return resTx, fmt.Errorf("failed to make sure that tx is committed: %v", err)