<p>Numbers up to 252 are encoded as a single byte, while larger numbers take 3 bytes. Differential encoding is effectively a form of compression, reducing the size of the data without losing information (the same set of transactions is communicated). Size of encoding matters in compact blocks, as its purpose is reducing latency. One aspect of that is aiming to fit everything in as few IP packets as possible (typically around 1500 bytes on the internet).</p>

CC BY-SA 4.0
2023-12-22T16:25:30.847Z
2023-12-22T16:25:30.847Z
Pieter Wuille
<p>If I want to send transaction indexes in either <code>cmpctblock</code> or <code>getblocktxn</code> messages, they are represented as differences. For example if I want to send indexes 0, 54, 65, 67 and 1236, they are represented as 0, 53, 10, 1 and 1168.</p>
<p>Why was this done this way? Why not only indexes are passed, but their differences? Is this due to some optimization or something else?</p>

<message><encoding>
Why are indexes in cmpctblock and getblocktxn messages calculated as differences?
Cosmos
# Why are indexes in cmpctblock and getblocktxn messages calculated as differences?

(Asked by: username_0 on 2023-12-22)

If I want to send transaction indexes in either `cmpctblock` or `getblocktxn` messages, they are represented as differences. For example if I want to send indexes 0, 54, 65, 67 and 1236, they are represented as 0, 53, 10, 1 and 1168.

Why was this done this way? Why not only indexes are passed, but their differences? Is this due to some optimization or something else?

**Tags:** message, encoding


---

## 1 answers

### Answer by username_1 on 2023-12-22. Score: 4 | Accepted answer

Numbers up to 252 are encoded as a single byte, while larger numbers take 3 bytes. Differential encoding is effectively a form of compression, reducing the size of the data without losing information (the same set of transactions is communicated). Size of encoding matters in compact blocks, as its purpose is reducing latency. One aspect of that is aiming to fit everything in as few IP packets as possible (typically around 1500 bytes on the internet).


---

