Skip to content

Commit 950a1fe

Browse files
committed
feat: vrf-seed in /v3/sortitions endpoint
1 parent 1f97bcf commit 950a1fe

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

stacks-signer/src/tests/chainstate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ fn check_proposal_refresh() {
556556
stacks_parent_ch: Some(view.cur_sortition.parent_tenure_id),
557557
last_sortition_ch: Some(view.cur_sortition.parent_tenure_id),
558558
committed_block_hash: None,
559+
vrf_seed: None,
559560
},
560561
SortitionInfo {
561562
burn_block_hash: BurnchainHeaderHash([128; 32]),
@@ -569,6 +570,7 @@ fn check_proposal_refresh() {
569570
stacks_parent_ch: Some(view.cur_sortition.parent_tenure_id),
570571
last_sortition_ch: Some(view.cur_sortition.parent_tenure_id),
571572
committed_block_hash: None,
573+
vrf_seed: None,
572574
},
573575
];
574576

stackslib/src/net/api/getsortition.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
use std::io::{Read, Seek, SeekFrom, Write};
1717
use std::{fs, io};
1818

19+
use clarity::types::chainstate::VRFSeed;
1920
use regex::{Captures, Regex};
2021
use serde::de::Error as de_Error;
22+
use serde::Serialize;
2123
use stacks_common::codec::{StacksMessageCodec, MAX_MESSAGE_LEN};
2224
use stacks_common::types::chainstate::{
2325
BlockHeaderHash, BurnchainHeaderHash, ConsensusHash, SortitionId, StacksBlockId,
@@ -111,6 +113,9 @@ pub struct SortitionInfo {
111113
/// In Stacks 2.x, this is the winning block.
112114
/// In Stacks 3.x, this is the first block of the parent tenure.
113115
pub committed_block_hash: Option<BlockHeaderHash>,
116+
#[serde(with = "prefix_opt_hex")]
117+
/// doc
118+
pub vrf_seed: Option<VRFSeed>,
114119
}
115120

116121
impl TryFrom<(&str, &str)> for QuerySpecifier {
@@ -163,12 +168,12 @@ impl GetSortitionHandler {
163168
let is_shadow = chainstate
164169
.nakamoto_blocks_db()
165170
.is_shadow_tenure(&sortition_sn.consensus_hash)?;
166-
let (miner_pk_hash160, stacks_parent_ch, committed_block_hash, last_sortition_ch) =
171+
let (miner_pk_hash160, stacks_parent_ch, committed_block_hash, last_sortition_ch, vrf_seed) =
167172
if !sortition_sn.sortition && !is_shadow {
168173
let handle = sortdb.index_handle(&sortition_sn.sortition_id);
169174
let last_sortition =
170175
handle.get_last_snapshot_with_sortition(sortition_sn.block_height)?;
171-
(None, None, None, Some(last_sortition.consensus_hash))
176+
(None, None, None, Some(last_sortition.consensus_hash), None)
172177
} else if !sortition_sn.sortition && is_shadow {
173178
// this is a shadow tenure.
174179
let parent_tenure_ch = chainstate
@@ -191,6 +196,7 @@ impl GetSortitionHandler {
191196
parent_tenure_start_header.index_block_hash().0,
192197
)),
193198
Some(parent_tenure_ch),
199+
None,
194200
)
195201
} else {
196202
let block_commit = SortitionDB::get_block_commit(sortdb.conn(), &sortition_sn.winning_block_txid, &sortition_sn.sortition_id)?
@@ -236,6 +242,7 @@ impl GetSortitionHandler {
236242
Some(stacks_parent_sn.consensus_hash),
237243
Some(block_commit.block_header_hash),
238244
Some(last_sortition_ch),
245+
Some(block_commit.new_seed),
239246
)
240247
};
241248

@@ -251,6 +258,7 @@ impl GetSortitionHandler {
251258
stacks_parent_ch,
252259
last_sortition_ch,
253260
committed_block_hash,
261+
vrf_seed,
254262
})
255263
}
256264
}

stackslib/src/net/api/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use clarity::types::chainstate::VRFSeed;
1718
use clarity::vm::costs::ExecutionCost;
1819
use stacks_common::codec::read_next;
1920
use stacks_common::types::chainstate::{
@@ -239,6 +240,7 @@ macro_rules! impl_hex_deser {
239240
impl_hex_deser!(BurnchainHeaderHash);
240241
impl_hex_deser!(StacksBlockId);
241242
impl_hex_deser!(SortitionId);
243+
impl_hex_deser!(VRFSeed);
242244
impl_hex_deser!(ConsensusHash);
243245
impl_hex_deser!(BlockHeaderHash);
244246
impl_hex_deser!(Hash160);

0 commit comments

Comments
 (0)