Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GitGab19 committed Sep 25, 2023
1 parent 8ebf95a commit e127068
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 15 deletions.
11 changes: 9 additions & 2 deletions roles/pool/pool-config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ authority_secret_key = "2Z1FZug7mZNyM63ggkm37r4oKQ29khLjAvEx43rGkFN47RcJ2t"
cert_validity_sec = 3600
test_only_listen_adress_plain = "0.0.0.0:34250"
listen_address = "0.0.0.0:34254"
# list of compressed or uncompressed pubkeys for coinbase payout (only supports 1 item in the array at this point)

# list of coinbase outputs used to build the coinbase tx
# ! right now only one output is supported, so comment all the ones you don't need !
coinbase_outputs = [
"02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0",
{ output_script_type = "P2PK", output_script_value = "02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0" },
#{ output_script_type = "P2PKH", output_script_value = "02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0" },
#{ output_script_type = "P2SH", output_script_value = "02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0" },
#{ output_script_type = "P2WSH", output_script_value = "02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0" },
#{ output_script_type = "P2WPKH", output_script_value = "02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0" },
#{ output_script_type = "P2TR", output_script_value = "02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0" },
]

# Template Provider config
Expand Down
1 change: 1 addition & 0 deletions roles/pool/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum PoolError {
pub enum OutputScriptError {
UnknownScriptType(String),
InvalidScript(String),
EmptyCoinbaseOutputs(String)
}

impl std::fmt::Display for PoolError {
Expand Down
4 changes: 2 additions & 2 deletions roles/pool/src/lib/mining_pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ impl Pool {
creator,
share_per_min,
kind,
pool_coinbase_outputs,
pool_coinbase_outputs.unwrap(),
)));
let pool = Arc::new(Mutex::new(Pool {
downstreams: HashMap::with_hasher(BuildNoHashHasher::default()),
Expand Down Expand Up @@ -599,7 +599,7 @@ mod test {
let _coinbase_tx_value_remaining: u64 = 5000000000;
let _coinbase_tx_outputs_count = 0;
let coinbase_tx_locktime = 0;
let coinbase_tx_outputs: Vec<bitcoin::TxOut> = crate::get_coinbase_output(&config);
let coinbase_tx_outputs: Vec<bitcoin::TxOut> = crate::get_coinbase_output(&config).unwrap();
// extranonce len set to max_extranonce_size in `ChannelFactory::new_extended_channel()`
let extranonce_len = 32;

Expand Down
32 changes: 24 additions & 8 deletions roles/pool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,23 @@ pub type EitherFrame = StandardEitherFrame<Message>;

const BLOCK_REWARD: u64 = 625_000_000;

pub fn get_coinbase_output(config: &Configuration) -> Vec<TxOut> {
config
pub fn get_coinbase_output(config: &Configuration) -> Result<Vec<TxOut>, OutputScriptError> {
let result = config
.coinbase_outputs
.iter()
.map(|coinbase_output| {
let output_script: Script = coinbase_output.try_into().unwrap();
TxOut {
value: crate::BLOCK_REWARD, // It's not important here, since it will be updated by NewTemplate from TP
coinbase_output.try_into().map(|output_script| TxOut {
value: crate::BLOCK_REWARD,
script_pubkey: output_script,
}
})
})
.collect()
.collect::<Result<Vec<TxOut>, OutputScriptError>>();

if result.is_ok() && result.as_ref().unwrap().is_empty() {
Err(OutputScriptError::EmptyCoinbaseOutputs("Empty coinbase outputs".to_string()))
} else {
result
}
}

impl TryFrom<&CoinbaseOutput> for Script {
Expand Down Expand Up @@ -230,7 +235,18 @@ async fn main() {
let (s_solution, r_solution) = bounded(10);
let (s_message_recv_signal, r_message_recv_signal) = bounded(10);
info!("Pool INITIALIZING with config: {:?}", &args.config_path);
let coinbase_output_len = get_coinbase_output(&config).len() as u32;
let coinbase_output_result = get_coinbase_output(&config);
let coinbase_output_len;

Check failure on line 239 in roles/pool/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy-check (ubuntu-latest)

unneeded late initialization
match coinbase_output_result {
Ok(coinbase_output) => {
coinbase_output_len = coinbase_output.len() as u32;
}
Err(err) => {
error!("Failed to get coinbase output: {:?}", err);
return;
}
}
//let coinbase_output_len = get_coinbase_output(&config).unwrap().len() as u32;
let template_rx_res = TemplateRx::connect(
config.tp_address.parse().unwrap(),
s_new_t,
Expand Down
6 changes: 4 additions & 2 deletions test/config/pool-mock-tp-bad-coinbase.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ authority_public_key = "2di19GHYQnAZJmEpoUeP7C3Eg9TCcksHr23rZCC83dvUiZgiDL"
authority_secret_key = "2Z1FZug7mZNyM63ggkm37r4oKQ29khLjAvEx43rGkFN47RcJ2t"
cert_validity_sec = 3600
test_only_listen_adress_plain = "0.0.0.0:34250"
# list of coinbase outputs used to build the coinbase tx
# ! right now only one output is supported, so comment all the ones you don't need !
coinbase_outputs = [
"04466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276728176c3c6431f8eeda4538dc37c865e2784f3a9e77d044f33e407797e1278",
]
{ output_script_type = "P2PK", output_script_value = "04466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276728176c3c6431f8eeda4538dc37c865e2784f3a9e77d044f33e407797e1278" },
]
2 changes: 1 addition & 1 deletion test/message-generator/test/bad-pool-config-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"WithConditions": {
"conditions": [
{
"output_string": "Failed to parse config:",
"output_string": "Failed to get coinbase output:",
"output_location": "StdOut",
"condition": true
}
Expand Down

0 comments on commit e127068

Please sign in to comment.