You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 07-Template-Distribution-Protocol.md
+71-9Lines changed: 71 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,22 +10,84 @@ Thereafter, the server SHOULD push new block templates to the client whenever th
10
10
11
11
Template Providers MUST attempt to broadcast blocks which are mined using work they provided, and thus MUST track the work which they provided to clients.
12
12
13
+
When crafting a template, in order to avoid creating an invalid, oversized block, the Template Provider MUST reserve appropriate blockspace and sigops for:
14
+
- the block header: 80 bytes, or 320 weight units
15
+
- the block transaction count: 3 bytes (which in terms of `CompactSize` is worst case for minimally sized transactions in a block), or 12 weight units
16
+
- the serialized coinbase transaction: which has fixed-sized and variable-sized fields, see definition of [`CoinbaseOutputConstraints`](#71-coinbaseoutputconstraints-client---server) below
Ultimately, the pool is responsible for adding coinbase transaction outputs for payouts and other uses, and thus the Template Provider will need to consider this additional block size, and sigops when selecting transactions for inclusion in a block (to not create an invalid, oversized block).
16
-
Thus, this message is used to indicate that some additional space and sigops in the block/coinbase transaction be reserved for the pool’s use (while always assuming the pool will use the entirety of available coinbase space and sigops).
20
+
Here's a table with all fields of a Coinbase Transaction that have fixed size:
So a Template Provider MUST reserve 236 weight units for the fixed-size fields in case of a SegWit block, or 200 weight units in the unlikely case of a legacy block. Meanwhile, the following fields of a Coinbase Transaction have variable size:
|`scriptSig`| 100 bytes max | 4 WU/byte | 400 WU max |
41
+
|`output count`| 3 bytes max | 4 WU/byte | 12 WU max |
42
+
|`outputs`| no limit | 4 WU/byte | no limit |
43
+
44
+
Note: while `output count` is `CompactSize`, we can only fit ~110k minimally sized outputs into a block, so 3 bytes is the worst case value here.
45
+
46
+
So a Template Provider MUST also reserve:
47
+
- the worst-case 400 weight units for `scriptSig` field
48
+
- the worst-case 12 weight units for `output count` field
49
+
- 188 weight units for witness commitment output (if SegWit)
50
+
51
+
But ultimately, the Pool (or JDC, in case of Job Declaration) is responsible for adding coinbase transaction outputs for payouts and other uses, and thus the Template Provider will need to consider this additional block size, and sigops when selecting transactions for inclusion in a block.
52
+
53
+
Thus, the `CoinbaseOutputConstraints` message is used to indicate that some additional space and sigops in the block/coinbase transaction be reserved for the Pool or JDC use (while always assuming the entirety of available coinbase space and sigops will be used).
54
+
55
+
JDC MUST discover the maximum serialized size of the additional outputs and sigops which will be added by the Pool(s) it intends to use this work with (via `AllocateMiningJobToken.Success`). It then MUST communicate it to the Template Provider via `CoinbaseOutputConstraints`.
17
56
18
-
The Job Declarator MUST discover the maximum serialized size of the additional outputs and sigops which will be added by the pool(s) it intends to use this work.
19
-
It then MUST communicate it to the Template Provider via this message.
20
57
The Template Provider MUST NOT provide `NewTemplate` messages which would represent consensus-invalid blocks once this additional size and sigops — along with a maximally-sized (100 byte) coinbase script field — is added.
21
-
Further, the Template Provider MUST consider the maximum additional bytes required in the output count variable-length integer in the coinbase transaction when complying with the size limits.
22
-
Current sigops limit per block in bitcoin is 80_000. We are not aware of any use cases where
23
-
coinbase have more the 65_535 so coinbase_output_max_sigops is an U16. Note that taproot outputs consume 0 sigops.
58
+
59
+
Current sigops limit per block in bitcoin is `80_000`. We are not aware of any use cases where a coinbase transaction has more than `65_535` so `coinbase_output_max_sigops` is an `U16`. Note that taproot outputs consume `0` sigops.
| coinbase_output_max_additional_size | U32 | The maximum additional serialized bytes which the pool will add in coinbase transaction outputs |
28
-
| coinbase_output_max_additional_sigops | U16 | The maximum additional sigops which the pool will add in coinbase transaction outputs |
63
+
| coinbase_output_max_additional_size | U32 | The maximum additional serialized bytes which Pool or JDC will add in coinbase transaction outputs |
64
+
| coinbase_output_max_additional_sigops | U16 | The maximum additional sigops which Pool or JDC will add in coinbase transaction outputs |
65
+
66
+
Below are the formulas that summarize the rationale around reserving blockspace presented above. In addition to reserving `coinbase_output_max_additional_sigops` sigops, the Template Provider MUST reserve the following weight unit values.
67
+
68
+
For SegWit blocks:
69
+
70
+
- block header: 320 weight units
71
+
- block tx count: 12 weight units
72
+
- coinbase tx fixed-size fields: 236 weight units
73
+
- coinbase tx `scriptSig`: 400 weight units
74
+
- coinbase tx `output count`: 12 weight units
75
+
- coinbase tx witness commitment output: 188 weight units
76
+
- coinbase tx outputs added by Pool or JDC: 4*`coinbase_output_max_additional_size` weight units
77
+
78
+
total: 1168 + 4*`coinbase_output_max_additional_size` weight units
79
+
80
+
For legacy blocks:
81
+
- block header: 320 weight units
82
+
- block tx count: 12 weight units
83
+
- coinbase tx fixed-size fields: 200 weight units
84
+
- coinbase tx `scriptSig`: 400 weight units
85
+
- coinbase tx `output count`: 12 weight units
86
+
- coinbase tx outputs added by Pool or JDC: 4*`coinbase_output_max_additional_size` weight units
87
+
88
+
total: 944 + 4*`coinbase_output_max_additional_size` weight units
89
+
90
+
Please note that Bitcoin Core establishes a floor value of 2000 weight units.
0 commit comments