Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Added the handling of begin and end block events #189

Merged
merged 47 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d671209
Added the handling of begin and end block events
RiccardoM May 25, 2021
17b5fb5
Run yarn fix
RiccardoM May 25, 2021
ec21380
Updated chain requirements to have Cosmos v0.42.4 and PR 9081 merged
RiccardoM May 25, 2021
1aefddf
Added changeset entry
RiccardoM May 25, 2021
a50da75
Add home option to ics20 command
Jun 9, 2021
2a955ea
Add changeset
Jun 10, 2021
c3f0e81
Merge pull request #191 from iov-one/add-home-to-ics20
ethanfrey Jun 10, 2021
dcabf3d
musselnet -> oysternet, remove relayer testnets
ethanfrey Jun 21, 2021
a4035b8
Add nyancat testnet
ethanfrey Jun 21, 2021
27de19c
Update README using nyancat
ethanfrey Jun 21, 2021
6f572b5
Test README demo with nyancat
ethanfrey Jun 21, 2021
a4c9a31
Add changelog entry
ethanfrey Jun 21, 2021
621c4ed
Prettify README
ethanfrey Jun 21, 2021
20906ca
[skip ci] Point to non-pruning node on nyancat
ethanfrey Jun 21, 2021
72cc9fd
Merge pull request #193 from confio/update-registry-testnets
ethanfrey Jun 21, 2021
f82ab96
Update blockchain versions
ethanfrey Jun 21, 2021
9033648
Bump cosmjs to 0.25.4
ethanfrey Jun 21, 2021
b8ab8f4
Use standard signing client setup in balances
ethanfrey Jun 21, 2021
ae2ebca
Use much faster polling for binary tests
ethanfrey Jun 21, 2021
9e4a5c3
Add changeset
ethanfrey Jun 21, 2021
eb30805
Merge pull request #194 from confio/update-deps
ethanfrey Jun 21, 2021
ef52b7e
Rough draft cw20 upload
ethanfrey Jun 21, 2021
2a48bf2
Upload script for cw20-base and cw20-ics20
ethanfrey Jun 21, 2021
4401e68
Add contract upload to CI
ethanfrey Jun 21, 2021
1b15924
Prettier js scripts
ethanfrey Jun 21, 2021
0045dab
Instantiate contracts in unit test
ethanfrey Jun 21, 2021
efc8ba3
Test channel handshake with ics20 contract
ethanfrey Jun 21, 2021
ef2895e
Send packet with contract
ethanfrey Jun 21, 2021
e74a38f
Return token over channel
ethanfrey Jun 21, 2021
95b61ca
Expect error on relaying native token over channel
ethanfrey Jun 21, 2021
71d5a36
Refactor and remove need for init script
ethanfrey Jun 21, 2021
752a80a
Merge pull request #195 from confio/use-cw20-ics20-contract
ethanfrey Jun 21, 2021
492f554
Bump to v0.1.6
ethanfrey Jun 21, 2021
25ece0b
add iris installation
chengwenxi Jun 22, 2021
a9fba16
Minor cleanup for CI
ethanfrey Jun 22, 2021
cfbf4cf
Merge pull request #196 from chengwenxi/vincent-iris
ethanfrey Jun 22, 2021
d5f0ccd
Updated CosmJS to 0.25.5
RiccardoM Jun 24, 2021
e88fb01
Added the handling of begin and end block events
RiccardoM May 25, 2021
004ee47
Run yarn fix
RiccardoM May 25, 2021
36afad0
Updated chain requirements to have Cosmos v0.42.4 and PR 9081 merged
RiccardoM May 25, 2021
b124983
Added changeset entry
RiccardoM May 25, 2021
b382422
Updated CosmJS to 0.25.5
RiccardoM Jun 24, 2021
5c5252e
Updated CosmJS to 0.25.5
RiccardoM Jun 24, 2021
f14a333
Merge remote-tracking branch 'origin/riccardo/block-results-events' i…
RiccardoM Jun 24, 2021
ade449b
Reverted custom @cosmjs/tendermint-rpc dependency
RiccardoM Jun 24, 2021
5343358
Run yarn fix:prettier
RiccardoM Jun 24, 2021
a502458
Updated simapp environment
RiccardoM Jun 24, 2021
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
5 changes: 5 additions & 0 deletions .changeset/long-hats-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@confio/relayer': patch
---

Added the handling of begin and end block events
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ The `GET /metrics` endpoint will be exposed by default on port `8080`, which you

## Chain Requirements

