Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve coinbase #1248

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Improve coinbase #1248

wants to merge 12 commits into from

Conversation

Fi3
Copy link
Collaborator

@Fi3 Fi3 commented Nov 13, 2024

Better management of the coinbase's input script:

  • rename the pool signature field of the channel factory into coinbase_script_additional_data, and change the type from String to Vec<u8>. Sv2 do not say anything about pool's signature, but we still want to let the user add some arbitrary data and the beginning of the extranonce. We do not assume that this data is a pool signature. We do not assume that this data is valid utf8.
  • send downstream coinbase_script_additional_data as part of the extranonce_prefix and not as part of the coinbase_prefix. This make the implementation of a JDC more straightforward, as it do not need anymore to observe the jobs sent and created by the pool and reconstruct and parse the coinbase to know the coinbase_script_additional_data.
  • add a method that the pool can use in order to change coinbase_script_additional_data of an already opened channel and send downstream the new extranonce_prefix

Copy link
Contributor

github-actions bot commented Nov 13, 2024

🐰 Bencher Report

BranchImproveCoinbase
Testbedsv1
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
nanoseconds (ns)
(Result Δ%)
Upper Boundary
nanoseconds (ns)
(Limit %)
client-submit-serialize📈 view plot
🚷 view threshold
6,498.10
(-3.38%)
7,245.69
(89.68%)
client-submit-serialize-deserialize📈 view plot
🚷 view threshold
7,345.20
(-3.88%)
8,182.60
(89.77%)
client-submit-serialize-deserialize-handle/client-submit-serialize-deserialize-handle📈 view plot
🚷 view threshold
8,064.40
(-1.82%)
8,588.62
(93.90%)
client-sv1-authorize-serialize-deserialize-handle/client-sv1-authorize-serialize-deserialize-handle📈 view plot
🚷 view threshold
876.58
(+0.38%)
942.34
(93.02%)
client-sv1-authorize-serialize-deserialize/client-sv1-authorize-serialize-deserialize📈 view plot
🚷 view threshold
684.24
(+1.62%)
716.65
(95.48%)
client-sv1-authorize-serialize/client-sv1-authorize-serialize📈 view plot
🚷 view threshold
246.16
(-0.91%)
262.17
(93.89%)
client-sv1-get-authorize/client-sv1-get-authorize📈 view plot
🚷 view threshold
158.59
(+0.67%)
163.94
(96.74%)
client-sv1-get-submit📈 view plot
🚷 view threshold
6,287.30
(-3.82%)
7,306.95
(86.05%)
client-sv1-get-subscribe/client-sv1-get-subscribe📈 view plot
🚷 view threshold
278.32
(-0.80%)
311.40
(89.38%)
client-sv1-subscribe-serialize-deserialize-handle/client-sv1-subscribe-serialize-deserialize-handle📈 view plot
🚷 view threshold
728.94
(-0.56%)
792.87
(91.94%)
client-sv1-subscribe-serialize-deserialize/client-sv1-subscribe-serialize-deserialize📈 view plot
🚷 view threshold
601.21
(+0.66%)
641.98
(93.65%)
client-sv1-subscribe-serialize/client-sv1-subscribe-serialize📈 view plot
🚷 view threshold
209.43
(+1.34%)
221.77
(94.43%)
🐰 View full continuous benchmarking report in Bencher

Copy link
Contributor

github-actions bot commented Nov 13, 2024

🐰 Bencher Report

BranchImproveCoinbase
Testbedsv1

