Skip to content

Commit 4dd6630

Browse files
committed
Merge branch 'develop' into fix/5285
2 parents fb54e4c + e92b081 commit 4dd6630

File tree

4 files changed

+86
-25
lines changed

4 files changed

+86
-25
lines changed

stackslib/src/chainstate/nakamoto/miner.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,10 +706,19 @@ impl BlockBuilder for NakamotoBlockBuilder {
706706
tx.txid(),
707707
100 - TX_BLOCK_LIMIT_PROPORTION_HEURISTIC,
708708
&total_budget
709+
);
710+
let mut measured_cost = cost_after;
711+
let measured_cost = if measured_cost.sub(&cost_before).is_ok() {
712+
Some(measured_cost)
713+
} else {
714+
warn!(
715+
"Failed to compute measured cost of a too big transaction"
709716
);
717+
None
718+
};
710719
return TransactionResult::error(
711720
&tx,
712-
Error::TransactionTooBigError,
721+
Error::TransactionTooBigError(measured_cost),
713722
);
714723
} else {
715724
warn!(

stackslib/src/chainstate/stacks/miner.rs

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,9 +1040,18 @@ impl<'a> StacksMicroblockBuilder<'a> {
10401040
100 - TX_BLOCK_LIMIT_PROPORTION_HEURISTIC,
10411041
&total_budget
10421042
);
1043+
let mut measured_cost = cost_after.clone();
1044+
let measured_cost = if measured_cost.sub(cost_before).is_ok() {
1045+
Some(measured_cost)
1046+
} else {
1047+
warn!(
1048+
"Failed to compute measured cost of a too big transaction"
1049+
);
1050+
None
1051+
};
10431052
return Ok(TransactionResult::error(
10441053
&tx,
1045-
Error::TransactionTooBigError,
1054+
Error::TransactionTooBigError(measured_cost),
10461055
));
10471056
} else {
10481057
warn!(
@@ -1323,7 +1332,22 @@ impl<'a> StacksMicroblockBuilder<'a> {
13231332
return Ok(None);
13241333
}
13251334
}
1326-
Error::TransactionTooBigError => {
1335+
Error::TransactionTooBigError(measured_cost) => {
1336+
if update_estimator {
1337+
if let Some(measured_cost) = measured_cost {
1338+
if let Err(e) = estimator.notify_event(
1339+
&mempool_tx.tx.payload,
1340+
&measured_cost,
1341+
&block_limit,
1342+
&stacks_epoch_id,
1343+
) {
1344+
warn!("Error updating estimator";
1345+
"txid" => %mempool_tx.metadata.txid,
1346+
"error" => ?e);
1347+
}
1348+
}
1349+
}
1350+
13271351
invalidated_txs.push(mempool_tx.metadata.txid);
13281352
}
13291353
_ => {}
@@ -2405,7 +2429,22 @@ impl StacksBlockBuilder {
24052429
return Ok(None);
24062430
}
24072431
}
2408-
Error::TransactionTooBigError => {
2432+
Error::TransactionTooBigError(measured_cost) => {
2433+
if update_estimator {
2434+
if let Some(measured_cost) = measured_cost {
2435+
if let Err(e) = estimator.notify_event(
2436+
&txinfo.tx.payload,
2437+
&measured_cost,
2438+
&block_limit,
2439+
&stacks_epoch_id,
2440+
) {
2441+
warn!("Error updating estimator";
2442+
"txid" => %txinfo.metadata.txid,
2443+
"error" => ?e);
2444+
}
2445+
}
2446+
}
2447+
24092448
invalidated_txs.push(txinfo.metadata.txid);
24102449
}
24112450
Error::InvalidStacksTransaction(_, true) => {
@@ -2714,9 +2753,18 @@ impl BlockBuilder for StacksBlockBuilder {
27142753
100 - TX_BLOCK_LIMIT_PROPORTION_HEURISTIC,
27152754
&total_budget
27162755
);
2756+
let mut measured_cost = cost_after;
2757+
let measured_cost = if measured_cost.sub(&cost_before).is_ok() {
2758+
Some(measured_cost)
2759+
} else {
2760+
warn!(
2761+
"Failed to compute measured cost of a too big transaction"
2762+
);
2763+
None
2764+
};
27172765
return TransactionResult::error(
27182766
&tx,
2719-
Error::TransactionTooBigError,
2767+
Error::TransactionTooBigError(measured_cost),
27202768
);
27212769
} else {
27222770
warn!(
@@ -2795,9 +2843,19 @@ impl BlockBuilder for StacksBlockBuilder {
27952843
100 - TX_BLOCK_LIMIT_PROPORTION_HEURISTIC,
27962844
&total_budget
27972845
);
2846+
let mut measured_cost = cost_after;
2847+
let measured_cost = if measured_cost.sub(&cost_before).is_ok() {
2848+
Some(measured_cost)
2849+
} else {
2850+
warn!(
2851+
"Failed to compute measured cost of a too big transaction"
2852+
);
2853+
None
2854+
};
2855+
27982856
return TransactionResult::error(
27992857
&tx,
2800-
Error::TransactionTooBigError,
2858+
Error::TransactionTooBigError(measured_cost),
28012859
);
28022860
} else {
28032861
warn!(

stackslib/src/chainstate/stacks/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub enum Error {
104104
NotInSameFork,
105105
InvalidChainstateDB,
106106
BlockTooBigError,
107-
TransactionTooBigError,
107+
TransactionTooBigError(Option<ExecutionCost>),
108108
BlockCostExceeded,
109109
NoTransactionsToMine,
110110
MicroblockStreamTooLongError,
@@ -168,7 +168,9 @@ impl fmt::Display for Error {
168168
Error::NoSuchBlockError => write!(f, "No such Stacks block"),
169169
Error::InvalidChainstateDB => write!(f, "Invalid chainstate database"),
170170
Error::BlockTooBigError => write!(f, "Too much data in block"),
171-
Error::TransactionTooBigError => write!(f, "Too much data in transaction"),
171+
Error::TransactionTooBigError(ref c) => {
172+
write!(f, "Too much data in transaction: measured_cost={c:?}")
173+
}
172174
Error::BlockCostExceeded => write!(f, "Block execution budget exceeded"),
173175
Error::MicroblockStreamTooLongError => write!(f, "Too many microblocks in stream"),
174176
Error::IncompatibleSpendingConditionError => {
@@ -246,7 +248,7 @@ impl error::Error for Error {
246248
Error::NoSuchBlockError => None,
247249
Error::InvalidChainstateDB => None,
248250
Error::BlockTooBigError => None,
249-
Error::TransactionTooBigError => None,
251+
Error::TransactionTooBigError(..) => None,
250252
Error::BlockCostExceeded => None,
251253
Error::MicroblockStreamTooLongError => None,
252254
Error::IncompatibleSpendingConditionError => None,
@@ -291,7 +293,7 @@ impl Error {
291293
Error::NoSuchBlockError => "NoSuchBlockError",
292294
Error::InvalidChainstateDB => "InvalidChainstateDB",
293295
Error::BlockTooBigError => "BlockTooBigError",
294-
Error::TransactionTooBigError => "TransactionTooBigError",
296+
Error::TransactionTooBigError(..) => "TransactionTooBigError",
295297
Error::BlockCostExceeded => "BlockCostExceeded",
296298
Error::MicroblockStreamTooLongError => "MicroblockStreamTooLongError",
297299
Error::IncompatibleSpendingConditionError => "IncompatibleSpendingConditionError",

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3874,12 +3874,9 @@ fn partial_tenure_fork() {
38743874

38753875
let mut miner_1_blocks = 0;
38763876
let mut miner_2_blocks = 0;
3877-
// Make sure that both miner 1 and 2 mine at least 1 block each
3878-
while miner_1_tenures < min_miner_1_tenures
3879-
|| miner_2_tenures < min_miner_2_tenures
3880-
|| miner_1_blocks == 0
3881-
|| miner_2_blocks == 0
3882-
{
3877+
let mut min_miner_2_blocks = 0;
3878+
3879+
while miner_1_tenures < min_miner_1_tenures || miner_2_tenures < min_miner_2_tenures {
38833880
if btc_blocks_mined >= max_nakamoto_tenures {
38843881
panic!("Produced {btc_blocks_mined} sortitions, but didn't cover the test scenarios, aborting");
38853882
}
@@ -3963,6 +3960,7 @@ fn partial_tenure_fork() {
39633960
// Ensure that miner 2 runs at least one more tenure
39643961
min_miner_2_tenures = miner_2_tenures + 1;
39653962
fork_initiated = true;
3963+
min_miner_2_blocks = miner_2_blocks;
39663964
}
39673965
if miner == 2 && miner_2_tenures == min_miner_2_tenures {
39683966
// This is the forking tenure. Ensure that miner 1 runs one more
@@ -4096,15 +4094,9 @@ fn partial_tenure_fork() {
40964094
// The height may be higher than expected due to extra transactions waiting
40974095
// to be mined during the forking miner's tenure.
40984096
// We cannot guarantee due to TooMuchChaining that the miner will mine inter_blocks_per_tenure
4099-
let min_num_miner_2_blocks = std::cmp::min(
4100-
miner_2_blocks,
4101-
min_miner_2_tenures * (inter_blocks_per_tenure + 1),
4102-
);
4103-
assert!(
4104-
miner_2_tenures >= min_miner_2_tenures,
4105-
"Miner 2 failed to win its minimum number of tenures"
4106-
);
4107-
assert!(peer_1_height >= pre_nakamoto_peer_1_height + miner_1_blocks + min_num_miner_2_blocks,);
4097+
// Must be at least the number of blocks mined by miner 1 and the number of blocks mined by miner 2
4098+
// before the fork was initiated
4099+
assert!(peer_1_height >= pre_nakamoto_peer_1_height + miner_1_blocks + min_miner_2_blocks);
41084100
assert_eq!(
41094101
btc_blocks_mined,
41104102
u64::try_from(miner_1_tenures + miner_2_tenures).unwrap()

0 commit comments

Comments
 (0)