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

Track used gas in channel and packet transactions #22

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions db/migrations/1724433908520-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = class Data1724433908520 {
name = 'Data1724433908520'

async up(db) {
await db.query(`ALTER TABLE "channel_open_init" ADD "gas_used" numeric`)
await db.query(`ALTER TABLE "channel_open_try" ADD "gas_used" numeric`)
await db.query(`ALTER TABLE "channel_open_ack" ADD "gas_used" numeric`)
await db.query(`ALTER TABLE "channel_open_confirm" ADD "gas_used" numeric`)
await db.query(`ALTER TABLE "close_ibc_channel" ADD "gas_used" numeric`)
await db.query(`ALTER TABLE "send_packet" ADD "gas_used" numeric`)
await db.query(`ALTER TABLE "recv_packet" ADD "gas_used" numeric`)
await db.query(`ALTER TABLE "write_ack_packet" ADD "gas_used" numeric`)
await db.query(`ALTER TABLE "acknowledgement" ADD "gas_used" numeric`)
await db.query(`ALTER TABLE "timeout" ADD "gas_used" numeric`)
await db.query(`ALTER TABLE "write_timeout_packet" ADD "gas_used" numeric`)
}

async down(db) {
await db.query(`ALTER TABLE "channel_open_init" DROP COLUMN "gas_used"`)
await db.query(`ALTER TABLE "channel_open_try" DROP COLUMN "gas_used"`)
await db.query(`ALTER TABLE "channel_open_ack" DROP COLUMN "gas_used"`)
await db.query(`ALTER TABLE "channel_open_confirm" DROP COLUMN "gas_used"`)
await db.query(`ALTER TABLE "close_ibc_channel" DROP COLUMN "gas_used"`)
await db.query(`ALTER TABLE "send_packet" DROP COLUMN "gas_used"`)
await db.query(`ALTER TABLE "recv_packet" DROP COLUMN "gas_used"`)
await db.query(`ALTER TABLE "write_ack_packet" DROP COLUMN "gas_used"`)
await db.query(`ALTER TABLE "acknowledgement" DROP COLUMN "gas_used"`)
await db.query(`ALTER TABLE "timeout" DROP COLUMN "gas_used"`)
await db.query(`ALTER TABLE "write_timeout_packet" DROP COLUMN "gas_used"`)
}
}
11 changes: 11 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type SendPacket @entity {
packetDataSender: String @index
uchEventSender: String @index
gas: BigInt!
gasUsed: BigInt
gasPrice: BigInt
maxFeePerGas: BigInt
maxPriorityFeePerGas: BigInt
Expand Down Expand Up @@ -72,6 +73,7 @@ type RecvPacket @entity {
transactionHash: String! @index
chainId: Int! @index
gas: BigInt!
gasUsed: BigInt
gasPrice: BigInt
maxFeePerGas: BigInt
maxPriorityFeePerGas: BigInt
Expand All @@ -94,6 +96,7 @@ type WriteAckPacket @entity {
transactionHash: String! @index
chainId: Int! @index
gas: BigInt!
gasUsed: BigInt
gasPrice: BigInt
maxFeePerGas: BigInt
maxPriorityFeePerGas: BigInt
Expand All @@ -117,6 +120,7 @@ type Acknowledgement @entity {
transactionHash: String! @index
chainId: Int! @index
gas: BigInt!
gasUsed: BigInt
gasPrice: BigInt
maxFeePerGas: BigInt
maxPriorityFeePerGas: BigInt
Expand All @@ -137,6 +141,7 @@ type Timeout @entity {
transactionHash: String! @index
chainId: Int! @index
gas: BigInt!
gasUsed: BigInt
gasPrice: BigInt
maxFeePerGas: BigInt
maxPriorityFeePerGas: BigInt
Expand All @@ -159,6 +164,7 @@ type WriteTimeoutPacket @entity {
transactionHash: String! @index
chainId: Int! @index
gas: BigInt!
gasUsed: BigInt
gasPrice: BigInt
maxFeePerGas: BigInt
maxPriorityFeePerGas: BigInt
Expand Down Expand Up @@ -227,6 +233,7 @@ type ChannelOpenInit @entity {
chainId: Int! @index
from: String!
gas: BigInt!
gasUsed: BigInt
gasPrice: BigInt
maxFeePerGas: BigInt
maxPriorityFeePerGas: BigInt
Expand Down Expand Up @@ -256,6 +263,7 @@ type ChannelOpenTry @entity {
transactionHash: String! @index
chainId: Int! @index
gas: BigInt!
gasUsed: BigInt
maxFeePerGas: BigInt
maxPriorityFeePerGas: BigInt
from: String!
Expand All @@ -279,6 +287,7 @@ type ChannelOpenAck @entity {
transactionHash: String! @index
chainId: Int! @index
gas: BigInt!
gasUsed: BigInt
gasPrice: BigInt
maxFeePerGas: BigInt
maxPriorityFeePerGas: BigInt
Expand All @@ -303,6 +312,7 @@ type ChannelOpenConfirm @entity {
transactionHash: String! @index
chainId: Int! @index
gas: BigInt!
gasUsed: BigInt
gasPrice: BigInt
maxFeePerGas: BigInt
maxPriorityFeePerGas: BigInt
Expand All @@ -325,6 +335,7 @@ type CloseIbcChannel @entity {
transactionHash: String! @index
chainId: Int! @index
gas: BigInt!
gasUsed: BigInt
gasPrice: BigInt
maxFeePerGas: BigInt
maxPriorityFeePerGas: BigInt
Expand Down
4 changes: 4 additions & 0 deletions src/handlers/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function handleChannelOpenInit(portPrefix: string, block: Block, log: Log
chainId: log.transaction?.chainId || 0,
from: log.transaction?.from || '',
gas: log.transaction?.gas,
gasUsed: log.transaction?.gasUsed,
maxFeePerGas: log.transaction?.maxFeePerGas,
maxPriorityFeePerGas: log.transaction?.maxPriorityFeePerGas,
});
Expand Down Expand Up @@ -74,6 +75,7 @@ export function handleChannelOpenTry(block: Block, log: Log): ChannelOpenTry {
chainId: log.transaction?.chainId || 0,
from: log.transaction?.from || '',
gas: log.transaction?.gas,
gasUsed: log.transaction?.gasUsed,
maxFeePerGas: log.transaction?.maxFeePerGas,
maxPriorityFeePerGas: log.transaction?.maxPriorityFeePerGas,
})
Expand Down Expand Up @@ -101,6 +103,7 @@ export function handleChannelOpenAck(block: Block, log: Log): ChannelOpenAck {
chainId: log.transaction?.chainId || 0,
from: log.transaction?.from || '',
gas: log.transaction?.gas,
gasUsed: log.transaction?.gasUsed,
maxFeePerGas: log.transaction?.maxFeePerGas,
maxPriorityFeePerGas: log.transaction?.maxPriorityFeePerGas
})
Expand All @@ -127,6 +130,7 @@ export function handleChannelOpenConfirm(block: Block, log: Log): ChannelOpenCon
chainId: log.transaction?.chainId || 0,
from: log.transaction?.from || '',
gas: log.transaction?.gas,
gasUsed: log.transaction?.gasUsed,
maxFeePerGas: log.transaction?.maxFeePerGas,
maxPriorityFeePerGas: log.transaction?.maxPriorityFeePerGas
})
Expand Down
12 changes: 12 additions & 0 deletions src/handlers/packets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function handleSendPacket(block: Block, log: Log, portPrefix: string, uch
let sourceChannelId = ethers.decodeBytes32String(event.sourceChannelId)
const packetHash = ethers.sha256(event.packet)
const gas = BigInt(log.transaction!.gas)
const gasUsed = BigInt(log.transaction!.gasUsed)
const gasPrice = log.transaction?.gasPrice ? BigInt(log.transaction.gasPrice) : null
const maxFeePerGas = log.transaction?.maxFeePerGas ? BigInt(log.transaction.maxFeePerGas) : null
const maxPriorityFeePerGas = log.transaction?.maxPriorityFeePerGas ? BigInt(log.transaction.maxPriorityFeePerGas) : null
Expand All @@ -38,6 +39,7 @@ export function handleSendPacket(block: Block, log: Log, portPrefix: string, uch
uchEventSender,
packetDataSender,
gas,
gasUsed,
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
Expand All @@ -51,6 +53,7 @@ export function handleRecvPacket(block: Block, log: Log, portPrefix: string): mo
let event = dispatcher.events.RecvPacket.decode(log)
let destChannelId = ethers.decodeBytes32String(event.destChannelId)
const gas = BigInt(log.transaction!.gas)
const gasUsed = BigInt(log.transaction!.gasUsed)
const gasPrice = log.transaction?.gasPrice ? BigInt(log.transaction.gasPrice) : null
const maxFeePerGas = log.transaction?.maxFeePerGas ? BigInt(log.transaction.maxFeePerGas) : null
const maxPriorityFeePerGas = log.transaction?.maxPriorityFeePerGas ? BigInt(log.transaction.maxPriorityFeePerGas) : null
Expand All @@ -68,6 +71,7 @@ export function handleRecvPacket(block: Block, log: Log, portPrefix: string): mo
transactionHash: log.transactionHash,
chainId: log.transaction?.chainId || 0,
gas,
gasUsed,
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
Expand All @@ -80,6 +84,7 @@ export function handleWriteAckPacket(block: Block, log: Log, portPrefix: string)
let writerChannelId = ethers.decodeBytes32String(event.writerChannelId);
const packetHash = ethers.sha256(event.ackPacket.data);
const gas = BigInt(log.transaction!.gas)
const gasUsed = BigInt(log.transaction!.gasUsed)
const gasPrice = log.transaction?.gasPrice ? BigInt(log.transaction.gasPrice) : null
const maxFeePerGas = log.transaction?.maxFeePerGas ? BigInt(log.transaction.maxFeePerGas) : null
const maxPriorityFeePerGas = log.transaction?.maxPriorityFeePerGas ? BigInt(log.transaction.maxPriorityFeePerGas) : null
Expand All @@ -99,6 +104,7 @@ export function handleWriteAckPacket(block: Block, log: Log, portPrefix: string)
transactionHash: log.transactionHash,
chainId: log.transaction?.chainId || 0,
gas,
gasUsed,
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
Expand All @@ -109,6 +115,7 @@ export function handleWriteAckPacket(block: Block, log: Log, portPrefix: string)
export function handleAcknowledgement(block: Block, log: Log, portPrefix: string): models.Acknowledgement {
let event = dispatcher.events.Acknowledgement.decode(log);
const gas = BigInt(log.transaction!.gas)
const gasUsed = BigInt(log.transaction!.gasUsed)
const gasPrice = log.transaction?.gasPrice ? BigInt(log.transaction.gasPrice) : null
const maxFeePerGas = log.transaction?.maxFeePerGas ? BigInt(log.transaction.maxFeePerGas) : null
const maxPriorityFeePerGas = log.transaction?.maxPriorityFeePerGas ? BigInt(log.transaction.maxPriorityFeePerGas) : null
Expand All @@ -126,6 +133,7 @@ export function handleAcknowledgement(block: Block, log: Log, portPrefix: string
transactionHash: log.transactionHash,
chainId: log.transaction?.chainId || 0,
gas,
gasUsed,
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
Expand All @@ -137,6 +145,7 @@ export function handleTimeout(block: Block, log: Log, portPrefix: string): model
let event = dispatcher.events.Timeout.decode(log);
let sourceChannelId = ethers.decodeBytes32String(event.sourceChannelId);
const gas = BigInt(log.transaction!.gas)
const gasUsed = BigInt(log.transaction!.gasUsed)
const gasPrice = log.transaction?.gasPrice ? BigInt(log.transaction.gasPrice) : null
const maxFeePerGas = log.transaction?.maxFeePerGas ? BigInt(log.transaction.maxFeePerGas) : null
const maxPriorityFeePerGas = log.transaction?.maxPriorityFeePerGas ? BigInt(log.transaction.maxPriorityFeePerGas) : null
Expand All @@ -154,6 +163,7 @@ export function handleTimeout(block: Block, log: Log, portPrefix: string): model
transactionHash: log.transactionHash,
chainId: log.transaction?.chainId || 0,
gas,
gasUsed,
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
Expand All @@ -165,6 +175,7 @@ export function handleWriteTimeoutPacket(block: Block, log: Log, portPrefix: str
let event = dispatcher.events.WriteTimeoutPacket.decode(log);
let writerChannelId = ethers.decodeBytes32String(event.writerChannelId);
const gas = BigInt(log.transaction!.gas)
const gasUsed = BigInt(log.transaction!.gasUsed)
const gasPrice = log.transaction?.gasPrice ? BigInt(log.transaction.gasPrice) : null
const maxFeePerGas = log.transaction?.maxFeePerGas ? BigInt(log.transaction.maxFeePerGas) : null
const maxPriorityFeePerGas = log.transaction?.maxPriorityFeePerGas ? BigInt(log.transaction.maxPriorityFeePerGas) : null
Expand All @@ -185,6 +196,7 @@ export function handleWriteTimeoutPacket(block: Block, log: Log, portPrefix: str
transactionHash: log.transactionHash,
chainId: log.transaction?.chainId || 0,
gas,
gasUsed,
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/acknowledgement.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export class Acknowledgement {
@BigIntColumn_({nullable: false})
gas!: bigint

@BigIntColumn_({nullable: true})
gasUsed!: bigint | undefined | null

@BigIntColumn_({nullable: true})
gasPrice!: bigint | undefined | null

Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/channelOpenAck.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export class ChannelOpenAck {
@BigIntColumn_({nullable: false})
gas!: bigint

@BigIntColumn_({nullable: true})
gasUsed!: bigint | undefined | null

@BigIntColumn_({nullable: true})
gasPrice!: bigint | undefined | null

Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/channelOpenConfirm.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export class ChannelOpenConfirm {
@BigIntColumn_({nullable: false})
gas!: bigint

@BigIntColumn_({nullable: true})
gasUsed!: bigint | undefined | null

@BigIntColumn_({nullable: true})
gasPrice!: bigint | undefined | null

Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/channelOpenInit.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export class ChannelOpenInit {
@BigIntColumn_({nullable: false})
gas!: bigint

@BigIntColumn_({nullable: true})
gasUsed!: bigint | undefined | null

@BigIntColumn_({nullable: true})
gasPrice!: bigint | undefined | null

Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/channelOpenTry.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export class ChannelOpenTry {
@BigIntColumn_({nullable: false})
gas!: bigint

@BigIntColumn_({nullable: true})
gasUsed!: bigint | undefined | null

@BigIntColumn_({nullable: true})
maxFeePerGas!: bigint | undefined | null

Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/closeIbcChannel.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export class CloseIbcChannel {
@BigIntColumn_({nullable: false})
gas!: bigint

@BigIntColumn_({nullable: true})
gasUsed!: bigint | undefined | null

@BigIntColumn_({nullable: true})
gasPrice!: bigint | undefined | null

Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/recvPacket.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export class RecvPacket {
@BigIntColumn_({nullable: false})
gas!: bigint

@BigIntColumn_({nullable: true})
gasUsed!: bigint | undefined | null

@BigIntColumn_({nullable: true})
gasPrice!: bigint | undefined | null

Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/sendPacket.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export class SendPacket {
@BigIntColumn_({nullable: false})
gas!: bigint

@BigIntColumn_({nullable: true})
gasUsed!: bigint | undefined | null

@BigIntColumn_({nullable: true})
gasPrice!: bigint | undefined | null

Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/timeout.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export class Timeout {
@BigIntColumn_({nullable: false})
gas!: bigint

@BigIntColumn_({nullable: true})
gasUsed!: bigint | undefined | null

@BigIntColumn_({nullable: true})
gasPrice!: bigint | undefined | null

Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/writeAckPacket.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export class WriteAckPacket {
@BigIntColumn_({nullable: false})
gas!: bigint

@BigIntColumn_({nullable: true})
gasUsed!: bigint | undefined | null

@BigIntColumn_({nullable: true})
gasPrice!: bigint | undefined | null

Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/writeTimeoutPacket.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export class WriteTimeoutPacket {
@BigIntColumn_({nullable: false})
gas!: bigint

@BigIntColumn_({nullable: true})
gasUsed!: bigint | undefined | null

@BigIntColumn_({nullable: true})
gasPrice!: bigint | undefined | null

Expand Down
Loading