1616mod simulation;
1717
1818use std:: {
19+ borrow:: Cow ,
1920 convert:: Infallible ,
2021 sync:: { Arc , Mutex } ,
2122 time:: Duration ,
@@ -42,7 +43,11 @@ use common::{
4243 authorize_pubkey_spend:: sign_public_key_spending,
4344 standard_signature:: StandardInputSignature , InputWitness ,
4445 } ,
45- sighash:: { sighashtype:: SigHashType , signature_hash} ,
46+ sighash:: {
47+ input_commitment:: { SighashInputCommitment , TrivialUtxoProvider } ,
48+ sighashtype:: SigHashType ,
49+ signature_hash,
50+ } ,
4651 } ,
4752 stakelock:: StakePoolData ,
4853 timelock:: OutputTimeLock ,
@@ -310,6 +315,17 @@ async fn randomized(#[case] seed: Seed) {
310315#[ case( test_utils:: random:: Seed :: from_entropy( ) ) ]
311316#[ tokio:: test]
312317async fn compare_pool_rewards_with_chainstate_real_state ( #[ case] seed : Seed ) {
318+ use std:: collections:: BTreeMap ;
319+
320+ use common:: chain:: {
321+ signature:: sighash:: input_commitment:: {
322+ make_sighash_input_commitments_for_transaction_inputs, OrderInfo , PoolInfo ,
323+ } ,
324+ OrderId ,
325+ } ;
326+
327+ logging:: init_logging ( ) ;
328+
313329 let mut rng = make_seedable_rng ( seed) ;
314330
315331 let initial_pledge = 40_000 * CoinUnit :: ATOMS_PER_COIN + rng. gen_range ( 10000 ..100000 ) ;
@@ -547,25 +563,47 @@ async fn compare_pool_rewards_with_chainstate_real_state(#[case] seed: Seed) {
547563 sync_and_compare ( & mut tf, block, & mut local_state, pool_id) . await ;
548564
549565 let remaining_coins = remaining_coins - rng. gen_range ( 0 ..10 ) ;
566+ let input1 = TxInput :: from_utxo ( OutPointSourceId :: Transaction ( prev_tx_id) , 0 ) ;
567+ let input2 = TxInput :: from_utxo ( OutPointSourceId :: BlockReward ( prev_block_hash. into ( ) ) , 0 ) ;
550568 let transaction = TransactionBuilder :: new ( )
551- . add_input (
552- TxInput :: from_utxo ( OutPointSourceId :: Transaction ( prev_tx_id) , 0 ) ,
553- InputWitness :: NoSignature ( None ) ,
554- )
555- . add_input (
556- TxInput :: from_utxo ( OutPointSourceId :: BlockReward ( prev_block_hash. into ( ) ) , 0 ) ,
557- InputWitness :: NoSignature ( None ) ,
558- )
569+ . add_input ( input1. clone ( ) , InputWitness :: NoSignature ( None ) )
570+ . add_input ( input2. clone ( ) , InputWitness :: NoSignature ( None ) )
559571 . add_output ( TxOutput :: Transfer (
560572 OutputValue :: Coin ( Amount :: from_atoms ( remaining_coins) ) ,
561573 Destination :: AnyoneCanSpend ,
562574 ) )
563575 . build ( ) ;
564576
577+ let utxos = [ Some ( coin_tx_out) , Some ( from_block_output) ] ;
578+ let decommissioned_pool_staker_balance = local_state
579+ . storage ( )
580+ . transaction_ro ( )
581+ . await
582+ . unwrap ( )
583+ . get_pool_data ( pool_id)
584+ . await
585+ . unwrap ( )
586+ . unwrap ( )
587+ . staker_balance ( )
588+ . unwrap ( ) ;
589+ let input_commitments = make_sighash_input_commitments_for_transaction_inputs (
590+ & [ input1, input2] ,
591+ & TrivialUtxoProvider ( & utxos) ,
592+ & BTreeMap :: < PoolId , PoolInfo > :: from ( [ (
593+ pool_id,
594+ PoolInfo {
595+ staker_balance : decommissioned_pool_staker_balance,
596+ } ,
597+ ) ] ) ,
598+ & BTreeMap :: < OrderId , OrderInfo > :: new ( ) ,
599+ & chain_config,
600+ tf. next_block_height ( ) ,
601+ )
602+ . unwrap ( ) ;
565603 let sighash = signature_hash (
566604 SigHashType :: default ( ) ,
567605 transaction. transaction ( ) ,
568- & [ Some ( & coin_tx_out ) , Some ( & from_block_output ) ] ,
606+ & input_commitments ,
569607 1 ,
570608 )
571609 . unwrap ( ) ;
@@ -787,7 +825,10 @@ async fn reorg_locked_balance(#[case] seed: Seed) {
787825 let sighash = signature_hash (
788826 SigHashType :: default ( ) ,
789827 spend_transaction. transaction ( ) ,
790- & [ Some ( & lock_for_block_count) , Some ( & lock_until_height) ] ,
828+ & [
829+ SighashInputCommitment :: Utxo ( Cow :: Borrowed ( & lock_for_block_count) ) ,
830+ SighashInputCommitment :: Utxo ( Cow :: Borrowed ( & lock_until_height) ) ,
831+ ] ,
791832 idx,
792833 )
793834 . unwrap ( ) ;
@@ -865,7 +906,10 @@ async fn reorg_locked_balance(#[case] seed: Seed) {
865906 let sighash = signature_hash (
866907 SigHashType :: default ( ) ,
867908 spend_time_locked. transaction ( ) ,
868- & [ Some ( & lock_for_sec) , Some ( & lock_until_time) ] ,
909+ & [
910+ SighashInputCommitment :: Utxo ( Cow :: Borrowed ( & lock_for_sec) ) ,
911+ SighashInputCommitment :: Utxo ( Cow :: Borrowed ( & lock_until_time) ) ,
912+ ] ,
869913 idx,
870914 )
871915 . unwrap ( ) ;
0 commit comments