Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/tempo/server/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,15 @@ async function verifyAndAcceptVoucher(parameters: {
if (onChain.closeRequestedAt !== 0n) {
throw new ChannelClosedError({ reason: 'channel has a pending close request' })
}
// Treat a zero deposit on an existing channel as settled/closed.
// During settlement the escrow contract may zero the deposit before
// setting the finalized flag, creating a brief window where
// finalized=false but deposit=0. Without this guard the voucher
// check below would return a 402 (AmountExceedsDepositError) instead
// of the correct 410 (ChannelClosedError).
if (onChain.deposit === 0n && onChain.payer !== '0x0000000000000000000000000000000000000000') {
throw new ChannelClosedError({ reason: 'channel deposit is zero (settled)' })
}

if (voucher.cumulativeAmount <= onChain.settled) {
throw new VerificationFailedError({
Expand Down