diff --git a/src/db/constants.ts b/src/db/constants.ts index 12681f5..373d562 100644 --- a/src/db/constants.ts +++ b/src/db/constants.ts @@ -1,6 +1,3 @@ // constants export const U64_MAX = 0xffffffffffffffffn - -// db path -export const DB_PATH = './.db/main.db' diff --git a/src/db/controller/channel.ts b/src/db/controller/channel.ts index b252208..90c7fbf 100644 --- a/src/db/controller/channel.ts +++ b/src/db/controller/channel.ts @@ -44,9 +44,7 @@ export class ChannelController { ) break case 'channel_close_confirm': - feedFns.push( - await this.feedChannelCloseConfirmEvent(rest, chainId, event) - ) + feedFns.push(this.feedChannelCloseConfirmEvent(rest, chainId, event)) break } } @@ -308,11 +306,11 @@ export class ChannelController { } } - private static async feedChannelCloseConfirmEvent( + private static feedChannelCloseConfirmEvent( _rest: RESTClient, chainId: string, event: ChannelOpenCloseEvent - ): Promise<() => void> { + ): () => void { return () => { del(DB, this.tableName, [ { diff --git a/src/db/controller/packet.ts b/src/db/controller/packet.ts index 3001992..e0eaa86 100644 --- a/src/db/controller/packet.ts +++ b/src/db/controller/packet.ts @@ -598,7 +598,7 @@ export class PacketController { } } - // update timeout timestamp to -1 + // update timeout timestamp to -1 to execute timeout closed channel public static updateTimeout(chainId: string, channelId: string) { update( DB, diff --git a/src/lib/eventParser.ts b/src/lib/eventParser.ts index d7fabc0..8e34ba6 100644 --- a/src/lib/eventParser.ts +++ b/src/lib/eventParser.ts @@ -143,9 +143,8 @@ function find( { // check base64 encoded key - const vals = event.attributes.filter( - (v) => v.key === Buffer.from(`${key}`).toString('base64') - ) + const base64Key = Buffer.from(key).toString('base64') + const vals = event.attributes.filter((v) => v.key === base64Key) if (vals.length !== 0) { return Buffer.from(vals[0].value, 'base64').toString() } diff --git a/src/workers/wallet.ts b/src/workers/wallet.ts index 02d270d..fa9c64d 100644 --- a/src/workers/wallet.ts +++ b/src/workers/wallet.ts @@ -122,6 +122,8 @@ export class WalletWorker { remain ) + remain -= timeoutPackets.length + const channelOpenEvents = remain === 0 ? [] @@ -321,7 +323,7 @@ export class WalletWorker { if (result.raw_log.startsWith('account sequence mismatch')) { try { const expected = result.raw_log.split(', ')[1] - this.sequence = Number(expected.split(' ')[1]) + this.sequence = Number(expected.split(' ')[1]) - 1 this.logger.info(`update sequence`) } catch (e) { this.logger.warn(`error to parse sequence`) @@ -453,8 +455,8 @@ export class WalletWorker { sendPacketMap[path].map((packet) => packet.sequence) ) - const unreceivedSequences = unreceivedPackets.sequences.map((sequence) => - Number(sequence) + const unreceivedSequences = unreceivedPackets.sequences.map( + (sequence) => Number(sequence) ) sendPacketsToDel.push( @@ -483,7 +485,7 @@ export class WalletWorker { const writeAckPacketsToDel: PacketWriteAckTable[] = [] for (const packet of writeAckPackets) { - const path = `${packet.src_port}/${packet.src_port}` + const path = `${packet.src_port}/${packet.src_channel_id}` if (!writeAckPacketMap[path]) { writeAckPacketMap[path] = [] } @@ -531,7 +533,7 @@ export class WalletWorker { const timeoutPacketsToDel: PacketTimeoutTable[] = [] for (const packet of timeoutPackets) { - const path = `${packet.src_port}/${packet.src_port}` + const path = `${packet.src_port}/${packet.src_channel_id}` if (!timeoutPacketMap[path]) { timeoutPacketMap[path] = [] } @@ -579,8 +581,8 @@ export class WalletWorker { timeoutPacketMap[path].map((packet) => packet.sequence) ) - const unreceivedSequences = unreceivedPackets.sequences.map((sequence) => - Number(sequence) + const unreceivedSequences = unreceivedPackets.sequences.map( + (sequence) => Number(sequence) ) timeoutPacketsToDel.push(