Skip to content

Commit

Permalink
Merge pull request #114 from siburu/fix-empty-proof
Browse files Browse the repository at this point in the history
Fix empty proof error at `ProveState` of the tendermint prover
  • Loading branch information
siburu authored Oct 16, 2023
2 parents d81ea3e + 17b6fcd commit 4e913ba
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
9 changes: 9 additions & 0 deletions chains/tendermint/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 24 additions & 8 deletions core/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 4e913ba

Please sign in to comment.