Skip to content

Commit 8836dba

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feat/fork-detection-state-machine
2 parents 2abb5cd + 5efe165 commit 8836dba

31 files changed

+1723
-106
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1515
### Changed
1616

1717
- Reduce the default `block_rejection_timeout_steps` configuration so that miners will retry faster when blocks fail to reach 70% approved or 30% rejected.
18+
- Added index for `next_ready_nakamoto_block()` which improves block processing performance.
1819
- Added a new field, `parent_burn_block_hash`, to the payload that is included in the `/new_burn_block` event observer payload.
1920

2021
## [3.1.0.0.8]

Cargo.lock

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libsigner/src/events.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ struct BlockEvent {
610610
#[serde(with = "prefix_hex")]
611611
index_block_hash: StacksBlockId,
612612
#[serde(with = "prefix_opt_hex")]
613+
#[serde(default)]
613614
signer_signature_hash: Option<Sha512Trunc256Sum>,
614615
#[serde(with = "prefix_hex")]
615616
consensus_hash: ConsensusHash,

stacks-signer/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1111

1212
- Upgraded `SUPPORTED_SIGNER_PROTOCOL_VERSION` to 1
1313

14+
## [3.1.0.0.8.1]
15+
16+
### Added
17+
18+
- The signer will now check if their associated stacks-node has processed the parent block for a block proposal before submitting that block proposal. If it cannot confirm that the parent block has been processed, it waits a default time of 15s before submitting, configurable via `proposal_wait_for_parent_time_secs` in the signer config.toml.
19+
1420
## [3.1.0.0.8.0]
1521

1622
### Changed

stacks-signer/src/chainstate.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ pub struct ProposalEvalConfig {
141141
/// Time following the last block of the previous tenure's global acceptance that a signer will consider an attempt by
142142
/// the new miner to reorg it as valid towards miner activity
143143
pub reorg_attempts_activity_timeout: Duration,
144+
/// Time to wait before submitting a block proposal to the stacks-node
145+
pub proposal_wait_for_parent_time: Duration,
144146
}
145147

146148
impl From<&SignerConfig> for ProposalEvalConfig {
@@ -152,6 +154,7 @@ impl From<&SignerConfig> for ProposalEvalConfig {
152154
tenure_idle_timeout: value.tenure_idle_timeout,
153155
reorg_attempts_activity_timeout: value.reorg_attempts_activity_timeout,
154156
tenure_idle_timeout_buffer: value.tenure_idle_timeout_buffer,
157+
proposal_wait_for_parent_time: value.proposal_wait_for_parent_time,
155158
}
156159
}
157160
}

stacks-signer/src/client/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ pub(crate) mod tests {
418418
tenure_idle_timeout_buffer: config.tenure_idle_timeout_buffer,
419419
block_proposal_max_age_secs: config.block_proposal_max_age_secs,
420420
reorg_attempts_activity_timeout: config.reorg_attempts_activity_timeout,
421+
proposal_wait_for_parent_time: config.proposal_wait_for_parent_time,
421422
}
422423
}
423424

stacks-signer/src/config.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const DEFAULT_REORG_ATTEMPTS_ACTIVITY_TIMEOUT_MS: u64 = 200_000;
4545
/// Default number of seconds to add to the tenure extend time, after computing the idle timeout,
4646
/// to allow for clock skew between the signer and the miner
4747
const DEFAULT_TENURE_IDLE_TIMEOUT_BUFFER_SECS: u64 = 2;
48+
/// Default time (in ms) to wait before submitting a proposal if we
49+
/// cannot determine that our stacks-node has processed the parent
50+
/// block
51+
const DEFAULT_PROPOSAL_WAIT_TIME_FOR_PARENT_SECS: u64 = 15;
4852

4953
#[derive(thiserror::Error, Debug)]
5054
/// An error occurred parsing the provided configuration
@@ -175,6 +179,9 @@ pub struct SignerConfig {
175179
pub reorg_attempts_activity_timeout: Duration,
176180
/// The running mode for the signer (dry-run or normal)
177181
pub signer_mode: SignerConfigMode,
182+
/// Time to wait before submitting a block proposal to the stacks-node if we cannot
183+
/// determine that the stacks-node has processed the parent
184+
pub proposal_wait_for_parent_time: Duration,
178185
}
179186

