Skip to content

Commit

Permalink
packet acknowledgment filtering (#375)
Browse files Browse the repository at this point in the history
* adding packet commitments to QueryPacketAcknowledgementsRequest for filtering

* adding testcase for filtered packet ack query

* adding changelog entry for packet ack filtering

* updating packet sequences type to repeated uint64

* updating to query specific packet acks outside bounds of paginated req

* updating changelog field naming, removing redundant pagination in query test

* continue in favour of returning an error on query PacketAcknowledgements

* updating to return empty array of acks if none of the provided commitments are found

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
  • Loading branch information
damiannolan and colin-axner committed Sep 7, 2021
1 parent 90ce97e commit 760d15a
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 131 deletions.
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

### 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

0 comments on commit 760d15a

Please sign in to comment.