🚨 1 Alert

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
serialize_deserialize_submitRAM Accesses
accesses
📈 plot
🚨 alert (🔔)
🚷 threshold
500.00
(+1.76%)
498.84
(100.23%)
Click to view all benchmark results
BenchmarkEstimated CyclesBenchmark Result
estimated cycles
(Result Δ%)
Upper Boundary
estimated cycles
(Limit %)
InstructionsBenchmark Result
instructions
(Result Δ%)
Upper Boundary
instructions
(Limit %)
L1 AccessesBenchmark Result
accesses
(Result Δ%)
Upper Boundary
accesses
(Limit %)
L2 AccessesBenchmark Result
accesses
(Result Δ%)
Upper Boundary
accesses
(Limit %)
RAM AccessesBenchmark Result
accesses
(Result Δ%)
Upper Boundary
accesses
(Limit %)
get_authorize📈 view plot
🚷 view threshold
8,346.00
(-1.41%)
8,732.36
(95.58%)
📈 view plot
🚷 view threshold
3,663.00
(-2.30%)
3,857.34
(94.96%)
📈 view plot
🚷 view threshold
5,111.00
(-2.77%)
5,426.68
(94.18%)
📈 view plot
🚷 view threshold
10.00
(+37.93%)
13.26
(75.43%)
📈 view plot
🚷 view threshold
91.00
(+0.39%)
95.14
(95.65%)
get_submit📈 view plot
🚷 view threshold
95,260.00
(-0.18%)
95,893.83
(99.34%)
📈 view plot
🚷 view threshold
59,263.00
(-0.33%)
59,685.04
(99.29%)
📈 view plot
🚷 view threshold
85,075.00
(-0.38%)
85,762.68
(99.20%)
📈 view plot
🚷 view threshold
49.00
(+9.46%)
63.35
(77.34%)
📈 view plot
🚷 view threshold
284.00
(+1.37%)
289.30
(98.17%)
get_subscribe📈 view plot
🚷 view threshold
7,867.00
(-1.94%)
8,277.68
(95.04%)
📈 view plot
🚷 view threshold
2,758.00
(-2.71%)
2,937.77
(93.88%)
📈 view plot
🚷 view threshold
3,832.00
(-3.27%)
4,120.52
(93.00%)
📈 view plot
🚷 view threshold
16.00
(+33.59%)
20.69
(77.35%)
📈 view plot
🚷 view threshold
113.00
(-1.15%)
118.50
(95.36%)
serialize_authorize📈 view plot
🚷 view threshold
12,135.00
(-1.20%)
12,567.08
(96.56%)
📈 view plot
🚷 view threshold
5,240.00
(-1.52%)
5,424.78
(96.59%)
📈 view plot
🚷 view threshold
7,280.00
(-1.88%)
7,584.83
(95.98%)
📈 view plot
🚷 view threshold
12.00
(+31.06%)
16.34
(73.45%)
📈 view plot
🚷 view threshold
137.00
(-0.47%)
142.56
(96.10%)
serialize_deserialize_authorize📈 view plot
🚷 view threshold
24,576.00
(-0.47%)
25,225.57
(97.42%)
📈 view plot
🚷 view threshold
9,786.00
(-1.06%)
10,033.67
(97.53%)
📈 view plot
🚷 view threshold
13,786.00
(-1.27%)
14,186.22
(97.18%)
📈 view plot
🚷 view threshold
37.00
(+6.76%)
43.61
(84.84%)
📈 view plot
🚷 view threshold
303.00
(+0.47%)
315.06
(96.17%)
serialize_deserialize_handle_authorize📈 view plot
🚷 view threshold
30,201.00
(-0.41%)
30,749.69
(98.22%)
📈 view plot
🚷 view threshold
11,989.00
(-0.77%)
12,202.89
(98.25%)
📈 view plot
🚷 view threshold
16,951.00
(-0.92%)
17,292.44
(98.03%)
📈 view plot
🚷 view threshold
60.00
(+7.99%)
67.42
(88.99%)
📈 view plot
🚷 view threshold
370.00
(+0.08%)
381.53
(96.98%)
serialize_deserialize_handle_submit📈 view plot
🚷 view threshold
126,506.00
(+0.02%)
126,895.77
(99.69%)
📈 view plot
🚷 view threshold
73,117.00
(-0.23%)
73,510.81
(99.46%)
📈 view plot
🚷 view threshold
104,756.00
(-0.29%)
105,438.09
(99.35%)
📈 view plot
🚷 view threshold
115.00
(+7.52%)
132.66
(86.69%)
📈 view plot
🚷 view threshold
605.00
(+1.43%)
605.52
(99.91%)
serialize_deserialize_handle_subscribe📈 view plot
🚷 view threshold
27,807.00
(-0.13%)
28,598.38
(97.23%)
📈 view plot
🚷 view threshold
9,577.00
(-0.75%)
9,751.62
(98.21%)
📈 view plot
🚷 view threshold
13,517.00
(-0.96%)
13,806.44
(97.90%)
📈 view plot
🚷 view threshold
72.00
(+13.34%)
76.21
(94.47%)
📈 view plot
🚷 view threshold
398.00
(+0.38%)
416.67
(95.52%)
serialize_deserialize_submit📈 view plot
🚷 view threshold
115,211.00
(-0.03%)
115,799.33
(99.49%)
📈 view plot
🚷 view threshold
67,894.00
(-0.31%)
68,396.31
(99.27%)
📈 view plot
🚷 view threshold
97,356.00
(-0.39%)
98,225.58
(99.11%)
📈 view plot
🚷 view threshold
71.00
(+13.19%)
78.31
(90.67%)
📈 view plot
🚨 view alert (🔔)
🚷 view threshold
500.00
(+1.76%)
498.84
(100.23%)
serialize_deserialize_subscribe📈 view plot
🚷 view threshold
23,184.00
(-0.34%)
23,985.79
(96.66%)
📈 view plot
🚷 view threshold
8,129.00
(-0.92%)
8,307.32
(97.85%)
📈 view plot
🚷 view threshold
11,424.00
(-1.15%)
11,712.66
(97.54%)
📈 view plot
🚷 view threshold
42.00
(+12.68%)
44.55
(94.27%)
📈 view plot
🚷 view threshold
330.00
(+0.26%)
347.65
(94.92%)
serialize_submit📈 view plot
🚷 view threshold
99,713.00
(-0.13%)
100,301.51
(99.41%)
📈 view plot
🚷 view threshold
61,325.00
(-0.29%)
61,718.15
(99.36%)
📈 view plot
🚷 view threshold
87,933.00
(-0.36%)
88,596.40
(99.25%)
📈 view plot
🚷 view threshold
53.00
(+13.44%)
64.32
(82.40%)
📈 view plot
🚷 view threshold
329.00
(+1.30%)
333.83
(98.55%)
serialize_subscribe📈 view plot
🚷 view threshold
11,350.00
(-0.48%)
11,676.74
(97.20%)
📈 view plot
🚷 view threshold
4,111.00
(-1.71%)
4,280.97
(96.03%)
📈 view plot
🚷 view threshold
5,690.00
(-2.21%)
5,973.52
(95.25%)
📈 view plot
🚷 view threshold
19.00
(+47.30%)
20.95
(90.68%)
📈 view plot
🚷 view threshold
159.00
(+0.79%)
163.15
(97.46%)
🐰 View full continuous benchmarking report in Bencher

