22
22
23
23
use minotari_app_grpc:: {
24
24
tari_rpc,
25
- tari_rpc:: { pow_algo:: PowAlgos , NewBlockTemplate , NewBlockTemplateRequest , PowAlgo } ,
25
+ tari_rpc:: { pow_algo:: PowAlgos , GetIdentityRequest , NewBlockTemplate , NewBlockTemplateRequest , PowAlgo } ,
26
26
} ;
27
27
use 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 } ;
29
30
use tari_core:: {
30
31
consensus:: ConsensusManager ,
31
32
transactions:: {
@@ -35,6 +36,7 @@ use tari_core::{
35
36
transaction_components:: { RangeProofType , WalletOutput } ,
36
37
} ,
37
38
} ;
39
+ use tari_crypto:: tari_utilities:: ByteArray ;
38
40
39
41
use crate :: TariWorld ;
40
42
@@ -57,14 +59,23 @@ pub fn register_miner_process(world: &mut TariWorld, miner_name: String, base_no
57
59
}
58
60
59
61
pub async fn mine_blocks ( world : & mut TariWorld , miner_name : String , num_blocks : u64 ) {
62
+ let miner = world. get_miner ( & miner_name) ;
60
63
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 ) ;
61
76
62
77
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 ;
68
79
}
69
80
}
70
81
@@ -76,13 +87,13 @@ async fn create_base_node_client(world: &TariWorld, miner_name: &String) -> Base
76
87
BaseNodeClient :: connect ( base_node_grpc_url) . await . unwrap ( )
77
88
}
78
89
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 ) {
80
91
let ( block_template, _) = create_block_template_with_coinbase (
81
92
base_client,
82
93
0 ,
83
94
& world. key_manager ,
84
95
& world. script_key_id ( ) . await ,
85
- & world . default_payment_address ,
96
+ payment_address ,
86
97
false ,
87
98
& world. consensus_manager ,
88
99
)
@@ -96,65 +107,14 @@ async fn mine_block(world: &TariWorld, base_client: &mut BaseNodeClient) {
96
107
. into_inner ( ) ;
97
108
let block = block_result. block . unwrap ( ) ;
98
109
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
100
111
let submit_res = base_client. submit_block ( block) . await . unwrap ( ) . into_inner ( ) ;
101
112
log:: info!(
102
113
"Block {} successfully mined at height {:?}" ,
103
114
tari_crypto:: tari_utilities:: hex:: to_hex( & submit_res. block_hash) ,
104
115
block_template. header. unwrap( ) . height
105
116
) ;
106
117
}
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
-
158
118
async fn create_block_template_with_coinbase (
159
119
base_client : & mut BaseNodeClient ,
160
120
weight : u64 ,
0 commit comments