2222
2323use minotari_app_grpc:: {
2424 tari_rpc,
25- tari_rpc:: { pow_algo:: PowAlgos , NewBlockTemplate , NewBlockTemplateRequest , PowAlgo } ,
25+ tari_rpc:: { pow_algo:: PowAlgos , GetIdentityRequest , NewBlockTemplate , NewBlockTemplateRequest , PowAlgo } ,
2626} ;
2727use minotari_node_grpc_client:: BaseNodeGrpcClient ;
28- use tari_common_types:: tari_address:: TariAddress ;
28+ use tari_common:: configuration:: Network ;
29+ use tari_common_types:: { tari_address:: TariAddress , types:: PublicKey } ;
2930use tari_core:: {
3031 consensus:: ConsensusManager ,
3132 transactions:: {
@@ -35,6 +36,7 @@ use tari_core::{
3536 transaction_components:: { RangeProofType , WalletOutput } ,
3637 } ,
3738} ;
39+ use tari_crypto:: tari_utilities:: ByteArray ;
3840
3941use crate :: TariWorld ;
4042
@@ -57,14 +59,23 @@ pub fn register_miner_process(world: &mut TariWorld, miner_name: String, base_no
5759}
5860
5961pub async fn mine_blocks ( world : & mut TariWorld , miner_name : String , num_blocks : u64 ) {
62+ let miner = world. get_miner ( & miner_name) ;
6063 let mut base_client = create_base_node_client ( world, & miner_name) . await ;
64+ let mut wallet_client = world. get_wallet ( & miner. wallet_name ) . create_client ( ) . await ;
65+
66+ let wallet_pk = PublicKey :: from_canonical_bytes (
67+ & wallet_client
68+ . identify ( GetIdentityRequest { } )
69+ . await
70+ . unwrap ( )
71+ . into_inner ( )
72+ . public_key ,
73+ )
74+ . unwrap ( ) ;
75+ let payment_address = TariAddress :: new ( wallet_pk, Network :: LocalNet ) ;
6176
6277 for _ in 0 ..num_blocks {
63- mine_block ( world, & mut base_client) . await ;
64- // Makes less likely that base layer will fail with
65- // "Chain storage error: You tried to execute an invalid Database operation: UTXO 248a... was already marked as
66- // deleted."
67- // tokio::time::sleep(Duration::from_millis(100)).await;
78+ mine_block ( world, & payment_address, & mut base_client) . await ;
6879 }
6980}
7081
@@ -76,13 +87,13 @@ async fn create_base_node_client(world: &TariWorld, miner_name: &String) -> Base
7687 BaseNodeClient :: connect ( base_node_grpc_url) . await . unwrap ( )
7788}
7889
79- async fn mine_block ( world : & TariWorld , base_client : & mut BaseNodeClient ) {
90+ async fn mine_block ( world : & TariWorld , payment_address : & TariAddress , base_client : & mut BaseNodeClient ) {
8091 let ( block_template, _) = create_block_template_with_coinbase (
8192 base_client,
8293 0 ,
8394 & world. key_manager ,
8495 & world. script_key_id ( ) . await ,
85- & world . default_payment_address ,
96+ payment_address ,
8697 false ,
8798 & world. consensus_manager ,
8899 )
@@ -96,65 +107,14 @@ async fn mine_block(world: &TariWorld, base_client: &mut BaseNodeClient) {
96107 . into_inner ( ) ;
97108 let block = block_result. block . unwrap ( ) ;
98109
99- // We don't need to mine, as Localnet blocks have difficulty 1s
110+ // We don't need to mine, as Localnet blocks have difficulty target of 1s
100111 let submit_res = base_client. submit_block ( block) . await . unwrap ( ) . into_inner ( ) ;
101112 log:: info!(
102113 "Block {} successfully mined at height {:?}" ,
103114 tari_crypto:: tari_utilities:: hex:: to_hex( & submit_res. block_hash) ,
104115 block_template. header. unwrap( ) . height
105116 ) ;
106117}
107-
108- // async fn create_block_template_with_coinbase(
109- // base_client: &mut BaseNodeClient,
110- // wallet_client: &mut WalletGrpcClient,
111- // ) -> NewBlockTemplate {
112- // // get the block template from the base node
113- // let template_req = NewBlockTemplateRequest {
114- // algo: Some(PowAlgo {
115- // pow_algo: PowAlgos::Sha3x.into(),
116- // }),
117- // max_weight: 0,
118- // };
119- // let template_res = base_client
120- // .get_new_block_template(template_req)
121- // .await
122- // .unwrap()
123- // .into_inner();
124- //
125- // let NewBlockTemplateResponse {
126- // new_block_template: Some(mut template),
127- // miner_data: Some(miner_data),
128- // ..
129- // } = template_res
130- // else {
131- // panic!("Failed to get block template");
132- // };
133- //
134- // let height = template.header.as_ref().unwrap().height;
135- // let coinbase_res = wallet_client
136- // .get_coinbase(GetCoinbaseRequest {
137- // reward: miner_data.reward,
138- // fee: miner_data.total_fees,
139- // height,
140- // extra: vec![],
141- // })
142- // .await
143- // .unwrap()
144- // .into_inner();
145- //
146- // let mut transaction_body = coinbase_res.transaction.unwrap().body.unwrap();
147- // let tx_out = transaction_body.outputs.remove(0);
148- // let tx_kernel = transaction_body.kernels.remove(0);
149- //
150- // // add the coinbase outputs and kernels to the block template
151- // let body = template.body.as_mut().unwrap();
152- // body.outputs.push(tx_out);
153- // body.kernels.push(tx_kernel);
154- //
155- // template
156- // }
157-
158118async fn create_block_template_with_coinbase (
159119 base_client : & mut BaseNodeClient ,
160120 weight : u64 ,
0 commit comments