@@ -17,6 +17,7 @@ use std::num::NonZeroU64;
17
17
18
18
use crate :: { framework:: BlockOutputs , TestChainstate , TestFramework } ;
19
19
use chainstate:: chainstate_interface:: ChainstateInterface ;
20
+ use chainstate_storage:: { BlockchainStorageRead , TipStorageTag } ;
20
21
use chainstate_types:: pos_randomness:: PoSRandomness ;
21
22
use common:: {
22
23
chain:: {
@@ -30,9 +31,9 @@ use common::{
30
31
} ,
31
32
stakelock:: StakePoolData ,
32
33
tokens:: { TokenData , TokenTransfer } ,
33
- Block , ChainConfig , ConsensusUpgrade , Destination , GenBlock , Genesis , NetUpgrades ,
34
- OutPointSourceId , PoolId , RequiredConsensus , TxInput , TxOutput , UpgradeVersion ,
35
- UtxoOutPoint ,
34
+ Block , ChainConfig , ConsensusUpgrade , Destination , GenBlock , Genesis , Mlt , NetUpgrades ,
35
+ OutPointSourceId , PoSChainConfig , PoolId , RequiredConsensus , TxInput , TxOutput ,
36
+ UpgradeVersion , UtxoOutPoint ,
36
37
} ,
37
38
primitives:: { per_thousand:: PerThousand , Amount , BlockHeight , Compact , Id , Idable , H256 } ,
38
39
Uint256 ,
@@ -42,6 +43,7 @@ use crypto::{
42
43
random:: { CryptoRng , Rng } ,
43
44
vrf:: { VRFPrivateKey , VRFPublicKey } ,
44
45
} ;
46
+ use pos_accounting:: { PoSAccountingDB , PoSAccountingView } ;
45
47
use test_utils:: nft_utils:: * ;
46
48
47
49
pub fn empty_witness ( rng : & mut impl Rng ) -> InputWitness {
@@ -357,7 +359,7 @@ pub fn create_chain_config_with_staking_pool(
357
359
(
358
360
BlockHeight :: new( 1 ) ,
359
361
UpgradeVersion :: ConsensusUpgrade ( ConsensusUpgrade :: PoS {
360
- initial_difficulty: Uint256 :: MAX . into( ) ,
362
+ initial_difficulty: Some ( Uint256 :: MAX . into( ) ) ,
361
363
config: create_unittest_pos_config( ) ,
362
364
} ) ,
363
365
) ,
@@ -408,20 +410,27 @@ pub fn produce_kernel_signature(
408
410
. unwrap ( )
409
411
}
410
412
413
+ // TODO: consider replacing this function with consensus::pos::stake
411
414
#[ allow( clippy:: too_many_arguments) ]
412
415
pub fn pos_mine (
416
+ storage : & impl BlockchainStorageRead ,
417
+ pos_config : & PoSChainConfig ,
413
418
initial_timestamp : BlockTimestamp ,
414
419
kernel_outpoint : UtxoOutPoint ,
415
420
kernel_witness : InputWitness ,
416
421
vrf_sk : & VRFPrivateKey ,
417
422
sealed_epoch_randomness : PoSRandomness ,
418
423
pool_id : PoolId ,
419
- pool_balance : Amount ,
424
+ final_supply : Mlt ,
420
425
epoch_index : EpochIndex ,
421
426
target : Compact ,
422
427
) -> Option < ( PoSData , BlockTimestamp ) > {
423
- let mut timestamp = initial_timestamp;
428
+ let pos_db = PoSAccountingDB :: < _ , TipStorageTag > :: new ( & storage) ;
429
+
430
+ let pool_balance = pos_db. get_pool_balance ( pool_id) . unwrap ( ) . unwrap ( ) ;
431
+ let pledge_amount = pos_db. get_pool_data ( pool_id) . unwrap ( ) . unwrap ( ) . pledge_amount ( ) ;
424
432
433
+ let mut timestamp = initial_timestamp;
425
434
for _ in 0 ..1000 {
426
435
let transcript = chainstate_types:: vrf_tools:: construct_transcript (
427
436
epoch_index,
@@ -440,12 +449,15 @@ pub fn pos_mine(
440
449
441
450
let vrf_pk = VRFPublicKey :: from_private_key ( vrf_sk) ;
442
451
if consensus:: check_pos_hash (
452
+ pos_config. consensus_version ( ) ,
443
453
epoch_index,
444
454
& sealed_epoch_randomness,
445
455
& pos_data,
446
456
& vrf_pk,
447
457
timestamp,
458
+ pledge_amount,
448
459
pool_balance,
460
+ final_supply. to_amount_atoms ( ) ,
449
461
)
450
462
. is_ok ( )
451
463
{
0 commit comments