Bitcoin Forum
May 27, 2024, 02:13:02 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How are transactions separated on bit-level in blocks?  (Read 746 times)
fevir (OP)
Newbie
*
Offline Offline

Activity: 22
Merit: 5


View Profile
November 21, 2016, 01:38:24 PM
Merited by ABCbits (1)
 #1

Hi,

A quick question. Assume that a block body contains several transactions (tx), and none of these transactions are of equal length. On bit level, transactions are represented by a set of 0 and 1. A set of tx will therefore result in a set of 0 and 1. Now, if a block contains multiple tx, how can the receiver of a block distinguish each transaction in the block body?

Thanks.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3402
Merit: 6659


Just writing some code


View Profile WWW
November 21, 2016, 02:08:01 PM
Merited by ABCbits (1)
 #2

Transactions have a known calculable size when it is parsed. So you will know that when a transaction ends and the next begins.

DannyHamilton
Legendary
*
Offline Offline

Activity: 3402
Merit: 4656



View Profile
November 21, 2016, 03:23:12 PM
Last edit: November 21, 2016, 03:50:33 PM by DannyHamilton
Merited by ABCbits (4)
 #3

Transactions have a known calculable size when it is parsed. So you will know that when a transaction ends and the next begins.

Specifically...

  • Each transaction starts with 32 bits (set of thirty-two 0 and 1 digits) that store a version number.
  • Following that is a "set of 0 and 1" that tell how many bits (actually how many bytes, but you can multiply by 8 to get the quantity of 0 and 1) in the transaction inputs.*
  • Following that is a "set of 0 and 1" representing all the inputs. This set is exactly the amount indicated in the previous "how many bits" value.
  • Following that is a "set of 0 and 1" that tell how many bits (actually how many bytes, but you can multiply by 8 to get the quantity of 0 and 1) in the transaction outputs.*
  • Following that is a "set of 0 and 1" representing all the outputs. This set is exactly the amount indicated in the previous "how many bits" value.
  • Following that is 32 bits that represent the locktime.

* note, there is a special pattern to the first eight 0 and 1 values of the section that "tells how many bits". This pattern allows the program to know when it has read enough 0 and 1 to determine the appropriate value. If this section starts with 11111111, then the next sixty-four 0 and 1 are used to indicate the size of the inputs or outputs. If it starts with 11111110, then the next thirty-two 0 and 1 are used to indicate the size of the inputs or outputs,  If it starts with 11111101, then the next sixteen 0 and 1 are used to indicate the size of the inputs or outputs. If it starts with anything else, then these 8 values are themselves the indication of the size of the inputs or outputs, and there is no need to use any additional digits to determine that size.

fevir (OP)
Newbie
*
Offline Offline

Activity: 22
Merit: 5


View Profile
November 21, 2016, 03:40:33 PM
 #4

Thanks, that's the details I was looking for
Kexkey
Full Member
***
Offline Offline

Activity: 237
Merit: 100

Smile while thinking.


View Profile
November 22, 2016, 01:56:41 AM
 #5

Thanks, that's the details I was looking for

Funny you want to have bit-scale details.  Have a look at the easy to understand and technically detailed doc : https://bitcoin.org/en/developer-reference#raw-transaction-format

Kex

This digital signature is not a digital signature.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!