Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: btp block missing issue fix #150

Merged
merged 15 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions relayer/chains/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
chantypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
tmclient "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/cosmos/relayer/v2/relayer/provider"
Expand Down Expand Up @@ -1169,3 +1170,8 @@ func (cc *CosmosProvider) QueryConsensusStateABCI(ctx context.Context, clientID
ProofHeight: proofHeight,
}, nil
}

func (ap *CosmosProvider) QueryClientPrevConsensusStateHeight(ctx context.Context, chainHeight int64, clientId string, clientHeight int64) (exported.Height, error) {
panic("QueryClientPrevConsensusStateHeight not implemented")

}
1 change: 0 additions & 1 deletion relayer/chains/icon/icon_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ func (icp *IconChainProcessor) handleBTPBlockRequest(
}
request.response.Header = NewIconIBCHeader(btpHeader, validators, int64(btpHeader.MainHeight))
request.response.IsProcessed = processed

}

func (icp *IconChainProcessor) handlePathProcessorUpdate(ctx context.Context,
Expand Down
4 changes: 2 additions & 2 deletions relayer/chains/icon/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,5 +475,5 @@ func TestHash(t *testing.T) {
// isValid, err := VerifyBtpProof(decision, signedHeader.Signatures, proofContext)
// assert.NoError(t, err)

// assert.True(t, isValid)
// }
// assert.True(t, isValid)
// }
5 changes: 5 additions & 0 deletions relayer/chains/icon/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/avast/retry-go/v4"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/proto"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/pkg/errors"
"go.uber.org/zap"
Expand Down Expand Up @@ -837,6 +838,10 @@ func (icp *IconProvider) QueryIconProof(ctx context.Context, height int64, keyHa
return nil, nil
}

func (ip *IconProvider) QueryClientPrevConsensusStateHeight(ctx context.Context, chainHeight int64, clientId string, clientHeight int64) (exported.Height, error) {
panic("QueryClientPrevConsensusStateHeight not implemented")
}

func (icp *IconProvider) HexStringToProtoUnmarshal(encoded string, v proto.Message) ([]byte, error) {
if encoded == "" {
return nil, fmt.Errorf("Encoded string is empty ")
Expand Down
5 changes: 5 additions & 0 deletions relayer/chains/penumbra/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
chantypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
tmclient "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/cosmos/relayer/v2/relayer/provider"
Expand Down Expand Up @@ -983,3 +984,7 @@ func (cc *PenumbraProvider) QueryICQWithProof(ctx context.Context, msgType strin
//TODO implement me
panic("implement me")
}

func (cc *PenumbraProvider) QueryClientPrevConsensusStateHeight(ctx context.Context, chainHeight int64, clientId string, clientHeight int64) (exported.Height, error) {
panic("QueryClientPrevConsensusStateHeight not implemented")
}
22 changes: 21 additions & 1 deletion relayer/chains/wasm/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
conntypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
chantypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"

ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/cosmos/relayer/v2/relayer/chains/wasm/types"
Expand Down Expand Up @@ -353,7 +354,6 @@ func (ap *WasmProvider) QueryIBCHandlerContract(ctx context.Context, param wasmt
zap.Error(err),
)
}))

}

func (ap *WasmProvider) QueryIBCHandlerContractProcessed(ctx context.Context, param wasmtypes.RawContractMessage) ([]byte, error) {
Expand Down Expand Up @@ -859,3 +859,23 @@ func (ap *WasmProvider) QueryDenomTraces(ctx context.Context, offset, limit uint
}
return transfers, nil
}

func (ap *WasmProvider) QueryClientPrevConsensusStateHeight(ctx context.Context, chainHeight int64, clientId string, clientHeight int64) (exported.Height, error) {
param, err := types.NewPrevConsensusStateHeight(clientId, uint64(clientHeight)).Bytes()
res, err := ap.QueryIBCHandlerContract(ctx, param)
if err != nil {
return nil, err
}

var heights []int64
err = json.Unmarshal(res.Data.Bytes(), &heights)

if err != nil {
return nil, err
}

if len(heights) == 0 {
return nil, fmt.Errorf("consensus state of client %s before %d", clientId, clientHeight)
}
return clienttypes.Height{RevisionNumber: 0, RevisionHeight: uint64(heights[0])}, nil
}
30 changes: 14 additions & 16 deletions relayer/chains/wasm/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,20 +744,20 @@ func (ap *WasmProvider) SendMessagesToMempool(
return err
}