Copy link
Contributor

github-actions bot commented Nov 13, 2024

🐰 Bencher Report

BranchImproveCoinbase
Testbedsv2
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
nanoseconds (ns)
(Result Δ%)
Upper Boundary
nanoseconds (ns)
(Limit %)
client_sv2_handle_message_common📈 view plot
🚷 view threshold
44.52
(-0.13%)
46.91
(94.91%)
client_sv2_handle_message_mining📈 view plot
🚷 view threshold
74.87
(+0.43%)
80.32
(93.21%)
client_sv2_mining_message_submit_standard📈 view plot
🚷 view threshold
14.71
(+0.28%)
14.84
(99.14%)
client_sv2_mining_message_submit_standard_serialize📈 view plot
🚷 view threshold
277.68
(+4.26%)
323.39
(85.87%)
client_sv2_mining_message_submit_standard_serialize_deserialize📈 view plot
🚷 view threshold
666.32
(+7.81%)
747.44
(89.15%)
client_sv2_open_channel📈 view plot
🚷 view threshold
163.81
(+7.12%)
194.34
(84.29%)
client_sv2_open_channel_serialize📈 view plot
🚷 view threshold
286.20
(+0.19%)
315.19
(90.80%)
client_sv2_open_channel_serialize_deserialize📈 view plot
🚷 view threshold
385.06
(+1.36%)
408.02
(94.37%)
client_sv2_setup_connection📈 view plot
🚷 view threshold
163.83
(+1.74%)
172.90
(94.75%)
client_sv2_setup_connection_serialize📈 view plot
🚷 view threshold
482.18
(+2.89%)
542.70
(88.85%)
client_sv2_setup_connection_serialize_deserialize📈 view plot
🚷 view threshold
1,034.00
(+5.36%)
1,095.42
(94.39%)
🐰 View full continuous benchmarking report in Bencher

