Skip to content

Commit 3a85972

Browse files
committed
Merge branch 'develop' of https://github.com/stacks-network/stacks-core into feat/mock-signature-aggregation
2 parents b4987f7 + 09c4b06 commit 3a85972

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3337
-1090
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
- tests::neon_integrations::confirm_unparsed_ongoing_ops
7373
- tests::neon_integrations::min_txs
7474
- tests::neon_integrations::vote_for_aggregate_key_burn_op_test
75+
- tests::neon_integrations::mock_miner_replay
7576
- tests::epoch_25::microblocks_disabled
7677
- tests::should_succeed_handling_malformed_and_valid_txs
7778
- tests::nakamoto_integrations::simple_neon_integration
@@ -96,6 +97,7 @@ jobs:
9697
- tests::signer::v0::signer_set_rollover
9798
- tests::signer::v0::miner_forking
9899
- tests::signer::v0::reloads_signer_set_in
100+
- tests::signer::v0::signers_broadcast_signed_blocks
99101
- tests::nakamoto_integrations::stack_stx_burn_op_integration_test
100102
- tests::nakamoto_integrations::check_block_heights
101103
- tests::nakamoto_integrations::clarity_burn_state

docs/rpc-endpoints.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ Determine whether a given trait is implemented within the specified contract (ei
427427

428428
See OpenAPI [spec](./rpc/openapi.yaml) for details.
429429

430-
### POST /v2/block_proposal
430+
### POST /v3/block_proposal
431431

432432
Used by miner to validate a proposed Stacks block using JSON encoding.
433433

libsigner/src/runloop.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub trait SignerRunLoop<R: Send, CMD: Send, T: SignerEventTrait> {
5353
&mut self,
5454
event: Option<SignerEvent<T>>,
5555
cmd: Option<CMD>,
56-
res: Sender<R>,
56+
res: &Sender<R>,
5757
) -> Option<R>;
5858

5959
/// This is the main loop body for the signer. It continuously receives events from
@@ -70,6 +70,7 @@ pub trait SignerRunLoop<R: Send, CMD: Send, T: SignerEventTrait> {
7070
result_send: Sender<R>,
7171
mut event_stop_signaler: EVST,
7272
) -> Option<R> {
73+
info!("Signer runloop begin");
7374
loop {
7475
let poll_timeout = self.get_event_timeout();
7576
let next_event_opt = match event_recv.recv_timeout(poll_timeout) {
@@ -83,7 +84,7 @@ pub trait SignerRunLoop<R: Send, CMD: Send, T: SignerEventTrait> {
8384
// Do not block for commands
8485
let next_command_opt = command_recv.try_recv().ok();
8586
if let Some(final_state) =
86-
self.run_one_pass(next_event_opt, next_command_opt, result_send.clone())
87+
self.run_one_pass(next_event_opt, next_command_opt, &result_send)
8788
{
8889
info!("Runloop exit; signaling event-receiver to stop");
8990
event_stop_signaler.send();

libsigner/src/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<T: SignerEventTrait> SignerRunLoop<Vec<SignerEvent<T>>, Command, T> for Sim
7676
&mut self,
7777
event: Option<SignerEvent<T>>,
7878
_cmd: Option<Command>,
79-
_res: Sender<Vec<SignerEvent<T>>>,
79+
_res: &Sender<Vec<SignerEvent<T>>>,
8080
) -> Option<Vec<SignerEvent<T>>> {
8181
debug!("Got event: {:?}", &event);
8282
if let Some(event) = event {

stacks-common/src/types/chainstate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ impl_byte_array_serde!(TrieHash);
3030

3131
pub const TRIEHASH_ENCODED_SIZE: usize = 32;
3232

33-
#[derive(Serialize, Deserialize)]
3433
pub struct BurnchainHeaderHash(pub [u8; 32]);
3534
impl_array_newtype!(BurnchainHeaderHash, u8, 32);
3635
impl_array_hexstring_fmt!(BurnchainHeaderHash);
3736
impl_byte_array_newtype!(BurnchainHeaderHash, u8, 32);
37+
impl_byte_array_serde!(BurnchainHeaderHash);
3838

3939
pub struct BlockHeaderHash(pub [u8; 32]);
4040
impl_array_newtype!(BlockHeaderHash, u8, 32);

stacks-common/src/util/macros.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,28 @@ macro_rules! impl_byte_array_serde {
617617
};
618618
}
619619

620+
#[allow(unused_macros)]
621+
#[macro_export]
622+
macro_rules! impl_file_io_serde_json {
623+
($thing:ident) => {
624+
impl $thing {
625+
pub fn serialize_to_file<P>(&self, path: P) -> Result<(), std::io::Error>
626+
where
627+
P: AsRef<std::path::Path>,
628+
{
629+
$crate::util::serialize_json_to_file(self, path)
630+
}
631+
632+
pub fn deserialize_from_file<P>(path: P) -> Result<Self, std::io::Error>
633+
where
634+
P: AsRef<std::path::Path>,
635+
{
636+
$crate::util::deserialize_json_from_file(path)
637+
}
638+
}
639+
};
640+
}
641+
620642
// print debug statements while testing
621643
#[allow(unused_macros)]
622644
#[macro_export]

stacks-common/src/util/mod.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ pub mod uint;
2828
pub mod vrf;
2929

3030
use std::collections::HashMap;
31+
use std::fs::File;
32+
use std::io::{BufReader, BufWriter, Write};
33+
use std::path::Path;
3134
use std::time::{SystemTime, UNIX_EPOCH};
3235
use std::{error, fmt, thread, time};
3336

@@ -120,3 +123,26 @@ pub mod db_common {
120123
true
121124
}
122125
}
126+
127+
/// Write any `serde_json` object directly to a file
128+
pub fn serialize_json_to_file<J, P>(json: &J, path: P) -> Result<(), std::io::Error>
129+
where
130+
J: ?Sized + serde::Serialize,
131+
P: AsRef<Path>,
132+
{
133+
let file = File::create(path)?;
134+
let mut writer = BufWriter::new(file);
135+
serde_json::to_writer(&mut writer, json)?;
136+
writer.flush()
137+
}
138+
139+
/// Read any `serde_json` object directly from a file
140+
pub fn deserialize_json_from_file<J, P>(path: P) -> Result<J, std::io::Error>
141+
where
142+
J: serde::de::DeserializeOwned,
143+
P: AsRef<Path>,
144+
{
145+
let file = File::open(path)?;
146+
let reader = BufReader::new(file);
147+
serde_json::from_reader::<_, J>(reader).map_err(std::io::Error::from)
148+
}

stacks-signer/src/client/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ pub(crate) mod tests {
570570
db_path: config.db_path.clone(),
571571
first_proposal_burn_block_timing: config.first_proposal_burn_block_timing,
572572
block_proposal_timeout: config.block_proposal_timeout,
573+
broadcast_signed_blocks: true,
573574
}
574575
}
575576

stacks-signer/src/client/stacks_client.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,13 @@ impl StacksClient {
685685
pub fn post_block(&self, block: &NakamotoBlock) -> Result<bool, ClientError> {
686686
let response = self
687687
.stacks_node_client
688-
.post(format!("{}{}", self.http_origin, postblock_v3::PATH))
688+
.post(format!(
689+
"{}{}?broadcast=1",
690+
self.http_origin,
691+
postblock_v3::PATH
692+
))
689693
.header("Content-Type", "application/octet-stream")
694+
.header(AUTHORIZATION, self.auth_password.clone())
690695
.body(block.serialize_to_vec())
691696
.send()?;
692697
if !response.status().is_success() {
@@ -789,7 +794,7 @@ impl StacksClient {
789794
}
790795

791796
fn block_proposal_path(&self) -> String {
792-
format!("{}/v2/block_proposal", self.http_origin)
797+
format!("{}/v3/block_proposal", self.http_origin)
793798
}
794799

795800
fn sortition_info_path(&self) -> String {
@@ -814,7 +819,7 @@ impl StacksClient {
814819
}
815820

816821
fn reward_set_path(&self, reward_cycle: u64) -> String {
817-
format!("{}/v2/stacker_set/{reward_cycle}", self.http_origin)
822+
format!("{}/v3/stacker_set/{reward_cycle}", self.http_origin)
818823
}
819824

820825
fn fees_transaction_path(&self) -> String {

stacks-signer/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ pub struct SignerConfig {
157157
pub first_proposal_burn_block_timing: Duration,
158158
/// How much time to wait for a miner to propose a block following a sortition
159159
pub block_proposal_timeout: Duration,
160+
/// Broadcast a block to the node if we gather enough signatures from other signers
161+
pub broadcast_signed_blocks: bool,
160162
}
161163

162164
/// The parsed configuration for the signer
@@ -201,6 +203,8 @@ pub struct GlobalConfig {
201203
pub first_proposal_burn_block_timing: Duration,
202204
/// How much time to wait for a miner to propose a block following a sortition
203205
pub block_proposal_timeout: Duration,
206+
/// Broadcast a block to the node if we gather enough signatures from other signers
207+
pub broadcast_signed_blocks: bool,
204208
}
205209

206210
/// Internal struct for loading up the config file
@@ -357,6 +361,7 @@ impl TryFrom<RawConfigFile> for GlobalConfig {
357361
metrics_endpoint,
358362
first_proposal_burn_block_timing,
359363
block_proposal_timeout,
364+
broadcast_signed_blocks: true,
360365
})
361366
}
362367
}

0 commit comments

Comments
 (0)