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

packet acknowledgment filtering #375

Merged
merged 9 commits into from
Sep 7, 2021
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (24-host) [#\344](https://github.com/cosmos/ibc-go/pull/344) Increase port identifier limit to 128 characters.

### Improvements
* [\#373](https://github.com/cosmos/ibc-go/pull/375) Added optional field `PacketCommitmentSequences` to `QueryPacketAcknowledgementsRequest` to provide filtering of packet acknowledgements

### Features
* [\#372](https://github.com/cosmos/ibc-go/pull/372) New CLI command `query ibc client status <client id>` to get the current activity status of a client

## [v1.0.0](https://github.com/cosmos/ibc-go/releases/tag/v1.0.0) - 2021-08-10

Expand Down Expand Up @@ -102,7 +107,6 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Features

* [\#198](https://github.com/cosmos/ibc-go/pull/198) New CLI command `query ibc-transfer escrow-address <port> <channel id>` to get the escrow address for a channel; can be used to then query balance of escrowed tokens
* [\#372](https://github.com/cosmos/ibc-go/pull/372) New CLI command `query ibc client status <client id>` to get the current activity status of a client
damiannolan marked this conversation as resolved.
Show resolved Hide resolved

### Client Breaking Changes

Expand Down
1 change: 1 addition & 0 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,7 @@ Query/QueryPacketCommitments RPC method
| `port_id` | [string](#string) | | port unique identifier |
| `channel_id` | [string](#string) | | channel unique identifier |
| `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination request |
| `packet_commitment_sequences` | [uint64](#uint64) | repeated | list of packet sequences |



Expand Down
22 changes: 22 additions & 0 deletions modules/core/04-channel/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,27 @@ func (q Keeper) PacketAcknowledgements(c context.Context, req *types.QueryPacket
acks := []*types.PacketState{}
store := prefix.NewStore(ctx.KVStore(q.storeKey), []byte(host.PacketAcknowledgementPrefixPath(req.PortId, req.ChannelId)))

// if a list of packet sequences is provided then query for each specific ack and return a list <= len(req.PacketCommitmentSequences)
// otherwise, maintain previous behaviour and perform paginated query
for _, seq := range req.PacketCommitmentSequences {
acknowledgementBz, found := q.GetPacketAcknowledgement(ctx, req.PortId, req.ChannelId, seq)
if !found || len(acknowledgementBz) == 0 {
continue
}

ack := types.NewPacketState(req.PortId, req.ChannelId, seq, acknowledgementBz)
acks = append(acks, &ack)
}

if len(req.PacketCommitmentSequences) > 0 {
selfHeight := clienttypes.GetSelfHeight(ctx)
return &types.QueryPacketAcknowledgementsResponse{
Acknowledgements: acks,
Pagination: nil,
Height: selfHeight,
}, nil
}

pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error {
keySplit := strings.Split(string(key), "/")

Expand All @@ -337,6 +358,7 @@ func (q Keeper) PacketAcknowledgements(c context.Context, req *types.QueryPacket

ack := types.NewPacketState(req.PortId, req.ChannelId, sequence, value)
acks = append(acks, &ack)

return nil
})

Expand Down
27 changes: 27 additions & 0 deletions modules/core/04-channel/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,33 @@ func (suite *KeeperTestSuite) TestQueryPacketAcknowledgements() {
},
true,
},
{
"success, filtered res",
func() {
path := ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)

var commitments []uint64

for i := uint64(0); i < 100; i++ {
ack := types.NewPacketState(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, i, []byte(fmt.Sprintf("hash_%d", i)))
suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetPacketAcknowledgement(suite.chainA.GetContext(), ack.PortId, ack.ChannelId, ack.Sequence, ack.Data)

if i < 10 { // populate the store with 100 and query for 10 specific acks
expAcknowledgements = append(expAcknowledgements, &ack)
commitments = append(commitments, ack.Sequence)
}
}

req = &types.QueryPacketAcknowledgementsRequest{
PortId: path.EndpointA.ChannelConfig.PortID,
ChannelId: path.EndpointA.ChannelID,
PacketCommitmentSequences: commitments,
Pagination: nil,
}
},
true,
},
{
"success",
func() {
Expand Down
Loading