Copy link
Contributor

github-actions bot commented Nov 13, 2024

🐰 Bencher Report

BranchImproveCoinbase
Testbedsv2

🚨 3 Alerts

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
client_sv2_handle_message_miningEstimated Cycles
estimated cycles
📈 plot
🚨 alert (🔔)
🚷 threshold
8,314.00
(+1.35%)
8,287.21
(100.32%)
client_sv2_handle_message_miningRAM Accesses
accesses
📈 plot
🚨 alert (🔔)
🚷 threshold
142.00
(+2.15%)
141.00
(100.71%)
client_sv2_mining_message_submit_standard_serialize_deserializeL2 Accesses
accesses
📈 plot
🚨 alert (🔔)
🚷 threshold
91.00
(+11.89%)
89.75
(101.39%)
Click to view all benchmark results
BenchmarkEstimated CyclesBenchmark Result
estimated cycles
(Result Δ%)
Upper Boundary
estimated cycles
(Limit %)
InstructionsBenchmark Result
instructions
(Result Δ%)
Upper Boundary
instructions
(Limit %)
L1 AccessesBenchmark Result
accesses
(Result Δ%)
Upper Boundary
accesses
(Limit %)
L2 AccessesBenchmark Result
accesses
(Result Δ%)
Upper Boundary
accesses
(Limit %)
RAM AccessesBenchmark Result
accesses
(Result Δ%)
Upper Boundary
accesses
(Limit %)
client_sv2_handle_message_common📈 view plot
🚷 view threshold
2,031.00
(-3.03%)
2,209.15
(91.94%)
📈 view plot
🚷 view threshold
473.00
(-0.07%)
488.51
(96.82%)
📈 view plot
🚷 view threshold
736.00
(0.00%)
757.26
(97.19%)
📈 view plot
🚷 view threshold
7.00
(+31.57%)
13.64
(51.32%)
📈 view plot
🚷 view threshold
36.00
(-5.40%)
41.24
(87.29%)
client_sv2_handle_message_mining📈 view plot
🚨 view alert (🔔)
🚷 view threshold
8,314.00
(+1.35%)
8,287.21
(100.32%)
📈 view plot
🚷 view threshold
2,137.00
(-0.03%)
2,143.08
(99.72%)
📈 view plot
🚷 view threshold
3,154.00
(-0.22%)
3,170.67
(99.47%)
📈 view plot
🚷 view threshold
38.00
(+7.11%)
41.84
(90.83%)
📈 view plot
🚨 view alert (🔔)
🚷 view threshold
142.00
(+2.15%)
141.00
(100.71%)
client_sv2_mining_message_submit_standard📈 view plot
🚷 view threshold
6,369.00
(+1.40%)
6,398.76
(99.53%)
📈 view plot
🚷 view threshold
1,750.00
(-0.05%)
1,766.87
(99.05%)
📈 view plot
🚷 view threshold
2,544.00
(-0.38%)
2,575.70
(98.77%)
📈 view plot
🚷 view threshold
23.00
(+36.17%)
24.42
(94.19%)
📈 view plot
🚷 view threshold
106.00
(+1.85%)
107.32
(98.77%)
client_sv2_mining_message_submit_standard_serialize📈 view plot
🚷 view threshold
14,710.00
(-0.11%)
14,947.99
(98.41%)
📈 view plot
🚷 view threshold
4,694.00
(-0.02%)
4,710.87
(99.64%)
📈 view plot
🚷 view threshold
6,750.00
(-0.13%)
6,781.78
(99.53%)
📈 view plot
🚷 view threshold
52.00
(+19.84%)
52.94
(98.22%)
📈 view plot
🚷 view threshold
220.00
(-0.66%)
227.33
(96.78%)
client_sv2_mining_message_submit_standard_serialize_deserialize📈 view plot
🚷 view threshold
27,652.00
(+0.42%)
27,819.17
(99.40%)
📈 view plot
🚷 view threshold
10,645.00
(+0.57%)
10,656.37
(99.89%)
📈 view plot
🚷 view threshold
15,507.00
(+0.68%)
15,519.38
(99.92%)
📈 view plot
🚨 view alert (🔔)
🚷 view threshold
91.00
(+11.89%)
89.75
(101.39%)
📈 view plot
🚷 view threshold
334.00
(-0.32%)
341.67
(97.75%)
client_sv2_open_channel📈 view plot
🚷 view threshold
4,481.00
(+1.99%)
4,592.89
(97.56%)
📈 view plot
🚷 view threshold
1,461.00
(-0.02%)
1,476.51
(98.95%)
📈 view plot
🚷 view threshold
2,156.00
(-0.19%)
2,184.12
(98.71%)
📈 view plot
🚷 view threshold
10.00
(+13.88%)
16.90
(59.16%)
📈 view plot
🚷 view threshold
65.00
(+3.90%)
67.92
(95.70%)
client_sv2_open_channel_serialize📈 view plot
🚷 view threshold
14,142.00
(+0.66%)
14,391.54
(98.27%)
📈 view plot
🚷 view threshold
5,064.00
(-0.01%)
5,079.51
(99.69%)
📈 view plot
🚷 view threshold
7,317.00
(-0.13%)
7,351.51
(99.53%)
📈 view plot
🚷 view threshold
42.00
(+19.87%)
43.18
(97.26%)
📈 view plot
🚷 view threshold
189.00
(+1.02%)
196.96
(95.96%)
client_sv2_open_channel_serialize_deserialize📈 view plot
🚷 view threshold
22,740.00
(+0.34%)
22,908.26
(99.27%)
📈 view plot
🚷 view threshold
8,040.00
(+0.22%)
8,072.97
(99.59%)
📈 view plot
🚷 view threshold
11,695.00
(+0.21%)
11,750.05
(99.53%)
📈 view plot
🚷 view threshold
81.00
(+8.93%)
85.12
(95.16%)
📈 view plot
🚷 view threshold
304.00
(+0.18%)
311.03
(97.74%)
client_sv2_setup_connection📈 view plot
🚷 view threshold
4,685.00
(+0.01%)
4,774.79
(98.12%)
📈 view plot
🚷 view threshold
1,502.00
(-0.02%)
1,517.51
(98.98%)
📈 view plot
🚷 view threshold
2,275.00
(-0.15%)
2,299.21
(98.95%)
📈 view plot
🚷 view threshold
13.00
(+35.84%)
16.69
(77.90%)
📈 view plot
🚷 view threshold
67.00
(-0.57%)
69.79
(96.01%)
client_sv2_setup_connection_serialize📈 view plot
🚷 view threshold
15,950.00
(-1.33%)
16,442.16
(97.01%)
📈 view plot
🚷 view threshold
5,963.00
(-0.01%)
5,978.51
(99.74%)
📈 view plot
🚷 view threshold
8,660.00
(-0.05%)
8,691.24
(99.64%)
📈 view plot
🚷 view threshold
51.00
(+28.15%)
52.97
(96.28%)
📈 view plot
🚷 view threshold
201.00
(-3.65%)
216.02
(93.05%)
client_sv2_setup_connection_serialize_deserialize📈 view plot
🚷 view threshold
35,588.00
(+0.10%)
35,763.26
(99.51%)
📈 view plot
🚷 view threshold
14,888.00
(+0.25%)
14,910.16
(99.85%)
📈 view plot
🚷 view threshold
21,878.00
(+0.27%)
21,923.52
(99.79%)
📈 view plot
🚷 view threshold
103.00
(+11.79%)
111.08
(92.73%)
📈 view plot
🚷 view threshold
377.00
(-0.59%)
384.69
(98.00%)
🐰 View full continuous benchmarking report in Bencher

