Skip to content

Commit a3cdab6

Browse files
committed
Merge branch 'fix/5285' into feat/shadow-block-tooling
2 parents eebf10d + a7e89bc commit a3cdab6

File tree

20 files changed

+837
-116
lines changed

20 files changed

+837
-116
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ jobs:
141141
- tests::nakamoto_integrations::v3_signer_api_endpoint
142142
- tests::nakamoto_integrations::test_shadow_recovery
143143
- tests::nakamoto_integrations::signer_chainstate
144+
- tests::nakamoto_integrations::clarity_cost_spend_down
144145
# TODO: enable these once v1 signer is supported by a new nakamoto epoch
145146
# - tests::signer::v1::dkg
146147
# - tests::signer::v1::sign_request_rejected

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1212
- Remove the panic for reporting DB deadlocks (just error and continue waiting)
1313
- Add index to `metadata_table` in Clarity DB on `blockhash`
1414
- Add `block_commit_delay_ms` to the config file to control the time to wait after seeing a new burn block, before submitting a block commit, to allow time for the first Nakamoto block of the new tenure to be mined, allowing this miner to avoid the need to RBF the block commit.
15+
- Add `tenure_cost_limit_per_block_percentage` to the miner config file to control the percentage remaining tenure cost limit to consume per nakamoto block.
1516

1617
## [3.0.0.0.1]
1718

clarity/src/vm/costs/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ impl LimitedCostTracker {
896896
Self::Free => ExecutionCost::max_value(),
897897
}
898898
}
899+
899900
pub fn get_memory(&self) -> u64 {
900901
match self {
901902
Self::Limited(TrackerData { memory, .. }) => *memory,
@@ -1170,6 +1171,7 @@ pub trait CostOverflowingMath<T> {
11701171
fn cost_overflow_mul(self, other: T) -> Result<T>;
11711172
fn cost_overflow_add(self, other: T) -> Result<T>;
11721173
fn cost_overflow_sub(self, other: T) -> Result<T>;
1174+
fn cost_overflow_div(self, other: T) -> Result<T>;
11731175
}
11741176

11751177
impl CostOverflowingMath<u64> for u64 {
@@ -1185,6 +1187,10 @@ impl CostOverflowingMath<u64> for u64 {
11851187
self.checked_sub(other)
11861188
.ok_or_else(|| CostErrors::CostOverflow)
11871189
}
1190+
fn cost_overflow_div(self, other: u64) -> Result<u64> {
1191+
self.checked_div(other)
1192+
.ok_or_else(|| CostErrors::CostOverflow)
1193+
}
11881194
}
11891195

11901196
impl ExecutionCost {
@@ -1293,6 +1299,15 @@ impl ExecutionCost {
12931299
Ok(())
12941300
}
12951301

1302+
pub fn divide(&mut self, divisor: u64) -> Result<()> {
1303+
self.runtime = self.runtime.cost_overflow_div(divisor)?;
1304+
self.read_count = self.read_count.cost_overflow_div(divisor)?;
1305+
self.read_length = self.read_length.cost_overflow_div(divisor)?;
1306+
self.write_length = self.write_length.cost_overflow_div(divisor)?;
1307+
self.write_count = self.write_count.cost_overflow_div(divisor)?;
1308+
Ok(())
1309+
}
1310+
12961311
/// Returns whether or not this cost exceeds any dimension of the
12971312
/// other cost.
12981313
pub fn exceeds(&self, other: &ExecutionCost) -> bool {

stacks-signer/src/signerdb.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,22 @@ impl BlockInfo {
258258
self.state = state;
259259
Ok(())
260260
}
261+
262+
/// Check if the block is globally accepted or rejected
263+
pub fn has_reached_consensus(&self) -> bool {
264+
matches!(
265+
self.state,
266+
BlockState::GloballyAccepted | BlockState::GloballyRejected
267+
)
268+
}
269+
270+
/// Check if the block is locally accepted or rejected
271+
pub fn is_locally_finalized(&self) -> bool {
272+
matches!(
273+
self.state,
274+
BlockState::LocallyAccepted | BlockState::LocallyRejected
275+
)
276+
}
261277
}
262278

263279
/// This struct manages a SQLite database connection

stacks-signer/src/v0/signer.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,7 @@ impl Signer {
540540
.block_lookup(self.reward_cycle, &signer_signature_hash)
541541
{
542542
Ok(Some(block_info)) => {
543-
if block_info.state == BlockState::GloballyRejected
544-
|| block_info.state == BlockState::GloballyAccepted
545-
{
543+
if block_info.is_locally_finalized() {
546544
debug!("{self}: Received block validation for a block that is already marked as {}. Ignoring...", block_info.state);
547545
return None;
548546
}
@@ -559,8 +557,11 @@ impl Signer {
559557
}
560558
};
561559
if let Err(e) = block_info.mark_locally_accepted(false) {
562-
warn!("{self}: Failed to mark block as locally accepted: {e:?}",);
563-
return None;
560+
if !block_info.has_reached_consensus() {
561+
warn!("{self}: Failed to mark block as locally accepted: {e:?}",);
562+
return None;
563+
}
564+
block_info.signed_self.get_or_insert(get_epoch_time_secs());
564565
}
565566
let signature = self
566567
.private_key
@@ -598,9 +599,7 @@ impl Signer {
598599
.block_lookup(self.reward_cycle, &signer_signature_hash)
599600
{
600601
Ok(Some(block_info)) => {
601-
if block_info.state == BlockState::GloballyRejected
602-
|| block_info.state == BlockState::GloballyAccepted
603-
{
602+
if block_info.is_locally_finalized() {
604603
debug!("{self}: Received block validation for a block that is already marked as {}. Ignoring...", block_info.state);
605604
return None;
606605
}
@@ -617,8 +616,10 @@ impl Signer {
617616
}
618617
};
619618
if let Err(e) = block_info.mark_locally_rejected() {
620-
warn!("{self}: Failed to mark block as locally rejected: {e:?}",);
621-
return None;
619+
if !block_info.has_reached_consensus() {
620+
warn!("{self}: Failed to mark block as locally rejected: {e:?}",);
621+
return None;
622+
}
622623
}
623624
let block_rejection = BlockRejection::from_validate_rejection(
624625
block_validate_reject.clone(),

0 commit comments

Comments
 (0)