Skip to content

Commit 06c2efc

Browse files
authored
Merge branch 'next' into feat/ci-build-docker-signer
2 parents 00a6e63 + abbead4 commit 06c2efc

File tree

11 files changed

+1027
-169
lines changed

11 files changed

+1027
-169
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libsigner/src/runloop.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,8 @@ pub trait SignerRunLoop<R: Send, CMD: Send> {
7979
return None;
8080
}
8181
};
82-
let next_command_opt = match command_recv.recv_timeout(poll_timeout) {
83-
Ok(cmd) => Some(cmd),
84-
Err(RecvTimeoutError::Timeout) => None,
85-
Err(RecvTimeoutError::Disconnected) => {
86-
info!("Command receiver disconnected");
87-
return None;
88-
}
89-
};
82+
// Do not block for commands
83+
let next_command_opt = command_recv.try_recv().ok();
9084
if let Some(final_state) =
9185
self.run_one_pass(next_event_opt, next_command_opt, result_send.clone())
9286
{

stacks-signer/src/client/stackerdb.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
use blockstack_lib::burnchains::Txid;
1716
use blockstack_lib::chainstate::nakamoto::NakamotoBlock;
1817
use blockstack_lib::net::api::postblock_proposal::{BlockValidateReject, ValidateRejectCode};
1918
use clarity::vm::types::QualifiedContractIdentifier;
@@ -78,6 +77,17 @@ pub struct BlockRejection {
7877
pub block: NakamotoBlock,
7978
}
8079

80+
impl BlockRejection {
81+
/// Create a new BlockRejection for the provided block and reason code
82+
pub fn new(block: NakamotoBlock, reason_code: RejectCode) -> Self {
83+
Self {
84+
reason: reason_code.to_string(),
85+
reason_code,
86+
block,
87+
}
88+
}
89+
}
90+
8191
impl From<BlockValidateReject> for BlockRejection {
8292
fn from(reject: BlockValidateReject) -> Self {
8393
Self {
@@ -94,8 +104,22 @@ impl From<BlockValidateReject> for BlockRejection {
94104
pub enum RejectCode {
95105
/// RPC endpoint Validation failed
96106
ValidationFailed(ValidateRejectCode),
97-
/// Missing expected transactions
98-
MissingTransactions(Vec<Txid>),
107+
/// Signers signed a block rejection
108+
SignedRejection,
109+
/// Invalid signature hash
110+
InvalidSignatureHash,
111+
}
112+
113+
impl std::fmt::Display for RejectCode {
114+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
115+
match self {
116+
RejectCode::ValidationFailed(code) => write!(f, "Validation failed: {:?}", code),
117+
RejectCode::SignedRejection => {
118+
write!(f, "A threshold number of signers rejected the block.")
119+
}
120+
RejectCode::InvalidSignatureHash => write!(f, "The signature hash was invalid."),
121+
}
122+
}
99123
}
100124

101125
impl From<Packet> for SignerMessage {
@@ -116,6 +140,12 @@ impl From<BlockRejection> for SignerMessage {
116140
}
117141
}
118142

143+
impl From<BlockValidateReject> for SignerMessage {
144+
fn from(rejection: BlockValidateReject) -> Self {
145+
Self::BlockResponse(BlockResponse::Rejected(rejection.into()))
146+
}
147+
}
148+
119149
impl SignerMessage {
120150
/// Helper function to determine the slot ID for the provided stacker-db writer id
121151
pub fn slot_id(&self, id: u32) -> u32 {

stacks-signer/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use wsts::state_machine::PublicKeys;
3636
/// List of key_ids for each signer_id
3737
pub type SignerKeyIds = HashMap<u32, Vec<u32>>;
3838

39-
const EVENT_TIMEOUT_MS: u64 = 50;
39+
const EVENT_TIMEOUT_MS: u64 = 5000;
4040

4141
#[derive(thiserror::Error, Debug)]
4242
/// An error occurred parsing the provided configuration

stacks-signer/src/main.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ use std::path::{Path, PathBuf};
3333
use std::sync::mpsc::{channel, Receiver, Sender};
3434
use std::time::Duration;
3535

36+
use blockstack_lib::chainstate::nakamoto::NakamotoBlock;
3637
use clap::Parser;
3738
use clarity::vm::types::QualifiedContractIdentifier;
3839
use libsigner::{RunningSigner, Signer, SignerEventReceiver, SignerSession, StackerDBSession};
3940
use libstackerdb::StackerDBChunkData;
40-
use slog::slog_debug;
41+
use slog::{slog_debug, slog_error};
4142
use stacks_common::address::{
4243
AddressHashMode, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG,
4344
};
44-
use stacks_common::debug;
45+
use stacks_common::codec::read_next;
4546
use stacks_common::types::chainstate::{StacksAddress, StacksPrivateKey, StacksPublicKey};
47+
use stacks_common::{debug, error};
4648
use stacks_signer::cli::{
4749
Cli, Command, GenerateFilesArgs, GetChunkArgs, GetLatestChunkArgs, PutChunkArgs, RunDkgArgs,
4850
SignArgs, StackerDBArgs,
@@ -204,10 +206,15 @@ fn handle_dkg(args: RunDkgArgs) {
204206
fn handle_sign(args: SignArgs) {
205207
debug!("Signing message...");
206208
let spawned_signer = spawn_running_signer(&args.config);
209+
let Some(block) = read_next::<NakamotoBlock, _>(&mut &args.data[..]).ok() else {
210+
error!("Unable to parse provided message as a NakamotoBlock.");
211+
spawned_signer.running_signer.stop();
212+
return;
213+
};
207214
spawned_signer
208215
.cmd_send
209216
.send(RunLoopCommand::Sign {
210-
message: args.data,
217+
block,
211218
is_taproot: false,
212219
merkle_root: None,
213220
})
@@ -220,12 +227,17 @@ fn handle_sign(args: SignArgs) {
220227
fn handle_dkg_sign(args: SignArgs) {
221228
debug!("Running DKG and signing message...");
222229
let spawned_signer = spawn_running_signer(&args.config);
230+
let Some(block) = read_next::<NakamotoBlock, _>(&mut &args.data[..]).ok() else {
231+
error!("Unable to parse provided message as a NakamotoBlock.");
232+
spawned_signer.running_signer.stop();
233+
return;
234+
};
223235
// First execute DKG, then sign
224236
spawned_signer.cmd_send.send(RunLoopCommand::Dkg).unwrap();
225237
spawned_signer
226238
.cmd_send
227239
.send(RunLoopCommand::Sign {
228-
message: args.data,
240+
block,
229241
is_taproot: false,
230242
merkle_root: None,
231243
})

0 commit comments

Comments
 (0)