Copy link

codecov bot commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 47.54098% with 96 lines in your changes missing coverage. Please review.

Project coverage is 19.90%. Comparing base (67a3f00) to head (0a6f3d7).

Files with missing lines Patch % Lines
...les-logic-sv2/src/channel_logic/channel_factory.rs 49.64% 70 Missing ⚠️
protocols/v2/roles-logic-sv2/src/utils.rs 20.00% 8 Missing ⚠️
roles/pool/src/lib/mining_pool/mod.rs 0.00% 6 Missing ⚠️
roles/translator/src/lib/proxy/bridge.rs 0.00% 4 Missing ⚠️
roles/pool/src/lib/mining_pool/message_handler.rs 0.00% 3 Missing ⚠️
...tocols/v2/roles-logic-sv2/src/channel_logic/mod.rs 0.00% 2 Missing ⚠️
protocols/v2/roles-logic-sv2/src/job_dispatcher.rs 85.71% 1 Missing ⚠️
roles/jd-client/src/lib/upstream_sv2/upstream.rs 0.00% 1 Missing ⚠️
...les/translator/src/lib/proxy/next_mining_notify.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1248      +/-   ##
==========================================
+ Coverage   19.30%   19.90%   +0.60%     
==========================================
  Files         164      164              
  Lines       10849    11021     +172     
