@@ -571,6 +571,17 @@ pub enum StateMachineUpdateContent {
571
571
/// The signer's view of who the current miner should be (and their tenure building info)
572
572
current_miner : StateMachineUpdateMinerState ,
573
573
} ,
574
+ /// Version 1
575
+ V1 {
576
+ /// The tip burn block (i.e., the latest bitcoin block) seen by this signer
577
+ burn_block : ConsensusHash ,
578
+ /// The tip burn block height (i.e., the latest bitcoin block) seen by this signer
579
+ burn_block_height : u64 ,
580
+ /// The signer's view of who the current miner should be (and their tenure building info)
581
+ current_miner : StateMachineUpdateMinerState ,
582
+ /// The replay transactions
583
+ replay_transactions : Vec < StacksTransaction > ,
584
+ } ,
574
585
}
575
586
576
587
/// Message for update the Signer State infos
@@ -676,6 +687,7 @@ impl StateMachineUpdateContent {
676
687
fn is_protocol_version_compatible ( & self , version : u64 ) -> bool {
677
688
match self {
678
689
Self :: V0 { .. } => version == 0 ,
690
+ Self :: V1 { .. } => version == 1 ,
679
691
}
680
692
}
681
693
@@ -690,6 +702,17 @@ impl StateMachineUpdateContent {
690
702
burn_block_height. consensus_serialize ( fd) ?;
691
703
current_miner. consensus_serialize ( fd) ?;
692
704
}
705
+ Self :: V1 {
706
+ burn_block,
707
+ burn_block_height,
708
+ current_miner,
709
+ replay_transactions,
710
+ } => {
711
+ burn_block. consensus_serialize ( fd) ?;
712
+ burn_block_height. consensus_serialize ( fd) ?;
713
+ current_miner. consensus_serialize ( fd) ?;
714
+ replay_transactions. consensus_serialize ( fd) ?;
715
+ }
693
716
}
694
717
Ok ( ( ) )
695
718
}
@@ -705,6 +728,18 @@ impl StateMachineUpdateContent {
705
728
current_miner,
706
729
} )
707
730
}
731
+ 1 => {
732
+ let burn_block = read_next ( fd) ?;
733
+ let burn_block_height = read_next ( fd) ?;
734
+ let current_miner = read_next ( fd) ?;
735
+ let replay_transactions = read_next ( fd) ?;
736
+ Ok ( Self :: V1 {
737
+ burn_block,
738
+ burn_block_height,
739
+ current_miner,
740
+ replay_transactions,
741
+ } )
742
+ }
708
743
other => Err ( CodecError :: DeserializeError ( format ! (
709
744
"Unknown state machine update version: {other}"
710
745
) ) ) ,
@@ -1716,15 +1751,17 @@ impl From<StateMachineUpdate> for SignerMessage {
1716
1751
mod test {
1717
1752
use blockstack_lib:: chainstate:: nakamoto:: NakamotoBlockHeader ;
1718
1753
use blockstack_lib:: chainstate:: stacks:: {
1719
- TransactionAnchorMode , TransactionAuth , TransactionPayload , TransactionPostConditionMode ,
1720
- TransactionSmartContract , TransactionVersion ,
1754
+ TransactionAnchorMode , TransactionAuth , TransactionContractCall , TransactionPayload ,
1755
+ TransactionPostConditionMode , TransactionSmartContract , TransactionSpendingCondition ,
1756
+ TransactionVersion ,
1721
1757
} ;
1722
1758
use blockstack_lib:: util_lib:: strings:: StacksString ;
1723
1759
use clarity:: consts:: CHAIN_ID_MAINNET ;
1724
- use clarity:: types:: chainstate:: { ConsensusHash , StacksBlockId , TrieHash } ;
1760
+ use clarity:: types:: chainstate:: { ConsensusHash , StacksAddress , StacksBlockId , TrieHash } ;
1725
1761
use clarity:: types:: PrivateKey ;
1726
1762
use clarity:: util:: hash:: { hex_bytes, MerkleTree } ;
1727
1763
use clarity:: util:: secp256k1:: MessageSignature ;
1764
+ use clarity:: vm:: { ClarityName , ContractName } ;
1728
1765
use rand:: rngs:: mock;
1729
1766
use rand:: { thread_rng, Rng , RngCore } ;
1730
1767
use rand_core:: OsRng ;
@@ -2316,4 +2353,84 @@ mod test {
2316
2353
2317
2354
assert_eq ! ( signer_message, signer_message_deserialized) ;
2318
2355
}
2356
+
2357
+ #[ test]
2358
+ fn deserialize_state_machine_update_v1 ( ) {
2359
+ let signer_message = StateMachineUpdate :: new (
2360
+ 1 ,
2361
+ 3 ,
2362
+ StateMachineUpdateContent :: V1 {
2363
+ burn_block : ConsensusHash ( [ 0x55 ; 20 ] ) ,
2364
+ burn_block_height : 100 ,
2365
+ current_miner : StateMachineUpdateMinerState :: ActiveMiner {
2366
+ current_miner_pkh : Hash160 ( [ 0xab ; 20 ] ) ,
2367
+ tenure_id : ConsensusHash ( [ 0x44 ; 20 ] ) ,
2368
+ parent_tenure_id : ConsensusHash ( [ 0x22 ; 20 ] ) ,
2369
+ parent_tenure_last_block : StacksBlockId ( [ 0x33 ; 32 ] ) ,
2370
+ parent_tenure_last_block_height : 1 ,
2371
+ } ,
2372
+ replay_transactions : vec ! [ ] ,
2373
+ } ,
2374
+ )
2375
+ . unwrap ( ) ;
2376
+
2377
+ let mut bytes = vec ! [ ] ;
2378
+ signer_message. consensus_serialize ( & mut bytes) . unwrap ( ) ;
2379
+
2380
+ // check for raw content for avoiding regressions when structure changes
2381
+ let raw_signer_message: Vec < & [ u8 ] > = vec ! [
2382
+ /* active_signer_protocol_version*/ & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ] ,
2383
+ /* local_supported_signer_protocol_version*/ & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 3 ] ,
2384
+ /* content_len*/ & [ 0 , 0 , 0 , 133 ] ,
2385
+ /* burn_block*/ & [ 0x55 ; 20 ] ,
2386
+ /* burn_block_height*/ & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 100 ] ,
2387
+ /* current_miner_variant */ & [ 0x01 ] ,
2388
+ /* current_miner_pkh */ & [ 0xab ; 20 ] ,
2389
+ /* tenure_id*/ & [ 0x44 ; 20 ] ,
2390
+ /* parent_tenure_id*/ & [ 0x22 ; 20 ] ,
2391
+ /* parent_tenure_last_block */ & [ 0x33 ; 32 ] ,
2392
+ /* parent_tenure_last_block_height*/ & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ] ,
2393
+ /* replay_transactions */ & [ 0 , 0 , 0 , 0 ] ,
2394
+ ] ;
2395
+
2396
+ assert_eq ! ( bytes, raw_signer_message. concat( ) ) ;
2397
+
2398
+ let signer_message_deserialized =
2399
+ StateMachineUpdate :: consensus_deserialize ( & mut & bytes[ ..] ) . unwrap ( ) ;
2400
+
2401
+ assert_eq ! ( signer_message, signer_message_deserialized) ;
2402
+
2403
+ let signer_message = StateMachineUpdate :: new (
2404
+ 1 ,
2405
+ 4 ,
2406
+ StateMachineUpdateContent :: V1 {
2407
+ burn_block : ConsensusHash ( [ 0x55 ; 20 ] ) ,
2408
+ burn_block_height : 100 ,
2409
+ current_miner : StateMachineUpdateMinerState :: NoValidMiner ,
2410
+ replay_transactions : vec ! [ ] ,
2411
+ } ,
2412
+ )
2413
+ . unwrap ( ) ;
2414
+
2415
+ let mut bytes = vec ! [ ] ;
2416
+ signer_message. consensus_serialize ( & mut bytes) . unwrap ( ) ;
2417
+
2418
+ // check for raw content for avoiding regressions when structure changes
2419
+ let raw_signer_message: Vec < & [ u8 ] > = vec ! [
2420
+ /* active_signer_protocol_version*/ & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ] ,
2421
+ /* local_supported_signer_protocol_version*/ & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 4 ] ,
2422
+ /* content_len*/ & [ 0 , 0 , 0 , 33 ] ,
2423
+ /* burn_block*/ & [ 0x55 ; 20 ] ,
2424
+ /* burn_block_height*/ & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 100 ] ,
2425
+ /* current_miner_variant */ & [ 0x00 ] ,
2426
+ /* replay_transactions */ & [ 0 , 0 , 0 , 0 ] ,
2427
+ ] ;
2428
+
2429
+ assert_eq ! ( bytes, raw_signer_message. concat( ) ) ;
2430
+
2431
+ let signer_message_deserialized =
2432
+ StateMachineUpdate :: consensus_deserialize ( & mut & bytes[ ..] ) . unwrap ( ) ;
2433
+
2434
+ assert_eq ! ( signer_message, signer_message_deserialized) ;
2435
+ }
2319
2436
}
0 commit comments