@@ -275,6 +275,8 @@ pub struct PeerInfo {
275
275
pub pox_consensus : ConsensusHash ,
276
276
/// The server version
277
277
pub server_version : String ,
278
+ /// The network id
279
+ pub network_id : u32 ,
278
280
}
279
281
280
282
impl StacksMessageCodec for PeerInfo {
@@ -287,6 +289,7 @@ impl StacksMessageCodec for PeerInfo {
287
289
fd. write_all ( self . server_version . as_bytes ( ) )
288
290
. map_err ( CodecError :: WriteError ) ?;
289
291
write_next ( fd, & self . pox_consensus ) ?;
292
+ write_next ( fd, & self . network_id ) ?;
290
293
Ok ( ( ) )
291
294
}
292
295
@@ -305,13 +308,15 @@ impl StacksMessageCodec for PeerInfo {
305
308
)
306
309
} ) ?;
307
310
let pox_consensus = read_next :: < ConsensusHash , _ > ( fd) ?;
311
+ let network_id = read_next ( fd) ?;
308
312
Ok ( Self {
309
313
burn_block_height,
310
314
stacks_tip_consensus_hash,
311
315
stacks_tip,
312
316
stacks_tip_height,
313
317
server_version,
314
318
pox_consensus,
319
+ network_id,
315
320
} )
316
321
}
317
322
}
@@ -321,18 +326,15 @@ impl StacksMessageCodec for PeerInfo {
321
326
pub struct MockProposal {
322
327
/// The view of the stacks node peer information at the time of the mock proposal
323
328
pub peer_info : PeerInfo ,
324
- /// The chain id for the mock proposal
325
- pub chain_id : u32 ,
326
329
/// The miner's signature across the peer info
327
330
signature : MessageSignature ,
328
331
}
329
332
330
333
impl MockProposal {
331
334
/// Create a new mock proposal data struct from the provided peer info, chain id, and private key.
332
- pub fn new ( peer_info : PeerInfo , chain_id : u32 , stacks_private_key : & StacksPrivateKey ) -> Self {
335
+ pub fn new ( peer_info : PeerInfo , stacks_private_key : & StacksPrivateKey ) -> Self {
333
336
let mut sig = Self {
334
337
signature : MessageSignature :: empty ( ) ,
335
- chain_id,
336
338
peer_info,
337
339
} ;
338
340
sig. sign ( stacks_private_key)
@@ -342,7 +344,8 @@ impl MockProposal {
342
344
343
345
/// The signature hash for the mock proposal
344
346
pub fn miner_signature_hash ( & self ) -> Sha256Sum {
345
- let domain_tuple = make_structured_data_domain ( "mock-miner" , "1.0.0" , self . chain_id ) ;
347
+ let domain_tuple =
348
+ make_structured_data_domain ( "mock-miner" , "1.0.0" , self . peer_info . network_id ) ;
346
349
let data_tuple = Value :: Tuple (
347
350
TupleData :: from_data ( vec ! [
348
351
(
@@ -375,7 +378,8 @@ impl MockProposal {
375
378
376
379
/// The signature hash including the miner's signature. Used by signers.
377
380
fn signer_signature_hash ( & self ) -> Sha256Sum {
378
- let domain_tuple = make_structured_data_domain ( "mock-signer" , "1.0.0" , self . chain_id ) ;
381
+ let domain_tuple =
382
+ make_structured_data_domain ( "mock-signer" , "1.0.0" , self . peer_info . network_id ) ;
379
383
let data_tuple = Value :: Tuple (
380
384
TupleData :: from_data ( vec ! [
381
385
(
@@ -413,18 +417,15 @@ impl MockProposal {
413
417
impl StacksMessageCodec for MockProposal {
414
418
fn consensus_serialize < W : Write > ( & self , fd : & mut W ) -> Result < ( ) , CodecError > {
415
419
self . peer_info . consensus_serialize ( fd) ?;
416
- write_next ( fd, & self . chain_id ) ?;
417
420
write_next ( fd, & self . signature ) ?;
418
421
Ok ( ( ) )
419
422
}
420
423
421
424
fn consensus_deserialize < R : Read > ( fd : & mut R ) -> Result < Self , CodecError > {
422
425
let peer_info = PeerInfo :: consensus_deserialize ( fd) ?;
423
- let chain_id = read_next :: < u32 , _ > ( fd) ?;
424
426
let signature = read_next :: < MessageSignature , _ > ( fd) ?;
425
427
Ok ( Self {
426
428
peer_info,
427
- chain_id,
428
429
signature,
429
430
} )
430
431
}
@@ -1024,26 +1025,26 @@ mod test {
1024
1025
let stacks_tip_height = thread_rng ( ) . next_u64 ( ) ;
1025
1026
let server_version = "0.0.0" . to_string ( ) ;
1026
1027
let pox_consensus_byte: u8 = thread_rng ( ) . gen ( ) ;
1028
+ let network_byte: u8 = thread_rng ( ) . gen_range ( 0 ..=1 ) ;
1029
+ let network_id = if network_byte == 1 {
1030
+ CHAIN_ID_TESTNET
1031
+ } else {
1032
+ CHAIN_ID_MAINNET
1033
+ } ;
1027
1034
PeerInfo {
1028
1035
burn_block_height,
1029
1036
stacks_tip_consensus_hash : ConsensusHash ( [ stacks_tip_consensus_byte; 20 ] ) ,
1030
1037
stacks_tip : BlockHeaderHash ( [ stacks_tip_byte; 32 ] ) ,
1031
1038
stacks_tip_height,
1032
1039
server_version,
1033
1040
pox_consensus : ConsensusHash ( [ pox_consensus_byte; 20 ] ) ,
1041
+ network_id,
1034
1042
}
1035
1043
}
1036
1044
fn random_mock_proposal ( ) -> MockProposal {
1037
- let chain_byte: u8 = thread_rng ( ) . gen_range ( 0 ..=1 ) ;
1038
- let chain_id = if chain_byte == 1 {
1039
- CHAIN_ID_TESTNET
1040
- } else {
1041
- CHAIN_ID_MAINNET
1042
- } ;
1043
1045
let peer_info = random_peer_data ( ) ;
1044
1046
MockProposal {
1045
1047
peer_info,
1046
- chain_id,
1047
1048
signature : MessageSignature :: empty ( ) ,
1048
1049
}
1049
1050
}
0 commit comments