180187
/// The parsed configuration for the signer
@@ -221,6 +228,9 @@ pub struct GlobalConfig {
221228
/// Time following the last block of the previous tenure's global acceptance that a signer will consider an attempt by
222229
/// the new miner to reorg it as valid towards miner activity
223230
pub reorg_attempts_activity_timeout: Duration,
231+
/// Time to wait before submitting a block proposal to the stacks-node if we cannot
232+
/// determine that the stacks-node has processed the parent
233+
pub proposal_wait_for_parent_time: Duration,
224234
/// Is this signer binary going to be running in dry-run mode?
225235
pub dry_run: bool,
226236
}
@@ -268,6 +278,8 @@ struct RawConfigFile {
268278
/// Time (in millisecs) following a block's global acceptance that a signer will consider an attempt by a miner
269279
/// to reorg the block as valid towards miner activity
270280
pub reorg_attempts_activity_timeout_ms: Option<u64>,
281+
/// Time to wait (in millisecs) before submitting a block proposal to the stacks-node
282+
pub proposal_wait_for_parent_time_secs: Option<u64>,
271283
/// Is this signer binary going to be running in dry-run mode?
272284
pub dry_run: Option<bool>,
273285
}
@@ -385,6 +397,12 @@ impl TryFrom<RawConfigFile> for GlobalConfig {
385397
.unwrap_or(DEFAULT_TENURE_IDLE_TIMEOUT_BUFFER_SECS),
386398
);
387399

400+
let proposal_wait_for_parent_time = Duration::from_secs(
401+
raw_data
402+
.proposal_wait_for_parent_time_secs
403+
.unwrap_or(DEFAULT_PROPOSAL_WAIT_TIME_FOR_PARENT_SECS),
404+
);
405+
388406
Ok(Self {
389407
node_host: raw_data.node_host,
390408
endpoint,
@@ -405,6 +423,7 @@ impl TryFrom<RawConfigFile> for GlobalConfig {
405423
reorg_attempts_activity_timeout,
406424
dry_run,
407425
tenure_idle_timeout_buffer,
426+
proposal_wait_for_parent_time,
408427
})
409428
}
410429
}

stacks-signer/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ pub trait Signer<T: SignerEventTrait>: Debug + Display {
7878
fn has_unprocessed_blocks(&self) -> bool;
7979
/// Get a reference to the local state machine of the signer
8080
fn get_local_state_machine(&self) -> &LocalStateMachine;
81+
/// Get the number of pending block proposals
82+
fn get_pending_proposals_count(&self) -> u64;
8183
}
8284

8385
/// A wrapper around the running signer type for the signer

stacks-signer/src/runloop.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub struct StateInfo {
5656
/// The local state machines for the running signers
5757
/// as a pair of (reward-cycle, state-machine)
5858
pub signer_state_machines: Vec<(u64, Option<LocalStateMachine>)>,
59+
/// The number of pending block proposals for this signer
60+
pub pending_proposals_count: u64,
5961
}
6062

6163
/// The signer result that can be sent across threads
@@ -320,6 +322,7 @@ impl<Signer: SignerTrait<T>, T: StacksMessageCodec + Clone + Send + Debug> RunLo
320322
tenure_idle_timeout_buffer: self.config.tenure_idle_timeout_buffer,
321323
block_proposal_max_age_secs: self.config.block_proposal_max_age_secs,
322324
reorg_attempts_activity_timeout: self.config.reorg_attempts_activity_timeout,
325+
proposal_wait_for_parent_time: self.config.proposal_wait_for_parent_time,
323326
}))
324327
}
325328

