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

Channel upgrade #143

Merged
merged 47 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
aa2fff3
refactor connection/channel handshake implementations
siburu May 30, 2024
0232e18
add `connectionID` argument to `Chain::QueryConnection` method
siburu Jun 10, 2024
38c1412
add methods for PathEnd to create MsgChannelUpgradeXxx messages
siburu Jun 10, 2024
bc2695c
add QueryChannelUpgrade and QueryChannelUpgradeError to Chain interface
siburu Jun 10, 2024
901aecf
add Chain::QueryCanTransitionToFlushComplete
siburu Jun 20, 2024
77600cb
implement channel upgrade
siburu Jun 20, 2024
1b740b0
fix simapp to use the relayer account as authority for IBC
siburu Jun 26, 2024
cb90c15
add `upgradeSequence` parameter to the parameter list of `Chain::Quer…
siburu Jul 5, 2024
1cb6e4b
fix the "tx channel-upgrade execute" command to gracefully exit after…
siburu Jul 5, 2024
600f614
add test-channel-upgrade to tm2tm
siburu Jul 5, 2024
4604b20
fix Chain::QueryChannelUpgradeError to return the latest error receip…
siburu Jul 5, 2024
20e8dd1
add core.QueryChannelUpgradeError to query an error receipt with proof
siburu Jul 8, 2024
cc2e1c9
add `tx channel-upgrade cancel` command
siburu Jul 8, 2024
f8b4da7
add a case for testing chanUpgradeCancel to the test-channel-upgrade …
siburu Jul 8, 2024
d6aece2
fix core.QueryChannelUpgradeError to return (nil,nil) if no error rec…
siburu Jul 12, 2024
15ff1b2
output a WARN log when cancelling a channel upgrade
siburu Jul 12, 2024
3e589ad
add the --until-flushing flag to the `tx channel-upgrade execute` sub…
siburu Jul 19, 2024
85a2543
improve logging in RelayMsgs::Send
siburu Jul 19, 2024
57869ee
fix core.ConfigI to allow to update the "order" and "version" fields
siburu Jul 24, 2024
49f72d4
update the path config fields (connection-id, version and order) when…
siburu Jul 25, 2024
2be31c2
fix test-channel-upgrade to test the path config update feature
siburu Jul 25, 2024
e802418
minor fix of test-create-xxx
siburu Jul 25, 2024
1bae6e3
minor fix of test-channel-upgrade
siburu Aug 5, 2024
432d60f
output a WARN log when executing chanUpgradeCancel without error receipt
siburu Aug 13, 2024
974ff9f
brush up `channel-upgrade execute` subcommand
siburu Aug 20, 2024
f304f82
add ibc-mock-app to simd
siburu Aug 20, 2024
3a44e81
use mockapp instead of ics20 in tm2tm test
siburu Aug 20, 2024
5ea24b4
add more test cases to test-channel-upgrade
siburu Aug 20, 2024
3d197e4
add more test cases related to timeout
siburu Aug 20, 2024
5763813
remove `upgradeSequence` parameter of `Chain::QueryChannelUpgradeError`
siburu Aug 20, 2024
a60f6e2
add `yrly query channel-upgrade` subcommand
siburu Aug 21, 2024
f776f94
delete use of logger.With in upgradeChannelStep
siburu Aug 22, 2024
b25de5e
add log outputs in channel upgrade functions
siburu Aug 23, 2024
315bb5a
modify {Init,Cancel}ChannelUpgrade to just send a msg and not to wait…
siburu Aug 25, 2024
eaec52a
add the `--unsafe` flag to the `tx channel-upgrade init` subcommand
siburu Aug 26, 2024
0e7d2b3
finish the command successfully if channel upgrade states are transit…
siburu Aug 26, 2024
b65f836
fix a bug in `tx channel-upgrade init`
siburu Aug 26, 2024
8ec8a0a
fix `tx query client|connection|channel|channel-upgrade` to return an…
siburu Aug 26, 2024
8479e6c
brush up and fix logics of checkChannelFinality and checkConnectionFi…
siburu Aug 26, 2024
5f042f2
fix `query channel-upgrade` subcommand to print the zero-value Upgrad…
siburu Aug 27, 2024
382b372
fix CancelChannelUpgrade to wait for state settlement and to send Msg…
siburu Aug 28, 2024
b1b5e66
fix CancelChannelUpgrade to avoid using multicall
siburu Aug 28, 2024
94e2251
fix logging in RelayMsgs
siburu Aug 29, 2024
311828e
fix CancelChannelUpgrade to stop waiting before the first attempt
siburu Aug 29, 2024
67a5da8
fix updateChannelStep to add the `first_call` attribute in log outputs
siburu Aug 29, 2024
d02879e
fix msgsToLoggable
siburu Aug 30, 2024
dc23bc2
improve the loop in ExecuteChannelUpgrade
siburu Aug 30, 2024
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
7 changes: 7 additions & 0 deletions chains/tendermint/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ func parseMsgEventLog(ev abcitypes.Event) (core.MsgEventLog, error) {
return nil, err
}
return &event, nil
case chantypes.EventTypeChannelUpgradeOpen:
var event core.EventUpgradeChannel
var err0, err1, err2 error
event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID)
event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID)
event.UpgradeSequence, err2 = getAttributeUint64(ev, chantypes.AttributeKeyUpgradeSequence)
return &event, errors.Join(err0, err1, err2)
default:
return &core.EventUnknown{Value: ev}, nil
}
Expand Down
88 changes: 83 additions & 5 deletions chains/tendermint/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
committypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
"github.com/hyperledger-labs/yui-relayer/core"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

// QueryClientState retrevies the latest consensus state for a client in state at a given height
Expand Down Expand Up @@ -55,12 +57,12 @@ var emptyConnRes = conntypes.NewQueryConnectionResponse(
)

// QueryConnection returns the remote end of a given connection
func (c *Chain) QueryConnection(ctx core.QueryContext) (*conntypes.QueryConnectionResponse, error) {
return c.queryConnection(int64(ctx.Height().GetRevisionHeight()), false)
func (c *Chain) QueryConnection(ctx core.QueryContext, connectionID string) (*conntypes.QueryConnectionResponse, error) {
return c.queryConnection(int64(ctx.Height().GetRevisionHeight()), connectionID, false)
}

func (c *Chain) queryConnection(height int64, prove bool) (*conntypes.QueryConnectionResponse, error) {
res, err := connutils.QueryConnection(c.CLIContext(height), c.PathEnd.ConnectionID, prove)
func (c *Chain) queryConnection(height int64, connectionID string, prove bool) (*conntypes.QueryConnectionResponse, error) {
res, err := connutils.QueryConnection(c.CLIContext(height), connectionID, prove)
if err != nil && strings.Contains(err.Error(), "not found") {
return emptyConnRes, nil
} else if err != nil {
Expand Down Expand Up @@ -354,11 +356,13 @@ func (c *Chain) queryWrittenAcknowledgement(ctx core.QueryContext, seq uint64) (
}

// QueryTxs returns an array of transactions given a tag
func (c *Chain) QueryTxs(height int64, page, limit int, events []string) ([]*ctypes.ResultTx, error) {
func (c *Chain) QueryTxs(maxHeight int64, page, limit int, events []string) ([]*ctypes.ResultTx, error) {
if len(events) == 0 {
return nil, errors.New("must declare at least one event to search")
}

events = append(events, fmt.Sprintf("tx.height<=%d", maxHeight))

if page <= 0 {
return nil, errors.New("page must greater than 0")
}
Expand All @@ -374,6 +378,65 @@ func (c *Chain) QueryTxs(height int64, page, limit int, events []string) ([]*cty
return res.Txs, nil
}

func (c *Chain) QueryChannelUpgrade(ctx core.QueryContext) (*chantypes.QueryUpgradeResponse, error) {
return c.queryChannelUpgrade(int64(ctx.Height().GetRevisionHeight()), false)
}

func (c *Chain) queryChannelUpgrade(height int64, prove bool) (chanRes *chantypes.QueryUpgradeResponse, err error) {
if res, err := chanutils.QueryUpgrade(
c.CLIContext(height),
c.PathEnd.PortID,
c.PathEnd.ChannelID,
prove,
); err != nil {
if st, ok := status.FromError(err); ok && st.Code() == codes.NotFound {
return nil, nil
} else {
return nil, err
}
} else {
return res, nil
}
}

func (c *Chain) QueryChannelUpgradeError(ctx core.QueryContext) (*chantypes.QueryUpgradeErrorResponse, error) {
return c.queryChannelUpgradeError(int64(ctx.Height().GetRevisionHeight()), false)
}

func (c *Chain) queryChannelUpgradeError(height int64, prove bool) (chanRes *chantypes.QueryUpgradeErrorResponse, err error) {
if res, err := chanutils.QueryUpgradeError(
c.CLIContext(height),
c.PathEnd.PortID,
c.PathEnd.ChannelID,
prove,
); err != nil {
if st, ok := status.FromError(err); ok && st.Code() == codes.NotFound {
return nil, nil
} else {
return nil, err
}
} else {
return res, nil
}
}

func (c *Chain) QueryCanTransitionToFlushComplete(ctx core.QueryContext) (bool, error) {
return c.queryCanTransitionToFlushComplete(int64(ctx.Height().GetRevisionHeight()))
}

func (c *Chain) queryCanTransitionToFlushComplete(height int64) (bool, error) {
queryClient := chantypes.NewQueryClient(c.CLIContext(height))
req := chantypes.QueryPacketCommitmentsRequest{
PortId: c.PathEnd.PortID,
ChannelId: c.PathEnd.ChannelID,
}
if res, err := queryClient.PacketCommitments(context.TODO(), &req); err != nil {
return false, err
} else {
return len(res.Commitments) == 0, nil
}
}

/////////////////////////////////////
// STAKING -> HistoricalInfo //
/////////////////////////////////////
Expand Down Expand Up @@ -470,3 +533,18 @@ func recvPacketQuery(channelID string, seq int) []string {
func writeAckQuery(channelID string, seq int) []string {
return []string{fmt.Sprintf("%s.packet_dst_channel='%s'", waTag, channelID), fmt.Sprintf("%s.packet_sequence='%d'", waTag, seq)}
}

func channelUpgradeErrorQuery(channelID string, upgradeSequence uint64) []string {
return []string{
fmt.Sprintf("%s.%s='%s'",
chantypes.EventTypeChannelUpgradeError,
chantypes.AttributeKeyChannelID,
channelID,
),
fmt.Sprintf("%s.%s='%d'",
chantypes.EventTypeChannelUpgradeError,
chantypes.AttributeKeyUpgradeSequence,
upgradeSequence,
),
}
}
56 changes: 50 additions & 6 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (

"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/jsonpb"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
chantypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
"github.com/hyperledger-labs/yui-relayer/config"
"github.com/hyperledger-labs/yui-relayer/core"
"github.com/hyperledger-labs/yui-relayer/helpers"
"github.com/spf13/cobra"
"github.com/cosmos/gogoproto/jsonpb"
)

// queryCmd represents the chain command
Expand All @@ -33,6 +34,7 @@ func queryCmd(ctx *config.Context) *cobra.Command {
queryClientCmd(ctx),
queryConnection(ctx),
queryChannel(ctx),
queryChannelUpgrade(ctx),
)

return cmd
Expand Down Expand Up @@ -69,7 +71,7 @@ func queryClientCmd(ctx *config.Context) *cobra.Command {
}
marshaler := jsonpb.Marshaler{}
if json, err := marshaler.MarshalToString(cs); err != nil {
fmt.Println(cs.String())
return err
} else {
fmt.Println(json)
}
Expand Down Expand Up @@ -101,13 +103,13 @@ func queryConnection(ctx *config.Context) *cobra.Command {
return err
}
queryHeight := clienttypes.NewHeight(latestHeight.GetRevisionNumber(), uint64(height))
res, err := c.QueryConnection(core.NewQueryContext(context.TODO(), queryHeight))
res, err := c.QueryConnection(core.NewQueryContext(context.TODO(), queryHeight), c.Path().ConnectionID)
if err != nil {
return err
}
marshaler := jsonpb.Marshaler{}
if json, err := marshaler.MarshalToString(res.Connection); err != nil {
fmt.Println(res.Connection.String())
return err
} else {
fmt.Println(json)
}
Expand All @@ -121,7 +123,7 @@ func queryConnection(ctx *config.Context) *cobra.Command {
func queryChannel(ctx *config.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "channel [path-name] [chain-id]",
Short: "Query the connection state for the given connection id",
Short: "Query the channel state for the given connection id",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
chains, _, _, err := ctx.Config.ChainsFromPath(args[0])
Expand All @@ -143,9 +145,51 @@ func queryChannel(ctx *config.Context) *cobra.Command {
if err != nil {
return err
}

marshaler := jsonpb.Marshaler{}
if json, err := marshaler.MarshalToString(res.Channel); err != nil {
fmt.Println(res.Channel.String())
return err
} else {
fmt.Println(json)
}
return nil
},
}

return heightFlag(cmd)
}

func queryChannelUpgrade(ctx *config.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "channel-upgrade [path-name] [chain-id]",
Short: "Query the channel upgrade state for the given channel id",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
chains, _, _, err := ctx.Config.ChainsFromPath(args[0])
if err != nil {
return err
}
c := chains[args[1]]

height, err := cmd.Flags().GetUint64(flags.FlagHeight)
if err != nil {
return err
}
latestHeight, err := c.LatestHeight()
if err != nil {
return err
}
queryHeight := clienttypes.NewHeight(latestHeight.GetRevisionNumber(), uint64(height))
res, err := c.QueryChannelUpgrade(core.NewQueryContext(context.TODO(), queryHeight))
if err != nil {
return err
} else if res == nil {
res = &chantypes.QueryUpgradeResponse{}
}

marshaler := jsonpb.Marshaler{}
if json, err := marshaler.MarshalToString(&res.Upgrade); err != nil {
return err
} else {
fmt.Println(json)
}
Expand Down
Loading
Loading