Skip to content

Commit ca979c4

Browse files
committed
capnp: add Mining.submitBlock() method
1 parent b186f51 commit ca979c4

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,45 @@ async fn mining_block_template_lifecycle() {
374374
.await;
375375
}
376376

377+
/// submitBlock with a template block should be rejected (unsolved high-hash).
378+
#[tokio::test]
379+
#[serial_test::serial]
380+
async fn mining_submit_block() {
381+
let path = unix_socket_path();
382+
let rpc_network = connect_unix_stream(path).await;
383+
let rpc_system = RpcSystem::new(Box::new(rpc_network), None);
384+
LocalSet::new()
385+
.run_until(async move {
386+
let (client, thread) = bootstrap(rpc_system).await;
387+
let mining = make_mining(&client, &thread).await;
388+
let template = make_block_template(&mining, &thread).await;
389+
390+
let mut get_block_req = template.get_block_request();
391+
get_block_req
392+
.get()
393+
.get_context()
394+
.unwrap()
395+
.set_thread(thread.clone());
396+
let get_block_resp = get_block_req.send().promise.await.unwrap();
397+
let block = get_block_resp.get().unwrap().get_result().unwrap().to_vec();
398+
399+
let mut req = mining.submit_block_request();
400+
req.get().get_context().unwrap().set_thread(thread.clone());
401+
req.get().set_block(&block);
402+
let resp = req.send().promise.await.unwrap();
403+
let results = resp.get().unwrap();
404+
assert!(
405+
!results.get_result(),
406+
"unsolved template block must not be accepted"
407+
);
408+
let _reason = results.get_reason().unwrap();
409+
let _debug = results.get_debug().unwrap();
410+
411+
destroy_template(&template, &thread).await;
412+
})
413+
.await;
414+
}
415+
377416
/// checkBlock with a template block payload, and interrupt.
378417
#[tokio::test]
379418
// Serialized because interrupt() can affect other in-flight mining waits.

0 commit comments

Comments
 (0)