Skip to content

Fix timestamp bug - min_ntime becomes always the one sent by TP#1325

Merged
plebhash merged 4 commits into
stratum-mining:mainfrom
GitGab19:fix-timestamp-bug
Jan 8, 2025
Merged

Fix timestamp bug - min_ntime becomes always the one sent by TP#1325
plebhash merged 4 commits into
stratum-mining:mainfrom
GitGab19:fix-timestamp-bug

Conversation

@GitGab19

@GitGab19 GitGab19 commented Jan 2, 2025

Copy link
Copy Markdown
Member

This PR introduces a new last_ntime field into JobsCreators struct to save the last nTime value sent by TP.

In this way, the correct value is always used when creating new jobs (future and not), instead of using the current system time.

Closes #1324

@GitGab19 GitGab19 marked this pull request as draft January 2, 2025 12:51
@GitGab19

GitGab19 commented Jan 2, 2025

Copy link
Copy Markdown
Member Author

@plebhash @jbesraa do you think we need to add a new integration test for this? We are able to assert specific fields value inside specific messages, right?

Also, let me know if you want me to bump roles_logic_sv2 patch version here or not.

@github-actions

github-actions Bot commented Jan 2, 2025

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchfix-timestamp-bug
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,389.40
(-2.58%)
6,958.45
(91.82%)
client-submit-serialize-deserialize📈 view plot
🚷 view threshold
7,255.60
(-1.96%)
7,837.13
(92.58%)
client-submit-serialize-deserialize-handle/client-submit-serialize-deserialize-handle📈 view plot
🚷 view threshold
8,019.00
(-1.04%)
9,442.13
(84.93%)
client-sv1-authorize-serialize-deserialize-handle/client-sv1-authorize-serialize-deserialize-handle📈 view plot
🚷 view threshold
880.72
(+1.40%)
945.30
(93.17%)
client-sv1-authorize-serialize-deserialize/client-sv1-authorize-serialize-deserialize📈 view plot
🚷 view threshold
681.02
(+0.87%)
718.76
(94.75%)
client-sv1-authorize-serialize/client-sv1-authorize-serialize📈 view plot
🚷 view threshold
253.18
(+1.12%)
275.24
(91.99%)
client-sv1-get-authorize/client-sv1-get-authorize📈 view plot
🚷 view threshold
169.14
(+7.03%)
171.25
(98.77%)
client-sv1-get-submit📈 view plot
🚷 view threshold
6,259.40
(-1.42%)
6,812.98
(91.87%)
client-sv1-get-subscribe/client-sv1-get-subscribe📈 view plot
🚷 view threshold
305.85
(+7.57%)
334.39
(91.46%)
client-sv1-subscribe-serialize-deserialize-handle/client-sv1-subscribe-serialize-deserialize-handle📈 view plot
🚷 view threshold
729.83
(+0.22%)
780.78
(93.47%)
client-sv1-subscribe-serialize-deserialize/client-sv1-subscribe-serialize-deserialize📈 view plot
🚷 view threshold
618.84
(+4.37%)
637.37
(97.09%)
client-sv1-subscribe-serialize/client-sv1-subscribe-serialize📈 view plot
🚷 view threshold
205.57
(-0.63%)
226.62
(90.71%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jan 2, 2025

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchfix-timestamp-bug
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.34
(-2.00%)
60.47
(73.32%)
client_sv2_handle_message_mining📈 view plot
🚷 view threshold
92.52
(+18.05%)
111.82
(82.75%)
client_sv2_mining_message_submit_standard📈 view plot
🚷 view threshold
14.67
(+0.00%)
14.72
(99.60%)
client_sv2_mining_message_submit_standard_serialize📈 view plot
🚷 view threshold
252.42
(-4.64%)
290.74
(86.82%)
client_sv2_mining_message_submit_standard_serialize_deserialize📈 view plot
🚷 view threshold
609.28
(-1.02%)
657.60
(92.65%)
client_sv2_open_channel📈 view plot
🚷 view threshold
161.81
(-2.57%)
180.11
(89.84%)
client_sv2_open_channel_serialize📈 view plot
🚷 view threshold
283.02
(-0.90%)
311.22
(90.94%)
client_sv2_open_channel_serialize_deserialize📈 view plot
🚷 view threshold
382.25
(+0.06%)
400.26
(95.50%)
client_sv2_setup_connection📈 view plot
🚷 view threshold
158.65
(-0.80%)
171.26
(92.64%)
client_sv2_setup_connection_serialize📈 view plot
🚷 view threshold
471.25
(+0.16%)
557.86
(84.47%)
client_sv2_setup_connection_serialize_deserialize📈 view plot
🚷 view threshold
1,017.20
(+1.48%)
1,203.28
(84.54%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jan 2, 2025

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchfix-timestamp-bug
Testbedsv1
Click to view all benchmark results
BenchmarkEstimated CyclesBenchmark Result
1e3 x estimated cycles
(Result Δ%)
Upper Boundary
1e3 x estimated cycles
(Limit %)
InstructionsBenchmark Result
1e3 x instructions
(Result Δ%)
Upper Boundary
1e3 x instructions
(Limit %)
L1 AccessesBenchmark Result
1e3 x accesses
(Result Δ%)
Upper Boundary
1e3 x 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.45
(-0.07%)
8.67
(97.43%)
📈 view plot
🚷 view threshold
3.66
(-1.68%)
3.86
(94.87%)
📈 view plot
🚷 view threshold
5.11
(-2.05%)
5.45
(93.79%)
📈 view plot
🚷 view threshold
10.00
(+18.85%)
16.17
(61.85%)
📈 view plot
🚷 view threshold
94.00
(+2.93%)
96.64
(97.27%)
get_submit📈 view plot
🚷 view threshold
95.31
(-0.05%)
95.61
(99.69%)
📈 view plot
🚷 view threshold
59.26
(-0.24%)
59.71
(99.26%)
📈 view plot
🚷 view threshold
85.08
(-0.28%)
85.82
(99.14%)
📈 view plot
🚷 view threshold
45.00
(+0.88%)
60.05
(74.94%)
📈 view plot
🚷 view threshold
286.00
(+1.91%)
291.53
(98.10%)
get_subscribe📈 view plot
🚷 view threshold
7.92
(-0.95%)
8.23
(96.21%)
📈 view plot
🚷 view threshold
2.76
(-1.96%)
2.94
(93.72%)
📈 view plot
🚷 view threshold
3.83
(-2.31%)
4.14
(92.55%)
📈 view plot
🚷 view threshold
12.00
(-3.70%)
20.59
(58.28%)
📈 view plot
🚷 view threshold
115.00
(+0.42%)
117.87
(97.57%)
serialize_authorize📈 view plot
🚷 view threshold
12.26
(+0.04%)
12.50
(98.09%)
📈 view plot
🚷 view threshold
5.24
(-1.11%)
5.43
(96.58%)
📈 view plot
🚷 view threshold
7.28
(-1.38%)
7.60
(95.75%)
📈 view plot
🚷 view threshold
10.00
(-1.54%)
18.74
(53.36%)
📈 view plot
🚷 view threshold
141.00
(+2.24%)
143.04
(98.57%)
serialize_deserialize_authorize📈 view plot
🚷 view threshold
24.73
(+0.05%)
25.18
(98.18%)
📈 view plot
🚷 view threshold
9.79
(-0.73%)
10.01
(97.77%)
📈 view plot
🚷 view threshold
13.79
(-0.89%)
14.17
(97.27%)
📈 view plot
🚷 view threshold
32.00
(-10.92%)
45.95
(69.64%)
📈 view plot
🚷 view threshold
308.00
(+1.47%)
313.38
(98.28%)
serialize_deserialize_handle_authorize📈 view plot
🚷 view threshold
30.36
(+0.13%)
30.73
(98.82%)
📈 view plot
🚷 view threshold
11.99
(-0.51%)
12.19
(98.39%)
📈 view plot
🚷 view threshold
16.95
(-0.66%)
17.29
(98.00%)
📈 view plot
🚷 view threshold
58.00
(+3.80%)
67.61
(85.79%)
📈 view plot
🚷 view threshold
375.00
(+1.08%)
379.28
(98.87%)
serialize_deserialize_handle_submit📈 view plot
🚷 view threshold
126.55
(+0.08%)
126.78
(99.82%)
📈 view plot
🚷 view threshold
73.12
(-0.18%)
73.53
(99.43%)
📈 view plot
🚷 view threshold
104.76
(-0.23%)
105.51
(99.29%)
📈 view plot
🚷 view threshold
109.00
(+2.26%)
125.65
(86.75%)
📈 view plot
🚷 view threshold
607.00
(+1.56%)
610.12
(99.49%)
serialize_deserialize_handle_subscribe📈 view plot
🚷 view threshold
27.96
(+0.19%)
28.39
(98.51%)
📈 view plot
🚷 view threshold
9.58
(-0.57%)
9.76
(98.13%)
📈 view plot
🚷 view threshold
13.52
(-0.74%)
13.84
(97.67%)
📈 view plot
🚷 view threshold
69.00
(+6.81%)
78.12
(88.33%)
📈 view plot
🚷 view threshold
403.00
(+0.94%)
409.70
(98.37%)
serialize_deserialize_submit📈 view plot
🚷 view threshold
115.31
(+0.05%)
115.71
(99.65%)
📈 view plot
🚷 view threshold
67.89
(-0.24%)
68.42
(99.23%)
📈 view plot
🚷 view threshold
97.36
(-0.30%)
98.29
(99.05%)
📈 view plot
🚷 view threshold
69.00
(+5.67%)
87.14
(79.19%)
📈 view plot
🚷 view threshold
503.00
(+1.97%)
504.55
(99.69%)
serialize_deserialize_subscribe📈 view plot
🚷 view threshold
23.34
(+0.05%)
23.82
(97.98%)
📈 view plot
🚷 view threshold
8.13
(-0.70%)
8.32
(97.75%)
📈 view plot
🚷 view threshold
11.42
(-0.87%)
11.75
(97.25%)
📈 view plot
🚷 view threshold
38.00
(-2.35%)
50.87
(74.70%)
📈 view plot
🚷 view threshold
335.00
(+1.01%)
342.32
(97.86%)
serialize_submit📈 view plot
🚷 view threshold
99.80
(+0.02%)
100.09
(99.71%)
📈 view plot
🚷 view threshold
61.33
(-0.21%)
61.73
(99.34%)
📈 view plot
🚷 view threshold
87.93
(-0.26%)
88.65
(99.20%)
📈 view plot
🚷 view threshold
50.00
(+4.17%)
66.61
(75.06%)
📈 view plot
🚷 view threshold
332.00
(+2.05%)
337.18
(98.46%)
serialize_subscribe📈 view plot
🚷 view threshold
11.44
(+0.36%)
11.60
(98.66%)
📈 view plot
🚷 view threshold
4.11
(-1.24%)
4.28
(95.98%)
📈 view plot
🚷 view threshold
5.69
(-1.60%)
6.00
(94.88%)
📈 view plot
🚷 view threshold
16.00
(+15.58%)
23.92
(66.89%)
📈 view plot
🚷 view threshold
162.00
(+2.21%)
164.36
(98.57%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jan 2, 2025

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchfix-timestamp-bug
Testbedsv2
Click to view all benchmark results
BenchmarkEstimated CyclesBenchmark Result
1e3 x estimated cycles
(Result Δ%)
Upper Boundary
1e3 x 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.14
(+1.15%)
2.24
(95.61%)
📈 view plot
🚷 view threshold
473.00
(-0.12%)
490.70
(96.39%)
📈 view plot
🚷 view threshold
732.00
(-0.53%)
759.35
(96.40%)
📈 view plot
🚷 view threshold
8.00
(+56.81%)
11.89
(67.30%)
📈 view plot
🚷 view threshold
39.00
(+1.01%)
41.67
(93.59%)
client_sv2_handle_message_mining📈 view plot
🚷 view threshold
8.28
(+0.66%)
8.40
(98.60%)
📈 view plot
🚷 view threshold
2,137.00📈 view plot
🚷 view threshold
3,155.00
(-0.12%)
3,167.53
(99.60%)
📈 view plot
🚷 view threshold
38.00
(+6.67%)
41.82
(90.86%)
📈 view plot
🚷 view threshold
141.00
(+0.95%)
144.49
(97.59%)
client_sv2_mining_message_submit_standard📈 view plot
🚷 view threshold
6.32
(+0.35%)
6.45
(98.07%)
📈 view plot
🚷 view threshold
1,750.00
(-0.03%)
1,767.70
(99.00%)
📈 view plot
🚷 view threshold
2,548.00
(-0.15%)
2,575.89
(98.92%)
📈 view plot
🚷 view threshold
20.00
(+15.89%)
24.62
(81.24%)
📈 view plot
🚷 view threshold
105.00
(+0.34%)
108.72
(96.58%)
client_sv2_mining_message_submit_standard_serialize📈 view plot
🚷 view threshold
14.79
(+0.45%)
14.93
(99.03%)
📈 view plot
🚷 view threshold
4,694.00
(-0.01%)
4,711.70
(99.62%)
📈 view plot
🚷 view threshold
6,745.00
(-0.16%)
6,786.79
(99.38%)
📈 view plot
🚷 view threshold
55.00
(+20.59%)
62.79
(87.60%)
📈 view plot
🚷 view threshold
222.00
(+0.38%)
226.12
(98.18%)
client_sv2_mining_message_submit_standard_serialize_deserialize📈 view plot
🚷 view threshold
27.79
(+0.70%)
28.05
(99.07%)
📈 view plot
🚷 view threshold
10,645.00
(+0.37%)
10,696.90
(99.51%)
📈 view plot
🚷 view threshold
15,502.00
(+0.41%)
15,591.18
(99.43%)
📈 view plot
🚷 view threshold
92.00
(+9.94%)
98.92
(93.00%)
📈 view plot
🚷 view threshold
338.00
(+0.75%)
343.09
(98.52%)
client_sv2_open_channel📈 view plot
🚷 view threshold
4.49
(+2.02%)
4.57
(98.12%)
📈 view plot
🚷 view threshold
1,461.00
(-0.04%)
1,478.70
(98.80%)
📈 view plot
🚷 view threshold
2,154.00
(-0.31%)
2,184.92
(98.58%)
📈 view plot
🚷 view threshold
12.00
(+46.43%)
14.03
(85.51%)
📈 view plot
🚷 view threshold
65.00
(+3.47%)
67.54
(96.23%)
client_sv2_open_channel_serialize📈 view plot
🚷 view threshold
14.09
(+0.48%)
14.20
(99.22%)
📈 view plot
🚷 view threshold
5,064.00
(-0.01%)
5,081.70
(99.65%)
📈 view plot
🚷 view threshold
7,316.00
(-0.14%)
7,352.91
(99.50%)
📈 view plot
🚷 view threshold
45.00
(+23.10%)
48.29
(93.19%)
📈 view plot
🚷 view threshold
187.00
(+0.55%)
190.78
(98.02%)
client_sv2_open_channel_serialize_deserialize📈 view plot
🚷 view threshold
22.97
(+1.17%)
23.06
(99.62%)
📈 view plot
🚷 view threshold
8,040.00
(+0.10%)
8,057.34
(99.78%)
📈 view plot
🚷 view threshold
11,683.00
(-0.01%)
11,714.06
(99.73%)
📈 view plot
🚷 view threshold
87.00
(+14.84%)
89.83
(96.85%)
📈 view plot
🚷 view threshold
310.00
(+1.97%)
312.43
(99.22%)
client_sv2_setup_connection📈 view plot
🚷 view threshold
4.71
(+0.53%)
4.79
(98.44%)
📈 view plot
🚷 view threshold
1,502.00
(-0.04%)
1,519.70
(98.84%)
📈 view plot
🚷 view threshold
2,275.00
(-0.16%)
2,301.24
(98.86%)
📈 view plot
🚷 view threshold
12.00
(+26.94%)
15.42
(77.82%)
📈 view plot
🚷 view threshold
68.00
(+0.67%)
70.07
(97.05%)
client_sv2_setup_connection_serialize📈 view plot
🚷 view threshold
16.23
(+0.47%)
16.32
(99.43%)
📈 view plot
🚷 view threshold
5,963.00
(-0.01%)
5,980.70
(99.70%)
📈 view plot
🚷 view threshold
8,650.00
(-0.16%)
8,692.77
(99.51%)
📈 view plot
🚷 view threshold
53.00
(+30.64%)
56.13
(94.43%)
📈 view plot
🚷 view threshold
209.00
(+0.38%)
212.05
(98.56%)
client_sv2_setup_connection_serialize_deserialize📈 view plot
🚷 view threshold
35.76
(+0.44%)
35.95
(99.46%)
📈 view plot
🚷 view threshold
14,888.00
(+0.14%)
14,918.45
(99.80%)
📈 view plot
🚷 view threshold
21,866.00
(+0.11%)
21,917.87
(99.76%)
📈 view plot
🚷 view threshold
111.00
(+17.74%)
119.12
(93.18%)
📈 view plot
🚷 view threshold
381.00
(+0.37%)
385.70
(98.78%)
🐰 View full continuous benchmarking report in Bencher

@codecov

codecov Bot commented Jan 2, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 19.30%. Comparing base (5fec3f1) to head (fb70488).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1325      +/-   ##
==========================================
+ Coverage   18.61%   19.30%   +0.68%     
==========================================
  Files         144      164      +20     
  Lines        9718    10853    +1135     
==========================================
+ Hits         1809     2095     +286     
- Misses       7909     8758     +849     
Flag Coverage Δ
binary_codec_sv2-coverage 0.00% <ø> (ø)
binary_serde_sv2-coverage 3.65% <ø> (ø)
binary_sv2-coverage 5.48% <ø> (ø)
bip32_derivation-coverage 0.00% <ø> (?)
buffer_sv2-coverage 25.02% <ø> (?)
codec_sv2-coverage 0.01% <ø> (ø)
common_messages_sv2-coverage 0.13% <ø> (ø)
const_sv2-coverage ?
error_handling-coverage 0.00% <ø> (?)
framing_sv2-coverage 0.29% <ø> (ø)
jd_client-coverage 0.00% <ø> (ø)
jd_server-coverage 7.79% <ø> (ø)
job_declaration_sv2-coverage 0.00% <ø> (ø)
key-utils-coverage 2.39% <ø> (?)
mining-coverage 2.51% <ø> (ø)
mining_device-coverage 0.00% <ø> (ø)
mining_proxy_sv2-coverage 0.70% <ø> (ø)
noise_sv2-coverage 4.35% <ø> (ø)
pool_sv2-coverage 1.38% <ø> (ø)
protocols 24.74% <100.00%> (+0.01%) ⬆️
roles 6.54% <ø> (ø)
roles_logic_sv2-coverage 8.11% <100.00%> (+0.03%) ⬆️
sv2_ffi-coverage 0.00% <ø> (ø)
template_distribution_sv2-coverage 0.00% <ø> (ø)
translator_sv2-coverage 9.60% <ø> (ø)
v1-coverage 2.47% <ø> (ø)

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.

@plebhash

plebhash commented Jan 2, 2025

Copy link
Copy Markdown
Member

do you think we need to add a new integration test for this?

IMO more tests are always desirable 🙈

the real question is how complex it is to write a comprehensive test for this bug

if it is too complex and we decide it's not worth spending our time on it now, we could always take note of this on #1077 and come back to it later

We are able to assert specific fields value inside specific messages, right?

yes, see:

// 2. If you want to assert the message with its properties, you can invoke the macro with the
// message group, the nested message group, the message, the expected message, and the expected
// properties and values:
// `assert_message!(TemplateDistribution, TemplateDistribution, $msg, $expected_message_variant,
// $expected_property, $expected_property_value, ...);`.
// Note that you can provide any number of properties and values.

or a more concrete example:

assert_common_message!(
&sniffer.next_message_from_downstream(),
SetupConnection,
protocol,
Protocol::TemplateDistributionProtocol,
flags,
0,
min_version,
2,
max_version,
2
);

Also, let me know if you want me to bump roles_logic_sv2 patch version here or not.

are we doing a patch release for this bugfix?

if yes, then we should bump and release right away

if not, then we should take note of this change and then bump before v1.3.0 (maybe there will be a MAJOR or MINOR bump that would overwrite this)

@Sjors

Sjors commented Jan 3, 2025

Copy link
Copy Markdown
Collaborator

You should the curtime field, not mintime. For the timewarp scenario that this PR fixes, they're the same. But normally mintime is equal to MTP + 1, which on mainnet is typically an hour in the past. Whereas curtime is the node clock time, adjusted for MTP + 1 and for timewarp where needed.

@GitGab19

GitGab19 commented Jan 3, 2025

Copy link
Copy Markdown
Member Author

You should the curtime field, not mintime. For the timewarp scenario that this PR fixes, they're the same. But normally mintime is equal to MTP + 1, which on mainnet is typically an hour in the past. Whereas curtime is the node clock time, adjusted for MTP + 1 and for timewarp where needed.

I'm not following you here, weren't we saying that we should always use the timestamp communicated by the TP?

@Sjors

Sjors commented Jan 3, 2025

Copy link
Copy Markdown
Collaborator

Maybe I'm just confused by the name. The getblocktemplate RPC has both a curtime and mintime field. But the TP doesn't use that field and just gives you the nTime value in the block. That's not the minimum time, so the variable name mintime is confusing. But it should work correctly.

@GitGab19

GitGab19 commented Jan 3, 2025

Copy link
Copy Markdown
Member Author

What I'm using in this PR is the header_timestamp field contained in the SetNewPrevHash message, as specified here. It's correct, right?

Regarding the naming, do you think something could be improved in the specs?

@Sjors

Sjors commented Jan 3, 2025

Copy link
Copy Markdown
Collaborator

Yes, it's indeed header_timestamp.

The spec is clear:

The nTime field in the block header at which the client should start (usually current time). This is NOT the minimum valid nTime value.

Some part of the SRI codebase is calling it Some(referenced_job.min_ntime). I think that variable should be renamed from min_ntime to either ntime or header_timestamp.

Comment thread protocols/v2/roles-logic-sv2/src/job_creator.rs
Comment thread protocols/v2/roles-logic-sv2/src/job_creator.rs Outdated
@GitGab19

GitGab19 commented Jan 3, 2025

Copy link
Copy Markdown
Member Author

Yes, it's indeed header_timestamp.

The spec is clear:

The nTime field in the block header at which the client should start (usually current time). This is NOT the minimum valid nTime value.

Some part of the SRI codebase is calling it Some(referenced_job.min_ntime). I think that variable should be renamed from min_ntime to either ntime or header_timestamp.

I think that's because on the mining protocol specs is specified as min_ntime: https://github.com/stratum-mining/sv2-spec/blob/main/05-Mining-Protocol.md#5315-newminingjob-server---client

Don't you think we should enhance that part of the specs? I can push changes on this PR, but I think that if we agree on it, we should also clarify specs.

@Sjors

Sjors commented Jan 3, 2025

Copy link
Copy Markdown
Collaborator

Yes it makes sense to improve the spec there.

Smallest nTime value available for hashing for the new mining job.

There's currently no way to know this, unless we add a new field to the NewTemplate and/or SetNewPrevHash message.

@GitGab19

GitGab19 commented Jan 3, 2025

Copy link
Copy Markdown
Member Author

@GitGab19 GitGab19 force-pushed the fix-timestamp-bug branch 2 times, most recently from 23b6e17 to e4e5e61 Compare January 3, 2025 16:34
@GitGab19 GitGab19 marked this pull request as ready for review January 3, 2025 16:35
@GitGab19

GitGab19 commented Jan 3, 2025

Copy link
Copy Markdown
Member Author

@plebhash integration test added in e4e5e61.

Wrt version bumping, I would discuss about it during next dev call. So that we can better agree on the need about doing a patch release or not.

@Shourya742 Shourya742 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tack 4c97af4.

A major version bump will be required due to the change in the JobCreator struct:

@@ -27,6 +27,7 @@ pub struct JobsCreators {
    templte_to_job_id: HashMap<u64, u32, BuildNoHashHasher<u64>>,
    ids: Id,
    last_target: mining_sv2::Target,
+   last_ntime: Option<u32>,
    extranonce_len: u8,
}

However, the rest of the changes do not affect any public APIs.

Comment thread roles/tests-integration/tests/pool_integration.rs Outdated
Comment thread roles/tests-integration/tests/pool_integration.rs
Comment thread protocols/v2/roles-logic-sv2/src/job_creator.rs Outdated

@jbesraa jbesraa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is really great to see you using the integration tests!

Added a few nits mainly in that regard.

Comment thread roles/tests-integration/tests/common/mod.rs Outdated
Comment thread roles/tests-integration/tests/pool_integration.rs Outdated
Comment thread roles/tests-integration/tests/pool_integration.rs Outdated
Comment thread roles/tests-integration/tests/pool_integration.rs Outdated
Comment thread protocols/v2/roles-logic-sv2/src/job_creator.rs
@GitGab19 GitGab19 force-pushed the fix-timestamp-bug branch 3 times, most recently from 2416330 to b53152c Compare January 7, 2025 16:29
@GitGab19

GitGab19 commented Jan 7, 2025

Copy link
Copy Markdown
Member Author

Thanks everyone for reviewing it 🙏 , I addressed almost every comment.

The last thing which needs to be done in this PR is to bump the crate version in its Cargo.toml. According to @Shourya742's comment here we should bump MAJOR, but cargo-semver-check is not failing on that.

I'm diving into it, will post updates here asap.

@plebhash

plebhash commented Jan 7, 2025

Copy link
Copy Markdown
Member

I did some local manual testing for the semver issue:

  • make sure cargo semver-checks is 0.37.0 (same as CI)
    • cargo +stable install cargo-semver-checks --version 0.37.0 --locked
  • run the tool on roles_logic_sv2
    • cd protocols/v2/roles-logic-sv2; cargo +stable semver-checks --default-features

(the +stable was used because my local cargo is locked on MSRV, while CI runs on stable)

no errors were reported

it's very good that @Shourya742 had the eagle eyes to detect this potential versioning issue, but we should definitely investigate deeper to know if:

  • @Shourya742 was mistaken and a PATCH bump is sufficient
  • OR we need to fix the CI, as it's not reliable

@plebhash

plebhash commented Jan 8, 2025

Copy link
Copy Markdown
Member

for future reference:

after some investigation, it was confirmed that the semver issue was a false alarm

although the JobsCreators is a public struct, the added field is private, which therefore does not categorize a MAJOR version bump

@plebhash plebhash merged commit dbc349b into stratum-mining:main Jan 8, 2025
@GitGab19 GitGab19 deleted the fix-timestamp-bug branch July 7, 2025 16:26
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.

Pool and JDC update nTime field with current timestamp - they should use the one sent by TP

5 participants