Skip to content

Commit 4a5f461

Browse files
committed
Merge branch '2025/10/test-fails'
2 parents 6264449 + aacc04d commit 4a5f461

File tree

9 files changed

+45
-398
lines changed

9 files changed

+45
-398
lines changed

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
To keep the repository tidy and easy to maintain, automated agents should follow these principles:
44

55
- **Follow established style.** Consult the developer guidelines in [`doc/developer-notes.md`](doc/developer-notes.md) before writing or editing code. Adhere to the documented formatting, naming, and documentation conventions unless the project maintainers request otherwise.
6+
- **Mind indentation-sensitive formats.** When touching YAML, Python, Markdown lists, or other whitespace-aware files, preserve the existing indentation levels and continuation alignment. Prefer editing tools like `apply_patch` that keep surrounding context intact, and re-read the affected block before saving to avoid shifting keys or breaking workflows.
67
- **Delete obsolete source files.** When retiring code, prefer removing the corresponding files outright instead of leaving stub implementations (for example, those containing only `#error` guards).
78
- **Confirm large refactors.** When a deletion task appears to require non-trivial refactoring elsewhere, pause and ask for confirmation first—consider whether removing the code you're about to refactor is a better alternative.
89
- **Update build metadata.** After deleting files, ensure any build scripts, project files, or documentation lists referencing them are updated accordingly.

contrib/devtools/README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,6 @@ For example:
134134
BUILDDIR=$PWD/my-build-dir contrib/devtools/gen-manpages.py
135135
```
136136

137-
headerssync-params.py
138-
=====================
139-
140-
A script to generate optimal parameters for the headerssync module (src/headerssync.cpp). It takes no command-line
141-
options, as all its configuration is set at the top of the file. It runs many times faster inside PyPy. Invocation:
142-
143-
```bash
144-
pypy3 contrib/devtools/headerssync-params.py
145-
```
146-
147137
gen-bitcoin-conf.sh
148138
===================
149139

contrib/devtools/headerssync-params.py

Lines changed: 0 additions & 357 deletions
This file was deleted.

src/sv2/template_provider.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include <util/thread.h>
1313
#include <streams.h>
1414

15+
#include <algorithm>
16+
#include <limits>
17+
1518
Sv2TemplateProvider::Sv2TemplateProvider(interfaces::Mining& mining) : m_mining{mining}
1619
{
1720
// TODO: persist static key
@@ -72,11 +75,12 @@ Sv2TemplateProvider::Sv2TemplateProvider(interfaces::Mining& mining) : m_mining{
7275
LogTrace(BCLog::SV2, "Authority key: %s\n", HexStr(m_authority_pubkey));
7376

7477
// Generate and sign certificate
75-
auto now{GetTime<std::chrono::seconds>()};
76-
uint16_t version = 0;
78+
const int64_t now_seconds{std::max<int64_t>(GetTime<std::chrono::seconds>().count(), 0)};
7779
// Start validity a little bit in the past to account for clock difference
78-
uint32_t valid_from = static_cast<uint32_t>(std::chrono::duration_cast<std::chrono::seconds>(now).count()) - 3600;
79-
uint32_t valid_to = std::numeric_limits<unsigned int>::max(); // 2106
80+
const int64_t backdated{std::max<int64_t>(now_seconds - int64_t{3600}, 0)};
81+
const uint32_t valid_from{static_cast<uint32_t>(std::min<int64_t>(backdated, std::numeric_limits<uint32_t>::max()))};
82+
const uint32_t valid_to{std::numeric_limits<uint32_t>::max()}; // 2106
83+
uint16_t version = 0;
8084
Sv2SignatureNoiseMessage certificate = Sv2SignatureNoiseMessage(version, valid_from, valid_to, XOnlyPubKey(static_key.GetPubKey()), authority_key);
8185

8286
m_connman = std::make_unique<Sv2Connman>(TP_SUBPROTOCOL, static_key, m_authority_pubkey, certificate);

src/test/sv2_connman_tests.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ class ConnTester : Sv2EventsInterface {
4343
m_connman_authority_pubkey = XOnlyPubKey(authority_key.GetPubKey());
4444

4545
// Generate and sign certificate
46-
auto now{GetTime<std::chrono::seconds>()};
47-
uint16_t version = 0;
48-
// Start validity a little bit in the past to account for clock difference
49-
uint32_t valid_from = static_cast<uint32_t>(std::chrono::duration_cast<std::chrono::seconds>(now).count()) - 3600;
50-
uint32_t valid_to = std::numeric_limits<unsigned int>::max(); // 2106
51-
Sv2SignatureNoiseMessage certificate{version, valid_from, valid_to, XOnlyPubKey(static_key.GetPubKey()), authority_key};
46+
uint32_t now_secs{0};
47+
uint32_t valid_from{0};
48+
uint32_t valid_to{0};
49+
Sv2SignatureNoiseMessage certificate = MakeSkewTolerantCertificate(static_key, authority_key, now_secs, valid_from, valid_to);
5250

5351
m_connman = std::make_unique<Sv2Connman>(TP_SUBPROTOCOL, static_key, m_connman_authority_pubkey, certificate);
5452

src/test/sv2_mock_mining.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
#ifndef BITCOIN_TEST_SV2_MOCK_MINING_H
66
#define BITCOIN_TEST_SV2_MOCK_MINING_H
77

8-
#include <interfaces/mining.h>
9-
#include <script/script.h>
10-
#include <sync.h>
11-
#include <uint256.h>
12-
#include <primitives/transaction.h>
13-
148
#include <condition_variable>
159
#include <memory>
1610
#include <mutex>
1711
#include <queue>
1812
#include <vector>
1913

14+
#include <interfaces/mining.h>
15+
#include <primitives/transaction.h>
16+
#include <script/script.h>
17+
#include <sync.h>
18+
#include <uint256.h>
19+
2020
// Minimal mocks for the Mining IPC interface used by sv2 tests.
2121

2222
struct MockEvent {

src/test/sv2_test_setup.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Sv2BasicTestingSetup::Sv2BasicTestingSetup()
1818
// Select a default chain for tests to satisfy BaseParams() users.
1919
SelectBaseParams(ChainType::REGTEST);
2020

21+
// Default mock time anchored to Bitcoin genesis so certificate helpers see a realistic clock.
22+
SetMockTime(TEST_GENESIS_TIME);
23+
2124
// Create an isolated temporary datadir for this test process.
2225
const auto micros = count_microseconds(Now<SteadyMicroseconds>().time_since_epoch());
2326
const std::string subdir = util::Join(std::array<std::string, 2>{"sv2_tests", util::ToString(micros)}, "");
@@ -37,6 +40,8 @@ Sv2BasicTestingSetup::Sv2BasicTestingSetup()
3740

3841
Sv2BasicTestingSetup::~Sv2BasicTestingSetup()
3942
{
43+
SetMockTime(std::chrono::seconds{0});
44+
4045
try {
4146
fs::remove_all(m_tmp_root);
4247
} catch (const std::exception&) {

src/test/sv2_test_setup.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
#ifndef BITCOIN_TEST_SV2_TEST_SETUP_H
66
#define BITCOIN_TEST_SV2_TEST_SETUP_H
77

8-
#include <test/util/random.h>
9-
#include <util/fs.h>
10-
#include <memory>
8+
#include <algorithm>
119
#include <chrono>
1210
#include <limits>
11+
#include <memory>
1312

14-
// SV2 noise / keys
15-
#include <sv2/noise.h>
1613
#include <key.h>
14+
#include <sv2/noise.h>
15+
#include <test/util/random.h>
16+
#include <util/fs.h>
17+
#include <util/time.h>
1718

1819
/**
1920
* Helper to build a skew-tolerant test certificate.
@@ -33,14 +34,22 @@ inline Sv2SignatureNoiseMessage MakeSkewTolerantCertificate(const CKey& static_k
3334
uint32_t backdate_secs = 3600,
3435
uint16_t version = 0)
3536
{
36-
auto epoch_now = std::chrono::system_clock::now().time_since_epoch();
37-
out_now = static_cast<uint32_t>(std::chrono::duration_cast<std::chrono::seconds>(epoch_now).count());
38-
out_valid_from = out_now - backdate_secs; // tolerate backward jumps / skew
37+
const auto now = GetTime<std::chrono::seconds>();
38+
const int64_t now_count = now.count();
39+
const int64_t clamped_now = std::max<int64_t>(0, now_count);
40+
out_now = static_cast<uint32_t>(clamped_now);
41+
42+
const int64_t backdated = std::max<int64_t>(0, clamped_now - static_cast<int64_t>(backdate_secs));
43+
out_valid_from = static_cast<uint32_t>(backdated);
3944
out_valid_to = std::numeric_limits<unsigned int>::max();
45+
4046
return Sv2SignatureNoiseMessage(version, out_valid_from, out_valid_to,
4147
XOnlyPubKey(static_key.GetPubKey()), authority_key);
4248
}
4349

50+
//! Default mock time for SV2 unit tests: Bitcoin genesis block timestamp (2009-01-03).
51+
inline constexpr std::chrono::seconds TEST_GENESIS_TIME{1231006505};
52+
4453

4554
class ECC_Context;
4655

src/test/sv2_transport_tests.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,10 @@ class Sv2TransportTester
5959
auto responder_authority_key{GenerateRandomKey()};
6060

6161
// Create certificates
62-
auto epoch_now = std::chrono::system_clock::now().time_since_epoch();
63-
uint16_t version = 0;
64-
uint32_t valid_from = static_cast<uint32_t>(std::chrono::duration_cast<std::chrono::seconds>(epoch_now).count());
65-
uint32_t valid_to = std::numeric_limits<unsigned int>::max();
66-
67-
auto responder_certificate = Sv2SignatureNoiseMessage(version, valid_from, valid_to,
68-
XOnlyPubKey(responder_static_key.GetPubKey()), responder_authority_key);
62+
uint32_t now_secs{0};
63+
uint32_t valid_from{0};
64+
uint32_t valid_to{0};
65+
auto responder_certificate = MakeSkewTolerantCertificate(responder_static_key, responder_authority_key, now_secs, valid_from, valid_to);
6966

7067
if (test_initiator) {
7168
m_transport = std::make_unique<Sv2Transport>(initiator_static_key, XOnlyPubKey(responder_authority_key.GetPubKey()));

0 commit comments

Comments
 (0)