-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add various new nakamoto block fields to /new_block
ingestion and StacksPayload
#659
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,36 @@ pub struct NewBlock { | |
pub transactions: Vec<NewTransaction>, | ||
pub events: Vec<NewEvent>, | ||
pub matured_miner_rewards: Vec<MaturedMinerReward>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub block_time: Option<u64>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub signer_bitvec: Option<String>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub signer_signature: Option<Vec<String>>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub cycle_number: Option<u64>, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub reward_set: Option<RewardSet>, | ||
} | ||
|
||
#[derive(Deserialize, Serialize)] | ||
pub struct RewardSet { | ||
pub pox_ustx_threshold: String, | ||
pub rewarded_addresses: Vec<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub signers: Option<Vec<RewardSetSigner>>, | ||
} | ||
|
||
#[derive(Deserialize, Serialize)] | ||
pub struct RewardSetSigner { | ||
pub signing_key: String, | ||
pub weight: u32, | ||
pub stacked_amt: String, | ||
} | ||
|
||
#[derive(Deserialize, Serialize, Default, Clone)] | ||
|
@@ -432,6 +462,29 @@ pub fn standardize_stacks_block( | |
pox_cycle_length: pox_cycle_length.try_into().unwrap(), | ||
confirm_microblock_identifier, | ||
stacks_block_hash: block.block_hash.clone(), | ||
|
||
block_time: block.block_time, | ||
// TODO: decode `signer_bitvec` into an easy to use bit string representation (e.g. "01010101") | ||
signer_bitvec: block.signer_bitvec.clone(), | ||
Comment on lines
+467
to
+468
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rafaelcr we get these from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I believe so, it's probably included in the update we did to the |
||
signer_signature: block.signer_signature.clone(), | ||
|
||
cycle_number: block.cycle_number, | ||
reward_set: block.reward_set.as_ref().and_then(|r| { | ||
Some(StacksBlockMetadataRewardSet { | ||
pox_ustx_threshold: r.pox_ustx_threshold.clone(), | ||
rewarded_addresses: r.rewarded_addresses.clone(), | ||
signers: r.signers.as_ref().map(|signers| { | ||
signers | ||
.into_iter() | ||
.map(|signer| StacksBlockMetadataRewardSetSigner { | ||
signing_key: signer.signing_key.clone(), | ||
weight: signer.weight, | ||
stacked_amt: signer.stacked_amt.clone(), | ||
}) | ||
.collect() | ||
}), | ||
}) | ||
}), | ||
}, | ||
transactions, | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,29 @@ pub struct StacksBlockMetadata { | |
pub pox_cycle_length: u32, | ||
pub confirm_microblock_identifier: Option<BlockIdentifier>, | ||
pub stacks_block_hash: String, | ||
|
||
// Fields included in Nakamoto block headers | ||
pub block_time: Option<u64>, | ||
pub signer_bitvec: Option<String>, | ||
pub signer_signature: Option<Vec<String>>, | ||
|
||
// Available starting in epoch3, only included in blocks where the pox cycle rewards are first calculated | ||
pub cycle_number: Option<u64>, | ||
pub reward_set: Option<StacksBlockMetadataRewardSet>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] | ||
pub struct StacksBlockMetadataRewardSet { | ||
pub pox_ustx_threshold: String, | ||
pub rewarded_addresses: Vec<String>, | ||
pub signers: Option<Vec<StacksBlockMetadataRewardSetSigner>>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] | ||
pub struct StacksBlockMetadataRewardSetSigner { | ||
pub signing_key: String, | ||
pub weight: u32, | ||
pub stacked_amt: String, | ||
Comment on lines
+117
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm simply re-using the same structure as the |
||
} | ||
|
||
/// BitcoinBlock contain an array of Transactions that occurred at a particular | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stacks-core isn't very consistent with some of these fields being optional (undefined) vs nullable. So goal here is to just support either case during deserialization.