==========================================
+ Hits         2094     2194     +100     
- Misses       8755     8827      +72     
Flag Coverage Δ
binary_codec_sv2-coverage 0.00% <0.00%> (ø)
binary_serde_sv2-coverage 3.62% <0.00%> (-0.03%) ⬇️
binary_sv2-coverage 5.43% <0.00%> (-0.04%) ⬇️
bip32_derivation-coverage 0.00% <ø> (ø)
buffer_sv2-coverage 25.02% <ø> (ø)
codec_sv2-coverage 0.01% <0.00%> (-0.01%) ⬇️
common_messages_sv2-coverage 0.13% <0.00%> (-0.01%) ⬇️
const_sv2-coverage 0.00% <0.00%> (ø)
error_handling-coverage 0.00% <ø> (ø)
framing_sv2-coverage 0.29% <0.00%> (-0.01%) ⬇️
jd_client-coverage 0.00% <0.00%> (ø)
jd_server-coverage 7.79% <ø> (ø)
job_declaration_sv2-coverage 0.00% <0.00%> (ø)
key-utils-coverage 2.39% <ø> (ø)
mining-coverage 2.55% <10.86%> (+0.05%) ⬆️
mining_device-coverage 0.00% <ø> (ø)
mining_proxy_sv2-coverage 0.70% <ø> (ø)
noise_sv2-coverage 4.33% <0.00%> (-0.03%) ⬇️
pool_sv2-coverage 1.38% <0.00%> (-0.01%) ⬇️
protocols 25.62% <51.78%> (+0.89%) ⬆️
roles 6.54% <0.00%> (-0.02%) ⬇️
roles_logic_sv2-coverage 9.67% <51.78%> (+1.60%) ⬆️
sv2_ffi-coverage 0.00% <0.00%> (ø)
template_distribution_sv2-coverage 0.00% <0.00%> (ø)
translator_sv2-coverage 9.57% <0.00%> (-0.03%) ⬇️
utils 25.13% <ø> (ø)
v1-coverage 2.45% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GitGab19
Copy link
Collaborator

