@@ -34,6 +34,53 @@ 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
+ }
43
+
44
+ impl From < NonceRequest > for BlockInfoV1 {
45
+ fn from ( value : NonceRequest ) -> Self {
46
+ Self {
47
+ nonce_request : Some ( value) ,
48
+ }
49
+ }
50
+ }
51
+
52
+ #[ derive( Serialize , Deserialize , Debug , PartialEq , Default ) ]
53
+ /// Store extra version-specific info in `BlockInfo`
54
+ pub enum ExtraBlockInfo {
55
+ #[ default]
56
+ /// Don't know what version
57
+ None ,
58
+ /// Extra data for Signer V0
59
+ V0 ,
60
+ /// Extra data for Signer V1
61
+ V1 ( BlockInfoV1 ) ,
62
+ }
63
+
64
+ impl ExtraBlockInfo {
65
+ /// Take `nonce_request` if it exists
66
+ pub fn take_nonce_request ( & mut self ) -> Option < NonceRequest > {
67
+ match self {
68
+ ExtraBlockInfo :: None | ExtraBlockInfo :: V0 => None ,
69
+ ExtraBlockInfo :: V1 ( v1) => v1. nonce_request . take ( ) ,
70
+ }
71
+ }
72
+ /// Set `nonce_request` if it exists
73
+ pub fn set_nonce_request ( & mut self , value : NonceRequest ) -> Result < ( ) , & str > {
74
+ match self {
75
+ ExtraBlockInfo :: None | ExtraBlockInfo :: V0 => Err ( "Field doesn't exist" ) ,
76
+ ExtraBlockInfo :: V1 ( v1) => {
77
+ v1. nonce_request = Some ( value) ;
78
+ Ok ( ( ) )
79
+ }
80
+ }
81
+ }
82
+ }
83
+
37
84
/// Additional Info about a proposed block
38
85
#[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
39
86
pub struct BlockInfo {
@@ -47,8 +94,6 @@ pub struct BlockInfo {
47
94
pub vote : Option < NakamotoBlockVote > ,
48
95
/// Whether the block contents are valid
49
96
pub valid : Option < bool > ,
50
- /// The associated packet nonce request if we have one
51
- pub nonce_request : Option < NonceRequest > ,
52
97
/// Whether this block is already being signed over
53
98
pub signed_over : bool ,
54
99
/// Time at which the proposal was received by this signer (epoch time in seconds)
@@ -57,6 +102,8 @@ pub struct BlockInfo {
57
102
pub signed_self : Option < u64 > ,
58
103
/// Time at which the proposal was signed by a threshold in the signer set (epoch time in seconds)
59
104
pub signed_group : Option < u64 > ,
105
+ /// Extra data specific to v0, v1, etc.
106
+ pub ext : ExtraBlockInfo ,
60
107
}
61
108
62
109
impl From < BlockProposal > for BlockInfo {
@@ -67,19 +114,19 @@ impl From<BlockProposal> for BlockInfo {
67
114
reward_cycle : value. reward_cycle ,
68
115
vote : None ,
69
116
valid : None ,
70
- nonce_request : None ,
71
117
signed_over : false ,
72
118
proposed_time : get_epoch_time_secs ( ) ,
73
119
signed_self : None ,
74
120
signed_group : None ,
121
+ ext : ExtraBlockInfo :: default ( ) ,
75
122
}
76
123
}
77
124
}
78
125
impl BlockInfo {
79
126
/// Create a new BlockInfo with an associated nonce request packet
80
- pub fn new_with_request ( block_proposal : BlockProposal , nonce_request : NonceRequest ) -> Self {
127
+ pub fn new_v1_with_request ( block_proposal : BlockProposal , nonce_request : NonceRequest ) -> Self {
81
128
let mut block_info = BlockInfo :: from ( block_proposal) ;
82
- block_info. nonce_request = Some ( nonce_request) ;
129
+ block_info. ext = ExtraBlockInfo :: V1 ( BlockInfoV1 :: from ( nonce_request) ) ;
83
130
block_info. signed_over = true ;
84
131
block_info
85
132
}
@@ -89,9 +136,7 @@ impl BlockInfo {
89
136
pub fn mark_signed_and_valid ( & mut self ) {
90
137
self . valid = Some ( true ) ;
91
138
self . signed_over = true ;
92
- if self . signed_self . is_none ( ) {
93
- self . signed_self = Some ( get_epoch_time_secs ( ) ) ;
94
- }
139
+ self . signed_self . get_or_insert ( get_epoch_time_secs ( ) ) ;
95
140
}
96
141
97
142
/// Return the block's signer signature hash
@@ -115,7 +160,7 @@ CREATE TABLE IF NOT EXISTS blocks (
115
160
block_info TEXT NOT NULL,
116
161
consensus_hash TEXT NOT NULL,
117
162
signed_over INTEGER NOT NULL,
118
- stacks_height INTEGER NOT NULL,
163
+ stacks_height INTEGER NOT NULL,
119
164
burn_block_height INTEGER NOT NULL,
120
165
PRIMARY KEY (reward_cycle, signer_signature_hash)
121
166
) STRICT" ;
@@ -189,7 +234,7 @@ impl SignerDb {
189
234
} )
190
235
. optional ( ) ;
191
236
match result {
192
- Ok ( x) => Ok ( x. unwrap_or_else ( || 0 ) ) ,
237
+ Ok ( x) => Ok ( x. unwrap_or ( 0 ) ) ,
193
238
Err ( e) => Err ( DBError :: from ( e) ) ,
194
239
}
195
240
}
0 commit comments