1

It seems like duplicated question, but i read many articles and posts to undestand about segwit.

Below links are something i read

What is block weight and how is it different from block size?

After Segwit Activation, what is the largest block size possible?

Understanding Segwit Block Size

Block weight

But i need example to clearfy about block weight T_T

In Understanding Segwit Block Size article, writer said that

The Segwit blocks are restricted by something called Block Weight. Block Weight is a new concept introduced in Segwit, and it’s calculated on a per-transaction basis. Each transaction has a “weight” which is defined this way:

(tx size with witness data stripped) * 3 + (tx size)

I think tx size is

tx = transactions + witness data

Then i stuck in recursion... I cannot undetstand.

To me, it seems like contradictory.

Because to define a tx size, needs Block weight to restrict witness data size. But to get a weight, need a tx size.

I understood that if there is no witness data, then maximum block size is 1mb(Before segwit). Yes It is clear. But some people are using weight same with byte.

For example, some people said(especially bitcoin wiki - Block weight)

weight = 1mb * 3 + 1mb = 4mb

And others said(What is block weight and how is it different from block size?)

Even in this post, Sam Jone said 4,000,000 WU but block is still 1mb

weight = 1mb * 3 + 1mb = 4,000,000 Weight unit(WU) Or 4mWU

what is the exact expression?

and If there is no witness data then what is left 3mb or 3mWU filled? is it empty?

In Block #577639, Block size is 1158.038 kB

How witness data is sotred?

1mb transaction + witness data right...?

or

1mb block is shared by transactions and witness data?

Basic concept of segwit is keep a block size as 1mb for transactions and add witness data right...?

It means size of transactions(witness data is excluded) is 1158.038kB? or transactions + witness data is 1158.038kb?

As we know, maximum block weight is 4mWU or 4mb. Therefore, if transactions without witness data is about 1.1mb, then it seems like weird

block weight = 1.1mb * 3 + (1.1mb + witnessdata)

Because it is larger than possible maximum size.

If transactions + witness data is about 1.1mb

block weight = (1.1mb - witnessdata) * 3 + 1.1mb

this calculation seems more reasonable. But if witness data is less than 0.1mb then block weight is more than 4mb. Is it possible that so little witness data?

And If There is only transaction data and no witness data like 1mb transaction data and 0 witness data(block weight is 4mb or 4mWU which is theoritical maximum size) Then how Transaction Malleability problem is solved?

I am so sorry. Questions are quite long, but i hope it can be helpful not only me but also person who are studying about blockchain.

Thank you for reading

4

Have a look: https://blockchair.com/bitcoin/block/0000000000000000000cbbceb342e07071f9621607e044ec909aa86fcdf88e8a

Size = 1,158,038 bytes
Weight units = 3,992,825 WU

Now what does it mean? So the size is what you probably understand well – when you have a file on disk, its size is measured in bytes and this is exactly what the size means here. It is the number of bytes you would need to store such a block in memory or on disk. This is the sum of non-witness data (nWD) and witness data (WD). Let's call this the absolute size for clarity (AS).

There is also something called virtual size (VS). This is a new concept, which measures the block in new units, called vBytes. It is calculated as (absolute size of non-witness data) + (absolute size of witness data)/4.

Weight of the block (BW) is calculated in weight units and is calculated as (absolute size of non-witness data) * 4 + (absolute size of witness data). This actually equals what you have mentioned in your post: (tx size with witness data stripped) * 3 + (tx size) because the transaction itself contains both witness and non-witness data.

So, now we know that:

AS = 1,158,038 bytes = nWD bytes + WD bytes
BW = 3,992,825 WU = nWD * 4 weight units + WD weight units

What are the limits in the protocol? Currently there is no block size limit any more. There is just one limit for block weight. This limit is set to 4,000,000 WU. It follows that in case of a block without Segwit txs, each byte's weight is 4 WU, therefore, such a block without Segwit txs is limited by absolute size of 1 MB.

Blocks that contain Segwit txs can be bigger than that and there are some theoretical calculations that say you can go to something like 3.7 MB of absolute size of a block. But this theoretical limit is just that – theoretical. In practice, even if the block was full of Segwit txs, its absolute size would not reach this limit.

Currently, most blocks contain both txs - Segwit and legacy, so we see the block sizes of full blocks usually in the range between 1 - 2.2 MB. The block is full if it's weight is very close to the protocol limit of 4,000,000 WU.

This implies that it is not correct to think that a block of size 1.1 MB is composed of 1,000,000 bytes of nWD and the rest is WD. That wouldn't work because the weight of 1,000,000 nWD bytes would already be 4,000,000 WU and therefore if we added the weight of WD to it, we would be over the limit. That is not possible.

So, if we know AS = 1,158,038 KB then it is rather that there are 944,929 bytes of nWD with weight of 3,779,716 WU and the rest is 213,109 bytes of WD with weight 213,109. This makes the total weight of the block 3,779,716 + 213,109 = 3,992,825 WU.

We can now calculate VS:

VS = nWD vBytes + WD/4 vBytes = 944,929 + 213,109 / 4 = 998,206.25 vBytes

Virtual size (VS) thus cannot be greater than 1,000,000 vBytes, so this is what is meant if someone says that the new block size is still limited by 1 MB - they actually mean 1 million of vBytes.

  • wow.. really really clear. Thank a lot! but "Currently, most blocks contain both txs - Segwit and legacy" This sentence means even the latest block is still including a legacy transaction which has script inside? – HSKim May 27 at 7:53
  • 1
    Even the latest blocks contain non-Segwit transactions. But because they also contain Segwit transactions, the whole block is Segwit. I'm not sure what you mean by "script inside". Script is used in both Segwit and non-Segwit transactions. Because this topic is very wide, consider asking multiple questions with limited scope. – Wapac May 27 at 15:53
  • Thank you a lot very helpful. Have a nice week:) – HSKim May 28 at 2:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.