Skip to content

Commit

Permalink
fix: fix errors from comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ALPAC-4 committed Dec 5, 2024
1 parent c0d899f commit 6521916
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
3 changes: 0 additions & 3 deletions src/db/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// constants

export const U64_MAX = 0xffffffffffffffffn

// db path
export const DB_PATH = './.db/main.db'
8 changes: 3 additions & 5 deletions src/db/controller/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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<ChannelOpenCloseTable>(DB, this.tableName, [
{
Expand Down
2 changes: 1 addition & 1 deletion src/db/controller/packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PacketTimeoutTable>(
DB,
Expand Down
5 changes: 2 additions & 3 deletions src/lib/eventParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
16 changes: 9 additions & 7 deletions src/workers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export class WalletWorker {
remain
)

remain -= timeoutPackets.length

const channelOpenEvents =
remain === 0
? []
Expand Down Expand Up @@ -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`)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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] = []
}
Expand Down Expand Up @@ -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] = []
}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 6521916

Please sign in to comment.