Skip to content

Commit ef45a38

Browse files
committed
chore: Address Aaron's comments
1 parent f6314e6 commit ef45a38

File tree

3 files changed

+14
-38
lines changed

3 files changed

+14
-38
lines changed

stacks-signer/src/signerdb.rs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,12 @@ use wsts::net::NonceRequest;
3939
pub struct BlockInfoV1 {
4040
/// The associated packet nonce request if we have one
4141
pub nonce_request: Option<NonceRequest>,
42-
/// Whether this block is already being signed over
43-
pub signed_over: bool,
4442
}
4543

4644
impl From<NonceRequest> for BlockInfoV1 {
4745
fn from(value: NonceRequest) -> Self {
4846
Self {
4947
nonce_request: Some(value),
50-
signed_over: true,
5148
}
5249
}
5350
}
@@ -65,23 +62,6 @@ pub enum ExtraBlockInfo {
6562
}
6663

6764
impl ExtraBlockInfo {
68-
/// Get `signed_over` if it exists
69-
pub fn get_signed_over(&self) -> Option<bool> {
70-
match self {
71-
ExtraBlockInfo::None | ExtraBlockInfo::V0 => None,
72-
ExtraBlockInfo::V1(v1) => Some(v1.signed_over),
73-
}
74-
}
75-
/// Set `signed_over` if it exists
76-
pub fn set_signed_over(&mut self, value: bool) -> Result<(), &str> {
77-
match self {
78-
ExtraBlockInfo::None | ExtraBlockInfo::V0 => Err("Field doesn't exist"),
79-
ExtraBlockInfo::V1(v1) => {
80-
v1.signed_over = value;
81-
Ok(())
82-
}
83-
}
84-
}
8565
/// Take `nonce_request` if it exists
8666
pub fn take_nonce_request(&mut self) -> Option<NonceRequest> {
8767
match self {
@@ -114,6 +94,8 @@ pub struct BlockInfo {
11494
pub vote: Option<NakamotoBlockVote>,
11595
/// Whether the block contents are valid
11696
pub valid: Option<bool>,
97+
/// Whether this block is already being signed over
98+
pub signed_over: bool,
11799
/// Time at which the proposal was received by this signer (epoch time in seconds)
118100
pub proposed_time: u64,
119101
/// Time at which the proposal was signed by this signer (epoch time in seconds)
@@ -132,6 +114,7 @@ impl From<BlockProposal> for BlockInfo {
132114
reward_cycle: value.reward_cycle,
133115
vote: None,
134116
valid: None,
117+
signed_over: false,
135118
proposed_time: get_epoch_time_secs(),
136119
signed_self: None,
137120
signed_group: None,
@@ -144,15 +127,16 @@ impl BlockInfo {
144127
pub fn new_v1_with_request(block_proposal: BlockProposal, nonce_request: NonceRequest) -> Self {
145128
let mut block_info = BlockInfo::from(block_proposal);
146129
block_info.ext = ExtraBlockInfo::V1(BlockInfoV1::from(nonce_request));
130+
block_info.signed_over = true;
147131
block_info
148132
}
149133

150134
/// Mark this block as valid, signed over, and record a timestamp in the block info if it wasn't
151135
/// already set.
152136
pub fn mark_signed_and_valid(&mut self) {
153137
self.valid = Some(true);
138+
self.signed_over = true;
154139
self.signed_self.get_or_insert(get_epoch_time_secs());
155-
_ = self.ext.set_signed_over(true);
156140
}
157141

158142
/// Return the block's signer signature hash
@@ -407,7 +391,7 @@ impl SignerDb {
407391
serde_json::to_string(&block_info).expect("Unable to serialize block info");
408392
let hash = &block_info.signer_signature_hash();
409393
let block_id = &block_info.block.block_id();
410-
let signed_over = &block_info.ext.get_signed_over().unwrap_or(false);
394+
let signed_over = &block_info.signed_over;
411395
let vote = block_info
412396
.vote
413397
.as_ref()
@@ -604,8 +588,6 @@ mod tests {
604588
let db_path = tmp_db_path();
605589
let mut db = SignerDb::new(db_path).expect("Failed to create signer db");
606590
let (mut block_info, block_proposal) = create_block();
607-
// We'll need the V1 data fields for this
608-
block_info.ext = ExtraBlockInfo::V1(BlockInfoV1::default());
609591
db.insert_block(&block_info).unwrap();
610592

611593
assert!(db

stacks-signer/src/v1/signer.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ impl Signer {
586586
.block_lookup(self.reward_cycle, &signer_signature_hash)
587587
.unwrap_or_else(|_| Some(BlockInfo::from(block_proposal.clone())))
588588
.unwrap_or_else(|| BlockInfo::from(block_proposal.clone()));
589-
if block_info.ext.get_signed_over().unwrap_or(false) {
589+
if block_info.signed_over {
590590
debug!("{self}: Received a sign command for a block we are already signing over. Ignore it.");
591591
return;
592592
}
@@ -603,9 +603,7 @@ impl Signer {
603603
Ok(msg) => {
604604
let ack = self.stackerdb_manager.send_message_with_retry(msg.into());
605605
debug!("{self}: ACK: {ack:?}",);
606-
block_info.ext.set_signed_over(true).unwrap_or_else(|e| {
607-
error!("{self}: `set_signed_over()` failed: {e:?}");
608-
});
606+
block_info.signed_over = true;
609607
self.signer_db
610608
.insert_block(&block_info)
611609
.unwrap_or_else(|e| {
@@ -709,7 +707,7 @@ impl Signer {
709707
"{self}: Received a block validate response";
710708
"block_hash" => block_info.block.header.block_hash(),
711709
"valid" => block_info.valid,
712-
"signed_over" => block_info.ext.get_signed_over(),
710+
"signed_over" => block_info.signed_over,
713711
);
714712
self.signer_db
715713
.insert_block(&block_info)

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use stacks_common::util::hash::{to_hex, Hash160, Sha512Trunc256Sum};
8989
use stacks_common::util::secp256k1::{MessageSignature, Secp256k1PrivateKey, Secp256k1PublicKey};
9090
use stacks_common::util::{get_epoch_time_secs, sleep_ms};
9191
use stacks_signer::chainstate::{ProposalEvalConfig, SortitionsView};
92-
use stacks_signer::signerdb::{BlockInfo, BlockInfoV1, ExtraBlockInfo, SignerDb};
92+
use stacks_signer::signerdb::{BlockInfo, ExtraBlockInfo, SignerDb};
9393
use wsts::net::Message;
9494

9595
use super::bitcoin_regtest::BitcoinCoreController;
@@ -4714,13 +4714,11 @@ fn signer_chainstate() {
47144714
reward_cycle,
47154715
vote: None,
47164716
valid: Some(true),
4717+
signed_over: true,
47174718
proposed_time: get_epoch_time_secs(),
47184719
signed_self: None,
47194720
signed_group: None,
4720-
ext: ExtraBlockInfo::V1(BlockInfoV1 {
4721-
nonce_request: None,
4722-
signed_over: true,
4723-
}),
4721+
ext: ExtraBlockInfo::None,
47244722
})
47254723
.unwrap();
47264724

@@ -4791,13 +4789,11 @@ fn signer_chainstate() {
47914789
reward_cycle,
47924790
vote: None,
47934791
valid: Some(true),
4792+
signed_over: true,
47944793
proposed_time: get_epoch_time_secs(),
47954794
signed_self: None,
47964795
signed_group: None,
4797-
ext: ExtraBlockInfo::V1(BlockInfoV1 {
4798-
nonce_request: None,
4799-
signed_over: true,
4800-
}),
4796+
ext: ExtraBlockInfo::None,
48014797
})
48024798
.unwrap();
48034799

0 commit comments

Comments
 (0)