From 503a92976cf7fd3b9a9c089bc614621aaed5d9ab Mon Sep 17 00:00:00 2001 From: Matthew Black Date: Sat, 4 Apr 2026 14:29:34 -0500 Subject: [PATCH] fix: remove backward compatibility heuristic for DlcOffer protocol version Remove the heuristic-based backward compatibility logic that was attempting to differentiate between old and new DlcOffer formats. The protocol_version field is now always read as a 4-byte u32 as specified in dlcspecs PR #163. This simplifies the parsing logic and ensures consistent handling of the protocol version field across all DlcOffer messages. --- packages/messaging/lib/messages/DlcOffer.ts | 32 ++------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/packages/messaging/lib/messages/DlcOffer.ts b/packages/messaging/lib/messages/DlcOffer.ts index 23d0458c..13dd97f5 100644 --- a/packages/messaging/lib/messages/DlcOffer.ts +++ b/packages/messaging/lib/messages/DlcOffer.ts @@ -127,35 +127,9 @@ export class DlcOffer implements IDlcMessage { ); } - // BACKWARD COMPATIBILITY: Detect old vs new format - // New format: [type][protocol_version: 4 bytes][contract_flags: 1 byte][chain_hash: 32 bytes] - // Old format: [type][contract_flags: 1 byte][chain_hash: 32 bytes] - - const nextBytes = reader.buffer.subarray( - reader.position, - reader.position + 5, - ); - const nextBytesBuffer = Buffer.from(nextBytes); - const nextBytesReader = new BufferReader(nextBytesBuffer); - const possibleProtocolVersion = nextBytesReader.readUInt32BE(); - const possibleContractFlags = nextBytesReader.readUInt8(); - - // Heuristic: protocol_version should be 1, contract_flags should be 0 - // If first 4 bytes are reasonable protocol version (1-10) and next byte is 0, assume new format - const isNewFormat = - possibleProtocolVersion >= 1 && - possibleProtocolVersion <= 10 && - possibleContractFlags === 0; - - if (isNewFormat) { - // New format with protocol_version - instance.protocolVersion = reader.readUInt32BE(); - instance.contractFlags = reader.readBytes(1); - } else { - // Old format without protocol_version - instance.protocolVersion = 1; // Default to version 1 - instance.contractFlags = reader.readBytes(1); - } + // Read protocol_version as 4 bytes (u32) as per dlcspecs PR #163 + instance.protocolVersion = reader.readUInt32BE(); + instance.contractFlags = reader.readBytes(1); instance.chainHash = reader.readBytes(32); instance.temporaryContractId = reader.readBytes(32);