Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ jobs:
key: ccache-${{ runner.os }}-${{ github.sha }}
restore-keys: ccache-${{ runner.os }}-
- name: Checkout Bitcoin Core
run: git clone --depth 1 --branch master https://github.com/bitcoin/bitcoin.git
run: |
git clone --depth 1 https://github.com/bitcoin/bitcoin.git
# DO NOT MERGE: switch to bitcoin/bitcoin#33922 PR branch
cd bitcoin
git fetch --depth 1 origin pull/33922/head:pr-33922
git checkout pr-33922
- name: Build Bitcoin Core
run: |
cd bitcoin
Expand Down
6 changes: 6 additions & 0 deletions capnp/mining.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface Mining $Proxy.wrap("interfaces::Mining") {
createNewBlock @4 (context :Proxy.Context, options: BlockCreateOptions, cooldown: Bool = true) -> (result: BlockTemplate);
checkBlock @5 (context :Proxy.Context, block: Data, options: BlockCheckOptions) -> (reason: Text, debug: Text, result: Bool);
interrupt @6 () -> ();
submitBlock @7 (context :Proxy.Context, block: Data) -> (reason: Text, debug: Text, result: Bool);
getMemoryLoad @8 (context :Proxy.Context) -> (result: MemoryLoad);
}

interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") {
Expand All @@ -44,6 +46,10 @@ struct BlockCreateOptions $Proxy.wrap("node::BlockCreateOptions") {
coinbaseOutputMaxAdditionalSigops @2 :UInt64 = .defaultCoinbaseOutputMaxAdditionalSigops $Proxy.name("coinbase_output_max_additional_sigops");
}

struct MemoryLoad $Proxy.wrap("interfaces::MemoryLoad") {
usage @0 :UInt64;
}

struct BlockWaitOptions $Proxy.wrap("node::BlockWaitOptions") {
timeout @0 : Float64 = .maxDouble $Proxy.name("timeout");
feeThreshold @1 : Int64 = .maxMoney $Proxy.name("fee_threshold");
Expand Down
42 changes: 41 additions & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn mining_constants() {
);
}

/// isTestChain, isInitialBlockDownload, getTip.
/// isTestChain, isInitialBlockDownload, getTip, getMemoryLoad.
#[tokio::test]
#[serial_test::parallel]
async fn mining_basic_queries() {
Expand All @@ -96,6 +96,13 @@ async fn mining_basic_queries() {
let tip_hash = tip.get_hash().unwrap();
assert_eq!(tip_hash.len(), 32, "block hash must be 32 bytes");
assert!(tip.get_height() >= 0, "height must be non-negative");

// getMemoryLoad
let mut req = mining.get_memory_load_request();
req.get().get_context().unwrap().set_thread(thread.clone());
let resp = req.send().promise.await.unwrap();
let memory_load = resp.get().unwrap().get_result().unwrap();
let _usage: u64 = memory_load.get_usage();
})
.await;
}
Expand Down Expand Up @@ -235,6 +242,39 @@ async fn mining_block_template_lifecycle() {
.await;
}

/// submitBlock with a template block should be rejected (unsolved high-hash).
#[tokio::test]
#[serial_test::serial]
async fn mining_submit_block() {
with_mining_client(|_client, thread, mining| async move {
let template = make_block_template(&mining, &thread).await;

let mut get_block_req = template.get_block_request();
get_block_req
.get()
.get_context()
.unwrap()
.set_thread(thread.clone());
let get_block_resp = get_block_req.send().promise.await.unwrap();
let block = get_block_resp.get().unwrap().get_result().unwrap().to_vec();

let mut req = mining.submit_block_request();
req.get().get_context().unwrap().set_thread(thread.clone());
req.get().set_block(&block);
let resp = req.send().promise.await.unwrap();
let results = resp.get().unwrap();
assert!(
!results.get_result(),
"unsolved template block must not be accepted"
);
let _reason = results.get_reason().unwrap();
let _debug = results.get_debug().unwrap();

destroy_template(&template, &thread).await;
})
.await;
}

/// checkBlock with a template block payload, and interrupt.
#[tokio::test]
// Serialized because interrupt() can affect other in-flight mining waits.
Expand Down
Loading