Skip to content

Commit

Permalink
feat: add tenure_height to /new_block event payload
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Oct 18, 2024
1 parent f245115 commit 607e3f1
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions stackslib/src/chainstate/coordinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ pub trait BlockEventDispatcher {
reward_set_data: &Option<RewardSetData>,
signer_bitvec: &Option<BitVec<4000>>,
block_timestamp: Option<u64>,
coinbase_height: u64,
);

/// called whenever a burn block is about to be
Expand Down
1 change: 1 addition & 0 deletions stackslib/src/chainstate/coordinator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ impl BlockEventDispatcher for NullEventDispatcher {
_reward_set_data: &Option<RewardSetData>,
_signer_bitvec: &Option<BitVec<4000>>,
_block_timestamp: Option<u64>,
_coinbase_height: u64,
) {
assert!(
false,
Expand Down
2 changes: 2 additions & 0 deletions stackslib/src/chainstate/nakamoto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2118,6 +2118,7 @@ impl NakamotoChainState {
&reward_set_data,
&Some(signer_bitvec),
Some(block_timestamp),
receipt.coinbase_height,
);
}

Expand Down Expand Up @@ -4382,6 +4383,7 @@ impl NakamotoChainState {
evaluated_epoch,
epoch_transition: applied_epoch_transition,
signers_updated,
coinbase_height,
};

Ok((epoch_receipt, clarity_commit, reward_set_data))
Expand Down
11 changes: 10 additions & 1 deletion stackslib/src/chainstate/stacks/db/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ impl BlockEventDispatcher for DummyEventDispatcher {
_reward_set_data: &Option<RewardSetData>,
_signer_bitvec: &Option<BitVec<4000>>,
_block_timestamp: Option<u64>,
_coinbase_height: u64,
) {
assert!(
false,
Expand Down Expand Up @@ -5809,8 +5810,10 @@ impl StacksChainState {
.map(|(_, _, _, info)| info.clone());

if do_not_advance {
let regtest_genesis_header = StacksHeaderInfo::regtest_genesis();
let coinbase_height = regtest_genesis_header.stacks_block_height;
let epoch_receipt = StacksEpochReceipt {
header: StacksHeaderInfo::regtest_genesis(),
header: regtest_genesis_header,
tx_receipts,
matured_rewards,
matured_rewards_info,
Expand All @@ -5822,6 +5825,7 @@ impl StacksChainState {
evaluated_epoch,
epoch_transition: applied_epoch_transition,
signers_updated: false,
coinbase_height,
};

return Ok((epoch_receipt, clarity_commit, None));
Expand Down Expand Up @@ -5898,6 +5902,9 @@ impl StacksChainState {
);
set_last_execution_cost_observed(&block_execution_cost, &block_limit);

// // The coinbase height is the same as the stacks block height in epoch 2.x
let coinbase_height = new_tip.stacks_block_height;

let epoch_receipt = StacksEpochReceipt {
header: new_tip,
tx_receipts,
Expand All @@ -5911,6 +5918,7 @@ impl StacksChainState {
evaluated_epoch,
epoch_transition: applied_epoch_transition,
signers_updated,
coinbase_height,
};

Ok((epoch_receipt, clarity_commit, reward_set_data))
Expand Down Expand Up @@ -6411,6 +6419,7 @@ impl StacksChainState {
&reward_set_data,
&None,
None,
next_staging_block.height,
);
}

Expand Down
1 change: 1 addition & 0 deletions stackslib/src/chainstate/stacks/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ pub struct StacksEpochReceipt {
pub epoch_transition: bool,
/// Was .signers updated during this block?
pub signers_updated: bool,
pub coinbase_height: u64,
}

/// Headers we serve over the network
Expand Down
1 change: 1 addition & 0 deletions stackslib/src/cost_estimates/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ pub fn make_block_receipt(tx_receipts: Vec<StacksTransactionReceipt>) -> StacksE
evaluated_epoch: StacksEpochId::Epoch20,
epoch_transition: false,
signers_updated: false,
coinbase_height: 1234,
}
}
1 change: 1 addition & 0 deletions stackslib/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,7 @@ pub mod test {
reward_set_data: &Option<RewardSetData>,
_signer_bitvec: &Option<BitVec<4000>>,
_block_timestamp: Option<u64>,
_coinbase_height: u64,
) {
self.blocks.lock().unwrap().push(TestEventObserverBlock {
block: block.clone(),
Expand Down
10 changes: 10 additions & 0 deletions testnet/stacks-node/src/event_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ impl EventObserver {
reward_set_data: &Option<RewardSetData>,
signer_bitvec_opt: &Option<BitVec<4000>>,
block_timestamp: Option<u64>,
coinbase_height: u64,
) -> serde_json::Value {
// Serialize events to JSON
let serialized_events: Vec<serde_json::Value> = filtered_events
Expand Down Expand Up @@ -809,6 +810,7 @@ impl EventObserver {
"signer_bitvec": signer_bitvec_value,
"reward_set": reward_set_value,
"cycle_number": cycle_number_value,
"tenure_height": coinbase_height,
});

let as_object_mut = payload.as_object_mut().unwrap();
Expand Down Expand Up @@ -1008,6 +1010,7 @@ impl BlockEventDispatcher for EventDispatcher {
reward_set_data: &Option<RewardSetData>,
signer_bitvec: &Option<BitVec<4000>>,
block_timestamp: Option<u64>,
coinbase_height: u64,
) {
self.process_chain_tip(
block,
Expand All @@ -1026,6 +1029,7 @@ impl BlockEventDispatcher for EventDispatcher {
reward_set_data,
signer_bitvec,
block_timestamp,
coinbase_height,
);
}

Expand Down Expand Up @@ -1209,6 +1213,7 @@ impl EventDispatcher {
reward_set_data: &Option<RewardSetData>,
signer_bitvec: &Option<BitVec<4000>>,
block_timestamp: Option<u64>,
coinbase_height: u64,
) {
let all_receipts = receipts.to_owned();
let (dispatch_matrix, events) = self.create_dispatch_matrix_and_event_vector(&all_receipts);
Expand Down Expand Up @@ -1261,6 +1266,7 @@ impl EventDispatcher {
reward_set_data,
signer_bitvec,
block_timestamp,
coinbase_height,
);

// Send payload
Expand Down Expand Up @@ -1669,6 +1675,7 @@ mod test {
let pox_constants = PoxConstants::testnet_default();
let signer_bitvec = BitVec::zeros(2).expect("Failed to create BitVec with length 2");
let block_timestamp = Some(123456);
let coinbase_height = 1234;

let payload = observer.make_new_block_processed_payload(
filtered_events,
Expand All @@ -1687,6 +1694,7 @@ mod test {
&None,
&Some(signer_bitvec.clone()),
block_timestamp,
coinbase_height,
);
assert_eq!(
payload
Expand Down Expand Up @@ -1737,6 +1745,7 @@ mod test {
let pox_constants = PoxConstants::testnet_default();
let signer_bitvec = BitVec::zeros(2).expect("Failed to create BitVec with length 2");
let block_timestamp = Some(123456);
let coinbase_height = 1234;

let payload = observer.make_new_block_processed_payload(
filtered_events,
Expand All @@ -1755,6 +1764,7 @@ mod test {
&None,
&Some(signer_bitvec.clone()),
block_timestamp,
coinbase_height,
);

let event_signer_signature = payload
Expand Down
1 change: 1 addition & 0 deletions testnet/stacks-node/src/run_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,6 @@ pub fn announce_boot_receipts(
&None,
&None,
None,
0,
);
}

0 comments on commit 607e3f1

Please sign in to comment.