@@ -529,6 +532,17 @@ impl<Signer: SignerTrait<T>, T: StacksMessageCodec + Clone + Send + Debug>
529532
)
530533
})
531534
.collect(),
535+
pending_proposals_count: self
536+
.stacks_signers
537+
.values()
538+
.find_map(|signer| {
539+
if let ConfiguredSigner::RegisteredSigner(signer) = signer {
540+
Some(signer.get_pending_proposals_count())
541+
} else {
542+
None
543+
}
544+
})
545+
.unwrap_or(0),
532546
};
533547
info!("Signer status check requested: {state_info:?}");
534548

stacks-signer/src/signerdb.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,12 +1301,18 @@ impl SignerDb {
13011301
/// If found, remove it from the pending table.
13021302
pub fn get_and_remove_pending_block_validation(
13031303
&self,
1304-
) -> Result<Option<Sha512Trunc256Sum>, DBError> {
1305-
let qry = "DELETE FROM block_validations_pending WHERE signer_signature_hash = (SELECT signer_signature_hash FROM block_validations_pending ORDER BY added_time ASC LIMIT 1) RETURNING signer_signature_hash";
1304+
) -> Result<Option<(Sha512Trunc256Sum, u64)>, DBError> {
1305+
let qry = "DELETE FROM block_validations_pending WHERE signer_signature_hash = (SELECT signer_signature_hash FROM block_validations_pending ORDER BY added_time ASC LIMIT 1) RETURNING signer_signature_hash, added_time";
13061306
let args = params![];
13071307
let mut stmt = self.db.prepare(qry)?;
1308-
let sighash: Option<String> = stmt.query_row(args, |row| row.get(0)).optional()?;
1309-
Ok(sighash.and_then(|sighash| Sha512Trunc256Sum::from_hex(&sighash).ok()))
1308+
let result: Option<(String, i64)> = stmt
1309+
.query_row(args, |row| Ok((row.get(0)?, row.get(1)?)))
1310+
.optional()?;
1311+
Ok(result.and_then(|(sighash, ts_i64)| {
1312+
let signer_sighash = Sha512Trunc256Sum::from_hex(&sighash).ok()?;
1313+
let ts = u64::try_from(ts_i64).ok()?;
1314+
Some((signer_sighash, ts))
1315+
}))
13101316
}
13111317

13121318
/// Remove a pending block validation
@@ -2275,20 +2281,29 @@ pub mod tests {
22752281
db.insert_pending_block_validation(&Sha512Trunc256Sum([0x03; 32]), 3000)
22762282
.unwrap();
22772283

2278-
let pending_hash = db.get_and_remove_pending_block_validation().unwrap();
2279-
assert_eq!(pending_hash, Some(Sha512Trunc256Sum([0x01; 32])));
2284+
let (pending_hash, _) = db
2285+
.get_and_remove_pending_block_validation()
2286+
.unwrap()
2287+
.unwrap();
2288+
assert_eq!(pending_hash, Sha512Trunc256Sum([0x01; 32]));
22802289

22812290
let pendings = db.get_all_pending_block_validations().unwrap();
22822291
assert_eq!(pendings.len(), 2);
22832292

2284-
let pending_hash = db.get_and_remove_pending_block_validation().unwrap();
2285-
assert_eq!(pending_hash, Some(Sha512Trunc256Sum([0x02; 32])));
2293+
let (pending_hash, _) = db
2294+
.get_and_remove_pending_block_validation()
2295+
.unwrap()
2296+
.unwrap();
2297+
assert_eq!(pending_hash, Sha512Trunc256Sum([0x02; 32]));
22862298

22872299
let pendings = db.get_all_pending_block_validations().unwrap();
22882300
assert_eq!(pendings.len(), 1);
22892301

2290-
let pending_hash = db.get_and_remove_pending_block_validation().unwrap();
2291-
assert_eq!(pending_hash, Some(Sha512Trunc256Sum([0x03; 32])));
2302+
let (pending_hash, _) = db
2303+
.get_and_remove_pending_block_validation()
2304+
.unwrap()
2305+
.unwrap();
2306+
assert_eq!(pending_hash, Sha512Trunc256Sum([0x03; 32]));
22922307

22932308
let pendings = db.get_all_pending_block_validations().unwrap();
22942309
assert!(pendings.is_empty());

0 commit comments

Comments
 (0)