# Transaction document : size, limits, optimization

**URL:** https://forum.duniter.org/t/transaction-document-size-limits-optimization/7766
**Category:** DUBP
**Tags:** transaction
**Created:** [17 November 2020 09:08 UTC](https://forum.duniter.org/t/transaction-document-size-limits-optimization/7766 "2020-11-17T09:08:55Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![matograine](https://forum.duniter.org/letter_avatar/matograine/32/5_5575768a8748004e209b776fc1b2916d.png) [@matograine](https://forum.duniter.org/u/matograine)
#### Post date: [17 November 2020 09:08 UTC](https://forum.duniter.org/t/transaction-document-size-limits-optimization/7766/1 "2020-11-17T09:08:55Z")

</div>

Hi !

I am working on the optimization of the document size in Silkaj. I share my calculations, hope this will help some other client devs.

Maybe @elois will find it useful for his GVA payment application. I also know @moul wanted to understand it more deeply.

## Transaction doc size

> A transaction in compact format cannot measure more than 100 lines ([rfc](https://git.duniter.org/nodes/common/doc/blob/master/rfc/0009_Duniter_Blockchain_Protocol_V11.md#transactions) )

We speak of _[compact](https://git.duniter.org/nodes/common/doc/blob/master/rfc/0009_Duniter_Blockchain_Protocol_V11.md#compact-format)_ format

> **compact format**
>
> ```auto
> TX:VERSION:NB_ISSUERS:NB_INPUTS:NB_UNLOCKS:NB_OUTPUTS:HAS_COMMENT:LOCKTIME
> BLOCKSTAMP
> PUBLIC_KEY
> ...
> INPUT
> ...
> UNLOCK
> ...
> OUTPUT
> ...
> COMMENT
> SIGNATURE
> ...
> 
> ```

## Transaction doc values

in 100 lines, we have :

- 2 **mandatory** lines (TX:… and BLOCKSTAMP). Let them be “FIX”

- 2 lines for **each issuer** (PUBKEY + SIGNATURE). Let “IS” be the number of issuers

- 2 lines for **each source** (INPUT + UNLOCK). Let “IN” be the number of sources

- 1 line for each output. Let “O” be the number of outputs.

- 0 to 1 line for comment. Let it be 🎵 “C”

Thus, we can set this formula :

> LINES\_NUMBER = FIX + (2 \* IS) + (2 \* IN) + O + C

## Limit values

The minimum tx is 1 issuer, 1 input, 1 output, 0 coment. The minimum values for IS, IN, O are 1.

C can be 0 or 1.

But what about maximum ?

We reach MAX\_ISSUERS when all other values are at minimum (it means, no comment), and LINES\_NUMBER is maximum 100 :

> MAX\_ISSUERS = (LINES\_NUMBER - FIX - (2 \* IN) - O - C) /2  
> MAX\_ISSUERS = (100 - 2 - 2 \* 1 - 1 - 0) / 2 = 95 / 2 = **47**

Follow :

> MAX\_INPUTS = (LINES\_NUMBER - FIX - (2 \* IS) - O - C) /2  
> MAX\_INPUTS = (100 - 2 - 2 \* 1 - 1 - 0) / 2 = 95 / 2 = **47**

> MAX\_OUTPUTS = LINES\_NUMBER - FIX - (2 \* IS) - (2 \* IN) - C  
> MAX\_OUTPUTS = 100 - 2 - 2 \* 1 - 2 \* 1 - 0 = **94**

## Common transaction

A common transaction has 1 issuer, 1 comment, 2 outputs (one for the receiver, one for the backchange). Let’s calculate the maximum number of inputs :

> INPUTS = (100 - 2 - 2 \* 1 - 2 - 1) /2 = 93/2 = 46

* * *

edit :

note about MAX\_ISSUERS : in this example, we have 47 issuers an only 1 input. This would rarely happen : in most cases in multisig transactions, one would have more inputs than issuers, because each issuer would send at least one input. However, the DUBP permits to have issuers that don’t spend any unit during a tx, but still sign the tx.
