@@ -34,6 +34,73 @@ use stacks_common::util::hash::Sha512Trunc256Sum;
34
34
use stacks_common:: { debug, error} ;
35
35
use wsts:: net:: NonceRequest ;
36
36
37
+ #[ derive( Serialize , Deserialize , Debug , PartialEq , Default ) ]
38
+ /// Information specific to Signer V1
39
+ pub struct BlockInfoV1 {
40
+ /// The associated packet nonce request if we have one
41
+ pub nonce_request : Option < NonceRequest > ,
42
+ /// Whether this block is already being signed over
43
+ pub signed_over : bool ,
44
+ }
45
+
46
+ impl From < NonceRequest > for BlockInfoV1 {
47
+ fn from ( value : NonceRequest ) -> Self {
48
+ Self {
49
+ nonce_request : Some ( value) ,
50
+ signed_over : true ,
51
+ }
52
+ }
53
+ }
54
+
55
+ #[ derive( Serialize , Deserialize , Debug , PartialEq , Default ) ]
56
+ /// Store extra version-specific info in `BlockInfo`
57
+ pub enum ExtraBlockInfo {
58
+ #[ default]
59
+ /// Don't know what version
60
+ None ,
61
+ /// Extra data for Signer V0
62
+ V0 ,
63
+ /// Extra data for Signer V1
64
+ V1 ( BlockInfoV1 ) ,
65
+ }
66
+
67
+ impl ExtraBlockInfo {
68
+ /// Get `signed_over` if it exists
69
+ pub fn get_signed_over ( & self ) -> Option < bool > {
70
+ match self {
71
+ ExtraBlockInfo :: None | ExtraBlockInfo :: V0 => None ,
72
+ ExtraBlockInfo :: V1 ( v1) => Some ( v1. signed_over ) ,
73
+ }
74
+ }
75
+ /// Set `signed_over` if it exists
76
+ pub fn set_signed_over ( & mut self , value : bool ) -> Result < ( ) , & str > {
77
+ match self {
78
+ ExtraBlockInfo :: None | ExtraBlockInfo :: V0 => Err ( "Field doesn't exist" ) ,
79
+ ExtraBlockInfo :: V1 ( v1) => {
80
+ v1. signed_over = value;
81
+ Ok ( ( ) )
82
+ }
83
+ }
84
+ }
85
+ /// Take `nonce_request` if it exists
86
+ pub fn take_nonce_request ( & mut self ) -> Option < NonceRequest > {
87
+ match self {
88
+ ExtraBlockInfo :: None | ExtraBlockInfo :: V0 => None ,
89
+ ExtraBlockInfo :: V1 ( v1) => v1. nonce_request . take ( ) ,
90
+ }
91
+ }
92
+ /// Set `nonce_request` if it exists
93
+ pub fn set_nonce_request ( & mut self , value : NonceRequest ) -> Result < ( ) , & str > {
94
+ match self {
95
+ ExtraBlockInfo :: None | ExtraBlockInfo :: V0 => Err ( "Field doesn't exist" ) ,
96
+ ExtraBlockInfo :: V1 ( v1) => {
97
+ v1. nonce_request = Some ( value) ;
98
+ Ok ( ( ) )
99
+ }
100
+ }
101
+ }
102
+ }
103
+
37
104
/// Additional Info about a proposed block
38
105
#[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
39
106
pub struct BlockInfo {
@@ -47,16 +114,14 @@ pub struct BlockInfo {
47
114
pub vote : Option < NakamotoBlockVote > ,
48
115
/// Whether the block contents are valid
49
116
pub valid : Option < bool > ,
50
- /// The associated packet nonce request if we have one
51
- pub nonce_request : Option < NonceRequest > ,
52
- /// Whether this block is already being signed over
53
- pub signed_over : bool ,
54
117
/// Time at which the proposal was received by this signer (epoch time in seconds)
55
118
pub proposed_time : u64 ,
56
119
/// Time at which the proposal was signed by this signer (epoch time in seconds)
57
120
pub signed_self : Option < u64 > ,
58
121
/// Time at which the proposal was signed by a threshold in the signer set (epoch time in seconds)
59
122
pub signed_group : Option < u64 > ,
123
+ /// Extra data specific to v0, v1, etc.
124
+ pub ext : ExtraBlockInfo ,
60
125
}
61
126
62
127
impl From < BlockProposal > for BlockInfo {
@@ -67,31 +132,27 @@ impl From<BlockProposal> for BlockInfo {
67
132
reward_cycle : value. reward_cycle ,
68
133
vote : None ,
69
134
valid : None ,
70
- nonce_request : None ,
71
- signed_over : false ,
72
135
proposed_time : get_epoch_time_secs ( ) ,
73
136
signed_self : None ,
74
137
signed_group : None ,
138
+ ext : ExtraBlockInfo :: default ( ) ,
75
139
}
76
140
}
77
141
}
78
142
impl BlockInfo {
79
143
/// Create a new BlockInfo with an associated nonce request packet
80
- pub fn new_with_request ( block_proposal : BlockProposal , nonce_request : NonceRequest ) -> Self {
144
+ pub fn new_v1_with_request ( block_proposal : BlockProposal , nonce_request : NonceRequest ) -> Self {
81
145
let mut block_info = BlockInfo :: from ( block_proposal) ;
82
- block_info. nonce_request = Some ( nonce_request) ;
83
- block_info. signed_over = true ;
146
+ block_info. ext = ExtraBlockInfo :: V1 ( BlockInfoV1 :: from ( nonce_request) ) ;
84
147
block_info
85
148
}
86
149
87
150
/// Mark this block as valid, signed over, and record a timestamp in the block info if it wasn't
88
151
/// already set.
89
152
pub fn mark_signed_and_valid ( & mut self ) {
90
153
self . valid = Some ( true ) ;
91
- self . signed_over = true ;
92
- if self . signed_self . is_none ( ) {
93
- self . signed_self = Some ( get_epoch_time_secs ( ) ) ;
94
- }
154
+ self . signed_self . get_or_insert ( get_epoch_time_secs ( ) ) ;
155
+ _ = self . ext . set_signed_over ( true ) ;
95
156
}
96
157
97
158
/// Return the block's signer signature hash
@@ -115,7 +176,7 @@ CREATE TABLE IF NOT EXISTS blocks (
115
176
block_info TEXT NOT NULL,
116
177
consensus_hash TEXT NOT NULL,
117
178
signed_over INTEGER NOT NULL,
118
- stacks_height INTEGER NOT NULL,
179
+ stacks_height INTEGER NOT NULL,
119
180
burn_block_height INTEGER NOT NULL,
120
181
PRIMARY KEY (reward_cycle, signer_signature_hash)
121
182
) STRICT" ;
@@ -189,7 +250,7 @@ impl SignerDb {
189
250
} )
190
251
. optional ( ) ;
191
252
match result {
192
- Ok ( x) => Ok ( x. unwrap_or_else ( || 0 ) ) ,
253
+ Ok ( x) => Ok ( x. unwrap_or ( 0 ) ) ,
193
254
Err ( e) => Err ( DBError :: from ( e) ) ,
194
255
}
195
256
}
@@ -346,7 +407,7 @@ impl SignerDb {
346
407
serde_json:: to_string ( & block_info) . expect ( "Unable to serialize block info" ) ;
347
408
let hash = & block_info. signer_signature_hash ( ) ;
348
409
let block_id = & block_info. block . block_id ( ) ;
349
- let signed_over = & block_info. signed_over ;
410
+ let signed_over = & block_info. ext . get_signed_over ( ) . unwrap_or ( false ) ;
350
411
let vote = block_info
351
412
. vote
352
413
. as_ref ( )
@@ -543,6 +604,8 @@ mod tests {
543
604
let db_path = tmp_db_path ( ) ;
544
605
let mut db = SignerDb :: new ( db_path) . expect ( "Failed to create signer db" ) ;
545
606
let ( mut block_info, block_proposal) = create_block ( ) ;
607
+ // We'll need the V1 data fields for this
608
+ block_info. ext = ExtraBlockInfo :: V1 ( BlockInfoV1 :: default ( ) ) ;
546
609
db. insert_block ( & block_info) . unwrap ( ) ;
547
610
548
611
assert ! ( db
0 commit comments