add a method that the pool can use in order to change coinbase_script_additional_data of an already opened channel and send downstream the new extranonce_prefix

SInce we're going to use the extranonce_prefix for this addictional data, I think we should use the SetExtranoncePrefix message to achieve your third point here.

@Fi3
Copy link
Collaborator Author

Fi3 commented Nov 14, 2024

add a method that the pool can use in order to change coinbase_script_additional_data of an already opened channel and send downstream the new extranonce_prefix

SInce we're going to use the extranonce_prefix for this addictional data, I think we should use the SetExtranoncePrefix message to achieve your third point here.

thats the plan

@Fi3
Copy link
Collaborator Author

Fi3 commented Nov 14, 2024

add a method that the pool can use in order to change coinbase_script_additional_data of an already opened channel and send downstream the new extranonce_prefix

SInce we're going to use the extranonce_prefix for this addictional data, I think we should use the SetExtranoncePrefix message to achieve your third point here.

I'm implementing it, and we need to support at least 2 extranonce if we want to be able to change it while the miner is mining. That cause there will be short time frames where we have job for the new extranonce and job for the old extranonce. I realized that this is true also for the target. We do not support 2 target at the same time, and this is very likley what cause the very rare invalid shares that we observe during tests. I will do another PR to fix it.

@GitGab19
Copy link
Collaborator

GitGab19 commented Nov 14, 2024

I guess it would be better to wait you to push the SetExtranoncePrefix changes before doing a proper review, right? For now I ACK the appproach 👍

@Fi3 Fi3 changed the title [WIP] Improve coinbase Improve coinbase Nov 16, 2024
@Fi3 Fi3 force-pushed the ImproveCoinbase branch 3 times, most recently from 08cf9a2 to 6734198 Compare November 26, 2024 18:20
fi3 added 11 commits November 26, 2024 19:20
Coinbase signature is not part of the Sv2 protocol, some pool maybe want
to use it other not. The first part of the extranonce could also be
reserved for things that are not a pool signature. This pr rename the
pool_signature field of the channel factory into additional_coinbase_script_data
and change the type from Strgin to Vec<u8>, since can be anything.
The coinbase input script additional data should be sent as part of the
extranonce_prefix and not as part of the coinbase_prefix. So that a JDC
can see what the pool want as coinbase input script additional data
without the need to observ the coinbase prefix in job constructed by the
pool.
Update the pool to use an extranonce of 16 bytes rather then 32 so that
there is enaugh space to add the additional coinbase input script data.
Right now the channel factory only support one active job at time. That
means that if we receive a share for a job right after we sent downstream
a new job that share will be invalid. Now the channel factory keep track
of the last 3 jobs, so we give time to the dowstream to receive the job
and propagate it down before stop accepting shares for older job. This
is useful, and the system can be more responsive: as soon as we
change the coinbase additional input script data we can send a new job
dowsntream without worrying of invalidating miner's shares. When the
pool receive a prev hash it immidiatly invalidate all the previous jobs,
we still want to refuse shares for stale jobs. The client can easly handle
this situation: when a pool refuse a share it should start a timer and if do
not receive a new prev hash (or already have) within n seconds it change
pool.
This commit fix 2 miner things:

When we calculate the coinbase_prefix (what we need to put in the
extended job) we need to account also for the coinbase input script
additional data that is part of the extranonce.

When we create pool channel facotry we pass an extranonce creator and an
pool signature. If the signature + extranonce are bigger then 32 bytes
we have to return an error. That cause in sv2 the extranonce can not be
longer than 32 bytes.
The translator normalize the coinbase and remove the segwit data
from the coinbase prefix and suffix. In order to do that it need to know
the extranonce len, we used a default value of 322 bytes, but the pool
could use also smalle extranonces.
 Add a method that the pool can use in order to change
 coinbase_script_additional_data of an already opened
 channel and send downstream the new extranonce_prefix
@Fi3 Fi3 force-pushed the ImproveCoinbase branch 2 times, most recently from 4102974 to b2dd540 Compare November 27, 2024 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants