Skip to content

Commit 076b0f3

Browse files
committed
Update capnp schemas to match Bitcoin Core master (pre-31.x)
Sync capnp proto files with Bitcoin Core master (e09b81638ba1). bitcoin/bitcoin#33819 (mining: getCoinbase() returns struct instead of raw tx) mining.capnp: - BlockTemplate.getCoinbaseTx now returns CoinbaseTx struct (was Data) - Added CoinbaseTx struct with fields: tx, txFee, totalFee, blockReservedWeight, coinbaseOutputMaxAdditionalSigops, defaultSignetChallenge, defaultWitnessCommitment - Added constants: maxMoney, maxDouble, defaultBlockReservedWeight, defaultCoinbaseOutputMaxAdditionalSigops - Added default values to all struct fields (BlockTemplateOptions, Amount, CoinbaseTx) bitcoin/bitcoin#34568 (mining: Break compatibility with existing IPC mining clients) init.capnp: - makeMining renumbered from @2 to @3 - Added deprecated makeMiningOld2 @2 placeholder (Cap'n Proto requires sequential ordinals, so this cannot be removed) mining.capnp: - Mining: removed getCoinbaseCommitment and getWitnessCommitmentIndex - Mining: added interrupt @6 - BlockTemplate: methods renumbered (@5 through @9) bitcoin/bitcoin#34184 (mining: add cooldown to createNewBlock() immediately after IBD) mining.capnp: - Mining.createNewBlock: added context @3, cooldown @4 params - Mining.checkBlock: added context @2 param - Mining.createNewBlock: timeout now has default value (60000000) Also adds make_mining_old2_rejected integration test verifying that the server returns an error for the deprecated method.
1 parent 82d765b commit 076b0f3

File tree

3 files changed

+53
-18
lines changed

3 files changed

+53
-18
lines changed

capnp/init.capnp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ using Mining = import "mining.capnp";
1414
interface Init $Proxy.wrap("interfaces::Init") {
1515
construct @0 (threadMap: Proxy.ThreadMap) -> (threadMap :Proxy.ThreadMap);
1616
makeEcho @1 (context :Proxy.Context) -> (result :Echo.Echo);
17-
makeMining @2 (context :Proxy.Context) -> (result :Mining.Mining);
17+
makeMiningOld2 @2 () -> ();
18+
makeMining @3 (context :Proxy.Context) -> (result :Mining.Mining);
1819
}

capnp/mining.capnp

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ $Cxx.namespace("ipc::capnp::messages");
1010
using Common = import "common.capnp";
1111
using Proxy = import "proxy.capnp";
1212

13+
const maxMoney :Int64 = 2100000000000000;
14+
const maxDouble :Float64 = 1.7976931348623157e308;
15+
const defaultBlockReservedWeight :UInt32 = 8000;
16+
const defaultCoinbaseOutputMaxAdditionalSigops :UInt32 = 400;
17+
1318
interface Mining $Proxy.wrap("interfaces::Mining") {
1419
isTestChain @0 (context :Proxy.Context) -> (result: Bool);
1520
isInitialBlockDownload @1 (context :Proxy.Context) -> (result: Bool);
1621
getTip @2 (context :Proxy.Context) -> (result: Common.BlockRef, hasResult: Bool);
17-
waitTipChanged @3 (context :Proxy.Context, currentTip: Data, timeout: Float64) -> (result: Common.BlockRef);
18-
createNewBlock @4 (options: BlockCreateOptions) -> (result: BlockTemplate);
19-
checkBlock @5 (block: Data, options: BlockCheckOptions) -> (reason: Text, debug: Text, result: Bool);
22+
waitTipChanged @3 (context :Proxy.Context, currentTip: Data, timeout: Float64 = .maxDouble) -> (result: Common.BlockRef);
23+
createNewBlock @4 (context :Proxy.Context, options: BlockCreateOptions, cooldown: Bool = true) -> (result: BlockTemplate);
24+
checkBlock @5 (context :Proxy.Context, block: Data, options: BlockCheckOptions) -> (reason: Text, debug: Text, result: Bool);
25+
interrupt @6 () -> ();
2026
}
2127

2228
interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") {
@@ -25,27 +31,35 @@ interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") {
2531
getBlock @2 (context: Proxy.Context) -> (result: Data);
2632
getTxFees @3 (context: Proxy.Context) -> (result: List(Int64));
2733
getTxSigops @4 (context: Proxy.Context) -> (result: List(Int64));
28-
getCoinbaseTx @5 (context: Proxy.Context) -> (result: Data);
29-
getCoinbaseCommitment @6 (context: Proxy.Context) -> (result: Data);
30-
getWitnessCommitmentIndex @7 (context: Proxy.Context) -> (result: Int32);
31-
getCoinbaseMerklePath @8 (context: Proxy.Context) -> (result: List(Data));
32-
submitSolution @9 (context: Proxy.Context, version: UInt32, timestamp: UInt32, nonce: UInt32, coinbase :Data) -> (result: Bool);
33-
waitNext @10 (context: Proxy.Context, options: BlockWaitOptions) -> (result: BlockTemplate);
34-
interruptWait @11() -> ();
34+
getCoinbaseTx @5 (context: Proxy.Context) -> (result: CoinbaseTx);
35+
getCoinbaseMerklePath @6 (context: Proxy.Context) -> (result: List(Data));
36+
submitSolution @7 (context: Proxy.Context, version: UInt32, timestamp: UInt32, nonce: UInt32, coinbase :Data) -> (result: Bool);
37+
waitNext @8 (context: Proxy.Context, options: BlockWaitOptions) -> (result: BlockTemplate);
38+
interruptWait @9() -> ();
3539
}
3640

3741
struct BlockCreateOptions $Proxy.wrap("node::BlockCreateOptions") {
38-
useMempool @0 :Bool $Proxy.name("use_mempool");
39-
blockReservedWeight @1 :UInt64 $Proxy.name("block_reserved_weight");
40-
coinbaseOutputMaxAdditionalSigops @2 :UInt64 $Proxy.name("coinbase_output_max_additional_sigops");
42+
useMempool @0 :Bool = true $Proxy.name("use_mempool");
43+
blockReservedWeight @1 :UInt64 = .defaultBlockReservedWeight $Proxy.name("block_reserved_weight");
44+
coinbaseOutputMaxAdditionalSigops @2 :UInt64 = .defaultCoinbaseOutputMaxAdditionalSigops $Proxy.name("coinbase_output_max_additional_sigops");
4145
}
4246

4347
struct BlockWaitOptions $Proxy.wrap("node::BlockWaitOptions") {
44-
timeout @0 : Float64 $Proxy.name("timeout");
45-
feeThreshold @1 : Int64 $Proxy.name("fee_threshold");
48+
timeout @0 : Float64 = .maxDouble $Proxy.name("timeout");
49+
feeThreshold @1 : Int64 = .maxMoney $Proxy.name("fee_threshold");
4650
}
4751

4852
struct BlockCheckOptions $Proxy.wrap("node::BlockCheckOptions") {
49-
checkMerkleRoot @0 :Bool $Proxy.name("check_merkle_root");
50-
checkPow @1 :Bool $Proxy.name("check_pow");
53+
checkMerkleRoot @0 :Bool = true $Proxy.name("check_merkle_root");
54+
checkPow @1 :Bool = true $Proxy.name("check_pow");
55+
}
56+
57+
struct CoinbaseTx $Proxy.wrap("node::CoinbaseTx") {
58+
version @0 :UInt32 $Proxy.name("version");
59+
sequence @1 :UInt32 $Proxy.name("sequence");
60+
scriptSigPrefix @2 :Data $Proxy.name("script_sig_prefix");
61+
witness @3 :Data $Proxy.name("witness");
62+
blockRewardRemaining @4 :Int64 $Proxy.name("block_reward_remaining");
63+
requiredOutputs @5 :List(Data) $Proxy.name("required_outputs");
64+
lockTime @6 :UInt32 $Proxy.name("lock_time");
5165
}

tests/test.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,23 @@ async fn integration() {
9797
})
9898
.await;
9999
}
100+
101+
/// Calling the deprecated makeMiningOld2 (@2) should return an error from the
102+
/// server. Cap'n Proto requires sequential ordinals so this placeholder cannot
103+
/// be removed, but the server intentionally rejects it.
104+
#[tokio::test]
105+
async fn make_mining_old2_rejected() {
106+
let path = unix_socket_path();
107+
let rpc_network = connect_unix_stream(path).await;
108+
let rpc_system = RpcSystem::new(Box::new(rpc_network), None);
109+
LocalSet::new()
110+
.run_until(async move {
111+
let (client, _thread) = bootstrap(rpc_system).await;
112+
let result = client.make_mining_old2_request().send().promise.await;
113+
assert!(
114+
result.is_err(),
115+
"makeMiningOld2 should be rejected by the server"
116+
);
117+
})
118+
.await;
119+
}

0 commit comments

Comments
 (0)