if msg.Type() == MethodUpdateClient {
if err := retry.Do(func() error {
if err := ap.BroadcastTx(cliCtx, txBytes, []provider.RelayerMessage{msg}, asyncCtx, defaultBroadcastWaitTimeout, asyncCallback, true); err != nil {
if strings.Contains(err.Error(), sdkerrors.ErrWrongSequence.Error()) {
ap.handleAccountSequenceMismatchError(err)
}
}
return err
}, retry.Context(ctx), rtyAtt, retry.Delay(time.Millisecond*time.Duration(ap.PCfg.BlockInterval)), rtyErr); err != nil {
ap.log.Error("Failed to update client", zap.Any("Message", msg))
return err
}
continue
}
// if msg.Type() == MethodUpdateClient {
// if err := retry.Do(func() error {
// if err := ap.BroadcastTx(cliCtx, txBytes, []provider.RelayerMessage{msg}, asyncCtx, defaultBroadcastWaitTimeout, asyncCallback, true); err != nil {
// if strings.Contains(err.Error(), sdkerrors.ErrWrongSequence.Error()) {
// ap.handleAccountSequenceMismatchError(err)
// }
// }
// return err
// }, retry.Context(ctx), rtyAtt, retry.Delay(time.Millisecond*time.Duration(ap.PCfg.BlockInterval)), rtyErr); err != nil {
// ap.log.Error("Failed to update client", zap.Any("Message", msg))
// return err
// }
// continue
// }
if err := ap.BroadcastTx(cliCtx, txBytes, []provider.RelayerMessage{msg}, asyncCtx, defaultBroadcastWaitTimeout, asyncCallback, false); err != nil {
if strings.Contains(err.Error(), sdkerrors.ErrWrongSequence.Error()) {
ap.handleAccountSequenceMismatchError(err)
Expand Down Expand Up @@ -1262,8 +1262,6 @@ func (cc *WasmProvider) QueryABCI(ctx context.Context, req abci.RequestQuery) (a
func (cc *WasmProvider) handleAccountSequenceMismatchError(err error) {

clientCtx := cc.ClientContext()
fmt.Println("client context is ", clientCtx.GetFromAddress())

_, seq, err := cc.ClientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, clientCtx.GetFromAddress())

// sequences := numRegex.FindAllString(err.Error(), -1)
Expand Down
32 changes: 24 additions & 8 deletions relayer/chains/wasm/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ func NewClientState(clientId string) *GetClientState {
}
}

type ConsensusStateByHeight struct {
ClientId string "json:\"client_id\""
Height uint64 "json:\"height\""
}

type GetConsensusStateByHeight struct {
ConsensusStateByHeight struct {
ClientId string "json:\"client_id\""
Height uint64 "json:\"height\""
} `json:"get_consensus_state_by_height"`
ConsensusStateByHeight ConsensusStateByHeight `json:"get_consensus_state_by_height"`
}

func (x *GetConsensusStateByHeight) Bytes() ([]byte, error) {
Expand All @@ -84,10 +86,7 @@ func (x *GetConsensusStateByHeight) Bytes() ([]byte, error) {

func NewConsensusStateByHeight(clientId string, height uint64) *GetConsensusStateByHeight {
return &GetConsensusStateByHeight{
ConsensusStateByHeight: struct {
ClientId string "json:\"client_id\""
Height uint64 "json:\"height\""
}{
ConsensusStateByHeight: ConsensusStateByHeight{
ClientId: clientId,
Height: height,
},
Expand Down Expand Up @@ -353,3 +352,20 @@ func NewCommitmentPrefix() *GetCommitmentPrefix {
GetCommitment: struct{}{},
}
}

type GetPrevConsensusStateHeight struct {
ConsensusStateByHeight ConsensusStateByHeight `json:"get_previous_consensus_state_height"`
}

func (x *GetPrevConsensusStateHeight) Bytes() ([]byte, error) {
return json.Marshal(x)
}

func NewPrevConsensusStateHeight(clientId string, height uint64) *GetPrevConsensusStateHeight {
return &GetPrevConsensusStateHeight{
ConsensusStateByHeight: ConsensusStateByHeight{
ClientId: clientId,
Height: height,
},
}
}
1 change: 1 addition & 0 deletions relayer/chains/wasm/wasm_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (l latestClientState) update(ctx context.Context, clientInfo clientInfo, cc

// update latest if no existing state or provided consensus height is newer
l[clientInfo.clientID] = clientState

}

// Provider returns the ChainProvider, which provides the methods for querying, assembling IBC messages, and sending transactions.
Expand Down
Loading