Skip to content

Commit b407807

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

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
@@ -235,6 +235,45 @@ 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+
let path = unix_socket_path();
243+
let rpc_network = connect_unix_stream(path).await;
244+
let rpc_system = RpcSystem::new(Box::new(rpc_network), None);
245+
LocalSet::new()
246+
.run_until(async move {
247+
let (client, thread) = bootstrap(rpc_system).await;
248+
let mining = make_mining(&client, &thread).await;
249+
let template = make_block_template(&mining, &thread).await;
250+
251+
let mut get_block_req = template.get_block_request();
252+
get_block_req
253+
.get()
254+
.get_context()
255+
.unwrap()
256+
.set_thread(thread.clone());
257+
let get_block_resp = get_block_req.send().promise.await.unwrap();
258+
let block = get_block_resp.get().unwrap().get_result().unwrap().to_vec();
259+
260+
let mut req = mining.submit_block_request();
261+
req.get().get_context().unwrap().set_thread(thread.clone());
262+
req.get().set_block(&block);
263+
let resp = req.send().promise.await.unwrap();
264+
let results = resp.get().unwrap();
265+
assert!(
266+
!results.get_result(),
267+
"unsolved template block must not be accepted"
268+
);
269+
let _reason = results.get_reason().unwrap();
270+
let _debug = results.get_debug().unwrap();
271+
272+
destroy_template(&template, &thread).await;
273+
})
274+
.await;
275+
}
276+
238277
/// checkBlock with a template block payload, and interrupt.
239278
#[tokio::test]
240279
// Serialized because interrupt() can affect other in-flight mining waits.

0 commit comments

Comments
 (0)