Transaction document : size, limits, optimization

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 )

We speak of compact format

compact format
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 :musical_note: “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.

2 Likes