Skip to content

Commit e4aa013

Browse files
committed
Merge branch 'develop' into feat/sip-029
2 parents d36c548 + 7985b33 commit e4aa013

File tree

19 files changed

+831
-117
lines changed

19 files changed

+831
-117
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::signer_chainstate
143143
- tests::nakamoto_integrations::sip029_coinbase_change
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
@@ -897,6 +897,7 @@ impl LimitedCostTracker {
897897
Self::Free => ExecutionCost::max_value(),
898898
}
899899
}
900+
900901
pub fn get_memory(&self) -> u64 {
901902
match self {
902903
Self::Limited(TrackerData { memory, .. }) => *memory,
@@ -1171,6 +1172,7 @@ pub trait CostOverflowingMath<T> {
11711172
fn cost_overflow_mul(self, other: T) -> Result<T>;
11721173
fn cost_overflow_add(self, other: T) -> Result<T>;
11731174
fn cost_overflow_sub(self, other: T) -> Result<T>;
1175+
fn cost_overflow_div(self, other: T) -> Result<T>;
11741176
}
11751177

11761178
impl CostOverflowingMath<u64> for u64 {
@@ -1186,6 +1188,10 @@ impl CostOverflowingMath<u64> for u64 {
11861188
self.checked_sub(other)
11871189
.ok_or_else(|| CostErrors::CostOverflow)
11881190
}
1191+
fn cost_overflow_div(self, other: u64) -> Result<u64> {
1192+
self.checked_div(other)
1193+
.ok_or_else(|| CostErrors::CostOverflow)
1194+
}
11891195
}
11901196

11911197
impl ExecutionCost {
@@ -1294,6 +1300,15 @@ impl ExecutionCost {
12941300
Ok(())
12951301
}
12961302

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