The blockchain must be based on Cosmos SDK `v0.41.1+`. In particular it must have
[PR 8458](https://github.com/cosmos/cosmos-sdk/pull/8458) merged (if you are using a fork)
in order for the relayer to work properly. `ibc-setup` should work on `v0.40.0+`
The blockchain must be based on Cosmos SDK `v0.42.4+`. In particular it must have
[PR 8458](https://github.com/cosmos/cosmos-sdk/pull/8458) and [PR 9081](https://github.com/cosmos/cosmos-sdk/pull/9081)
merged (if you are using a fork) in order for the relayer to work properly. `ibc-setup` should work on `v0.40.0+`

The chain must have a large value for `staking.params.historical_entries` (often set in genesis).
The default is "10000" and this should work with "1000", but no relayer will work if it is set to 0.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@cosmjs/proto-signing": "0.25.3",
"@cosmjs/stargate": "0.25.3",
"@cosmjs/stream": "0.25.3",
"@cosmjs/tendermint-rpc": "0.25.3",
"@cosmjs/tendermint-rpc": "https://gitpkg.now.sh/desmos-labs/cosmjs/packages/tendermint-rpc?riccardo/add-block-search",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, very nice. I never knew how to import non-tagged releases from lerna monorepos

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. But where is the TS -> JS compiled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webmaster128 I think you can read more here. It should be compiled by them

"@cosmjs/utils": "0.25.3",
"ajv": "7.1.1",
"axios": "0.21.1",
Expand Down
53 changes: 50 additions & 3 deletions src/lib/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { CommitResponse } from '@cosmjs/tendermint-rpc';
import { Packet } from '../codec/ibc/core/channel/v1/channel';

import { IbcClient } from './ibcclient';
import { Ack, parseAcksFromLogs, parsePacketsFromLogs } from './utils';
import {
Ack,
parseAcksFromLogs,
parsePacketsFromBlockResult,
parsePacketsFromLogs,
} from './utils';

export interface PacketWithMetadata {
packet: Packet;
Expand Down Expand Up @@ -54,8 +59,35 @@ export class Endpoint {
return this.client.getCommit();
}

// returns all packets (auto-paginates, so be careful about not setting a minHeight)
public async querySentPackets({
private async getPacketsFromBlockEvents({
minHeight,
maxHeight,
}: QueryOpts = {}): Promise<PacketWithMetadata[]> {
let query = `send_packet.packet_connection='${this.connectionID}'`;
if (minHeight) {
query = `${query} AND block.height>=${minHeight}`;
}
if (maxHeight) {
query = `${query} AND block.height<=${maxHeight}`;
}

const search = await this.client.tm.blockSearchAll({ query });
const resultsNested = await Promise.all(
search.blocks.map(async ({ block }) => {
const height = block.header.height;
const result = await this.client.tm.blockResults(height);
return parsePacketsFromBlockResult(result).map((packet) => ({
packet,
height,
sender: '',
}));
})
);

return ([] as PacketWithMetadata[]).concat(...resultsNested);
}

private async getPacketsFromTxs({
minHeight,
maxHeight,
}: QueryOpts = {}): Promise<PacketWithMetadata[]> {
Expand Down Expand Up @@ -92,6 +124,21 @@ export class Endpoint {
return ([] as PacketWithMetadata[]).concat(...resultsNested);
}

// returns all packets (auto-paginates, so be careful about not setting a minHeight)
public async querySentPackets({
minHeight,
maxHeight,
}: QueryOpts = {}): Promise<PacketWithMetadata[]> {
const txsPackets = await this.getPacketsFromTxs({ minHeight, maxHeight });
const eventsPackets = await this.getPacketsFromBlockEvents({
minHeight,
maxHeight,
});
return ([] as PacketWithMetadata[])
.concat(...txsPackets)
.concat(...eventsPackets);
}

// returns all acks (auto-paginates, so be careful about not setting a minHeight)
public async queryWrittenAcks({
minHeight,
Expand Down
24 changes: 24 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { fromUtf8, toHex, toUtf8 } from '@cosmjs/encoding';
import { BroadcastTxFailure, Coin, logs, StdFee } from '@cosmjs/stargate';
const { parseEvent } = logs;
import {
BlockResultsResponse,
ReadonlyDateWithNanoseconds,
Header as RpcHeader,
ValidatorPubkey as RpcPubKey,
Expand Down Expand Up @@ -193,6 +195,28 @@ interface ParsedEvent {
readonly attributes: readonly ParsedAttribute[];
}

function decodeBase64(value: Uint8Array): string {
return Buffer.from(value).toString('binary');
}

export function parsePacketsFromBlockResult(
result: BlockResultsResponse
): Packet[] {
const allEvents: ParsedEvent[] = result.beginBlockEvents
.concat(...result.endBlockEvents)
.filter(({ type }) => type === 'send_packet')
.map(({ type, attributes }) => ({
type,
attributes: attributes.map(({ key, value }) => ({
key: decodeBase64(key),
value: decodeBase64(value),
})),
}));

const flatEvents = ([] as ParsedEvent[]).concat(allEvents.map(parseEvent));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, nice you do parseEvents to do all the validity checks

return flatEvents.map(parsePacket);
}

export function parsePacketsFromLogs(logs: readonly logs.Log[]): Packet[] {
// grab all send_packet events from the logs
const allEvents: ParsedEvent[][] = logs.map((log) =>
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,20 @@
readonly-date "^1.0.0"
xstream "^11.14.0"

"@cosmjs/tendermint-rpc@https://gitpkg.now.sh/desmos-labs/cosmjs/packages/tendermint-rpc?riccardo/add-block-search":
version "0.25.3"
resolved "https://gitpkg.now.sh/desmos-labs/cosmjs/packages/tendermint-rpc?riccardo/add-block-search#03c68a35639b17d50646cc62c2cf9644cfdfd46d"
dependencies:
"@cosmjs/crypto" "^0.25.3"
"@cosmjs/encoding" "^0.25.3"
"@cosmjs/json-rpc" "^0.25.3"
"@cosmjs/math" "^0.25.3"
"@cosmjs/socket" "^0.25.3"
"@cosmjs/stream" "^0.25.3"
axios "^0.21.1"
readonly-date "^1.0.0"
xstream "^11.14.0"

"@cosmjs/utils@0.25.3", "@cosmjs/utils@^0.25.3":
version "0.25.3"
resolved "https://registry.yarnpkg.com/@cosmjs/utils/-/utils-0.25.3.tgz#e74a85d0be74ef6a9cb3efa45fd219e459cdaa03"
Expand Down