Skip to content

Commit

Permalink
Merge pull request #57 from penumbra-zone/ibc-channel-height
Browse files Browse the repository at this point in the history
chore: added missing counterparty height to ibc channel page/endpoint.
  • Loading branch information
ejmg authored Jan 17, 2024
2 parents 4c47800 + 910a4dd commit 6908320
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
57 changes: 56 additions & 1 deletion src/app/api/ibc/channel/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,56 @@ export async function GET(req: NextRequest) {

console.log("Successfully queried client_id for channel.", clientId);

// WARNING: This query does not check/enforce the fact that this update used the channel.
// TODO: Check for whether this event is associated with the correct channel.
// update_client event types do not include this information, so I'd hope/assume that a related
// transaction or block will have that associated data? If so, how do I find it?
const clientHeight = await db.events.findFirstOrThrow({
select: {
attributes: {
select: {
key: true,
value: true,
},
where: {
key: {
equals: "consensus_height",
},
},
},
},
where: {
AND: [
{
type: {
equals: "update_client",
},
attributes: {
some: {
AND: [
{
key: {
equals: "client_id",
},
},
{
value: {
equals: clientId.attributes[0].value,
},
},
],

},
},
},
],
},
orderBy: {
block_id: "desc",
},
});

console.log("Successfully queried for latest client height.", clientHeight);

// This will return the block id for the latest client_update event type for a given client_id.
const transactions = await db.events.findMany({
Expand Down Expand Up @@ -111,7 +161,12 @@ export async function GET(req: NextRequest) {

console.log("Successfully queried recent transactions for channel.", recentTransactions);

return new Response(JSON.stringify({ "connectionId": connectionId.attributes[0].value, "clientId": clientId.attributes[0].value, recentTransactions}));
return new Response(JSON.stringify({
"connectionId": connectionId.attributes[0].value,
"clientId": clientId.attributes[0].value,
"consensusHeight": clientHeight.attributes[0].value,
recentTransactions,
}));

} catch (error) {
console.error("GET request failed.", error);
Expand Down
2 changes: 2 additions & 0 deletions src/app/api/ibc/channels/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export async function GET(_req: NextRequest) {
console.log(channelsQuery[0].attributes);

console.log("Searching for connections associated with IBC Channels...");
// TODO: I currently don't know of a good way to find the last known consensus height for every channel's counterparty chain.
// See note in /api/ibc/channels/route.ts#L85
const connections = await db.events.findMany({
select: {
attributes: {
Expand Down
6 changes: 5 additions & 1 deletion src/app/ibc/channel/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Page : FC<PageProps> = ({ params }) => {
console.log(`Fetching: GET /api/ibc/channel/${channelId}`);
const { data } = await axios.get(`/api/ibc/channel?q=${channelId}`);
console.log("Fetched result:", data);
return data as { connectionId: string, clientId: string, recentTransactions: Array<{hash: string}>};
return data as { connectionId: string, clientId: string, consensusHeight: string, recentTransactions: Array<{hash: string}>};
// TODO: enforce validation
// const result = IbcChannelValidator.safeParse(data);
},
Expand Down Expand Up @@ -53,6 +53,10 @@ const Page : FC<PageProps> = ({ params }) => {
<p className="w-1/6">Client ID</p>
<Link href={`/ibc/client/${data.clientId}`} className="underline"><pre>{data.clientId}</pre></Link>
</div>
<div className="flex justify-start w-full">
<p className="w-1/6">Counterparty Height</p>
<pre>{data.consensusHeight}</pre>
</div>
<div className="flex justify-start w-full">
<p className="w-1/6">Connection IDs</p>
<Link href={`/ibc/connection/${data.connectionId}`} className="underline"><pre>{data.connectionId}</pre></Link>
Expand Down

0 comments on commit 6908320

Please sign in to comment.