Skip to content

Commit fa5ca24

Browse files
committed
capnp: add Mining.submitBlock() method
1 parent b3db9fa commit fa5ca24

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

capnp/mining.capnp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interface Mining $Proxy.wrap("interfaces::Mining") {
2323
createNewBlock @4 (context :Proxy.Context, options: BlockCreateOptions, cooldown: Bool = true) -> (result: BlockTemplate);
2424
checkBlock @5 (context :Proxy.Context, block: Data, options: BlockCheckOptions) -> (reason: Text, debug: Text, result: Bool);
2525
interrupt @6 () -> ();
26+
submitBlock @7 (context :Proxy.Context, block: Data) -> (reason: Text, debug: Text, result: Bool);
2627
}
2728

2829
interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") {

tests/test.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,39 @@ async fn mining_block_template_lifecycle() {
235235
.await;
236236
}
237237

238+
/// submitBlock with a template block should be rejected (unsolved high-hash).
239+
#[tokio::test]
240+
#[serial_test::serial]
241+
async fn mining_submit_block() {
242+
with_mining_client(|_client, thread, mining| async move {
243+
let template = make_block_template(&mining, &thread).await;
244+
245+
let mut get_block_req = template.get_block_request();
246+
get_block_req
247+
.get()
248+
.get_context()
249+
.unwrap()
250+
.set_thread(thread.clone());
251+
let get_block_resp = get_block_req.send().promise.await.unwrap();
252+
let block = get_block_resp.get().unwrap().get_result().unwrap().to_vec();
253+
254+
let mut req = mining.submit_block_request();
255+
req.get().get_context().unwrap().set_thread(thread.clone());
256+
req.get().set_block(&block);
257+
let resp = req.send().promise.await.unwrap();
258+
let results = resp.get().unwrap();
259+
assert!(
260+
!results.get_result(),
261+
"unsolved template block must not be accepted"
262+
);
263+
let _reason = results.get_reason().unwrap();
264+
let _debug = results.get_debug().unwrap();
265+
266+
destroy_template(&template, &thread).await;
267+
})
268+
.await;
269+
}
270+
238271
/// checkBlock with a template block payload, and interrupt.
239272
#[tokio::test]
240273
// Serialized because interrupt() can affect other in-flight mining waits.

0 commit comments

Comments
 (0)