Skip to content

Commit

Permalink
Fix MG tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3 committed Nov 27, 2024
1 parent 798106a commit 0a6f3d7
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 23 deletions.
60 changes: 47 additions & 13 deletions protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,18 @@ impl ChannelFactory {
.extranonces
.next_extended(max_extranonce_size as usize)
.unwrap();
let extranonce_with_stripped_data = extranonce
.into_prefix(self.extranonces.get_prefix_len(), &[])
.unwrap();
let success_with_stirpped_extranonce_add_data = OpenExtendedMiningChannelSuccess {
request_id,
channel_id,
target: target.clone(),
extranonce_size: max_extranonce_size,
extranonce_prefix: extranonce_with_stripped_data,
};
self.extended_channels
.insert(channel_id, success_with_stirpped_extranonce_add_data);
let extranonce_prefix = extranonce
.into_prefix(
self.extranonces.get_prefix_len(),
Expand All @@ -370,7 +382,6 @@ impl ChannelFactory {
extranonce_size: max_extranonce_size,
extranonce_prefix,
};
self.extended_channels.insert(channel_id, success.clone());
let mut result = vec![Mining::OpenExtendedMiningChannelSuccess(success)];
if let Some((job, _)) = &self.get_last_valid_job() {
let mut job = job.clone();
Expand Down Expand Up @@ -909,9 +920,7 @@ impl ChannelFactory {
} => upstream_target.clone(),
};

let (downstream_target, extranonce) = self
.get_channel_specific_mining_info(&m)
.ok_or(Error::ShareDoNotMatchAnyChannel)?;
let (downstream_target, extranonce) = self.get_channel_specific_mining_info(&m)?;
let extranonce_1_len = self.extranonces.get_range0_len();
let extranonce_2 = extranonce[extranonce_1_len..].to_vec();
match &mut m {
Expand Down Expand Up @@ -1037,10 +1046,16 @@ impl ChannelFactory {
}
}
/// Returns the downstream target and extranonce for the channel
fn get_channel_specific_mining_info(&self, m: &Share) -> Option<(mining_sv2::Target, Vec<u8>)> {
fn get_channel_specific_mining_info(
&self,
m: &Share,
) -> Result<(mining_sv2::Target, Vec<u8>), Error> {
match m {
Share::Extended(share) => {
let channel = self.extended_channels.get(&m.get_channel_id())?;
let channel = self

Check warning on line 1055 in protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs

View check run for this annotation

Codecov / codecov/patch

protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs#L1055

Added line #L1055 was not covered by tests
.extended_channels
.get(&m.get_channel_id())
.ok_or(Error::ShareDoNotMatchAnyChannel)?;

Check warning on line 1058 in protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs

View check run for this annotation

Codecov / codecov/patch

protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs#L1057-L1058

Added lines #L1057 - L1058 were not covered by tests
let extranonce_prefix = channel.extranonce_prefix.to_vec();
let dowstream_target = channel.target.clone().into();
let extranonce = [&extranonce_prefix[..], &share.extranonce.to_vec()[..]]
Expand All @@ -1052,8 +1067,9 @@ impl ChannelFactory {
self.extranonces.get_len(),
extranonce.len()
);
return Err(Error::InvalidCoinbase);

Check warning on line 1070 in protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs

View check run for this annotation

Codecov / codecov/patch

protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs#L1070

Added line #L1070 was not covered by tests
}
Some((dowstream_target, extranonce))
Ok((dowstream_target, extranonce))

Check warning on line 1072 in protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs

View check run for this annotation

Codecov / codecov/patch

protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs#L1072

Added line #L1072 was not covered by tests
}
Share::Standard((share, group_id)) => match &self.kind {
ExtendedChannelKind::Pool => {
Expand All @@ -1066,9 +1082,16 @@ impl ChannelFactory {
.standard_channels_for_hom_downstreams
.get(&share.channel_id);
};
Some((
channel?.target.clone(),
channel?.extranonce.clone().to_vec(),
Ok((
channel
.ok_or(Error::ShareDoNotMatchAnyChannel)?
.target
.clone(),
channel
.ok_or(Error::ShareDoNotMatchAnyChannel)?
.extranonce
.clone()
.to_vec(),
))
}
ExtendedChannelKind::Proxy { .. } | ExtendedChannelKind::ProxyJd { .. } => {
Expand All @@ -1081,9 +1104,16 @@ impl ChannelFactory {
.standard_channels_for_hom_downstreams
.get(&share.channel_id);
};
Some((
channel?.target.clone(),
channel?.extranonce.clone().to_vec(),
Ok((
channel
.ok_or(Error::ShareDoNotMatchAnyChannel)?

Check warning on line 1109 in protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs

View check run for this annotation

Codecov / codecov/patch

protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs#L1109

Added line #L1109 was not covered by tests
.target
.clone(),
channel
.ok_or(Error::ShareDoNotMatchAnyChannel)?
.extranonce
.clone()
.to_vec(),
))
}
},
Expand Down Expand Up @@ -1228,6 +1258,10 @@ impl PoolChannelFactory {
// This initialise a PoolChannelFactory for a JDC that can not have
// additional_coinbase_script_data as it is set only by the pool.
assert!(self.additional_coinbase_script_data.is_empty());
self.channel_to_additional_coinbase_script_data.insert(
channel_id,
(self.additional_coinbase_script_data.clone(), None),
);
self.inner.replicate_upstream_extended_channel_only_jd(
target,
extranonce,
Expand Down
2 changes: 1 addition & 1 deletion test/config/pool-config-sri-tp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ coinbase_outputs = [
{ output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
]
# Pool signature (string to be included in coinbase tx)
pool_signature = "Stratum v2 SRI Pool"
pool_signature = "Stratum v2 SRI"
2 changes: 1 addition & 1 deletion test/config/pool-mock-tp-standard-coverage.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ coinbase_outputs = [
{ output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
]
# Pool signature (string to be included in coinbase tx)
pool_signature = "Stratum v2 SRI Pool"
pool_signature = "Stratum v2 SRI"
2 changes: 1 addition & 1 deletion test/config/pool-mock-tp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ coinbase_outputs = [
{ output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
]
# Pool signature (string to be included in coinbase tx)
pool_signature = "Stratum v2 SRI Pool"
pool_signature = "Stratum v2 SRI"
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"user_identity": "",
"nominal_hash_rate": 10,
"max_target": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
"min_extranonce_size": 16
"min_extranonce_size": 8
},
"replace_fields": [["request_id", "ARBITRARY"]],
"id": "open_extended_mining_channel"
Expand Down Expand Up @@ -54,7 +54,7 @@
[
[
"extranonce_size",
{"U16": 16}
{"U16": 8}
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
[
[
"coinbase_tx_prefix",
{"B064K": [2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 56, 3, 76, 163, 38, 0, 83, 116, 114, 97, 116, 117, 109, 32, 118, 50, 32, 83, 82, 73, 32, 80, 111, 111, 108]}
{"B064K": [2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 32, 3, 76, 163, 38, 0]}
],

[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"type": "SubmitSharesStandard",
"channel_id": 1,
"sequence_number": 0,
"job_id": 0,
"job_id": 1,
"nonce": 927894720,
"ntime": 1671039088,
"version": 536870912
Expand All @@ -66,8 +66,8 @@
"type": "SubmitSharesStandard",
"channel_id": 1,
"sequence_number": 0,
"job_id": 0,
"nonce": 1751,
"job_id": 1,
"nonce": 1752,
"ntime": 1671116742,
"version": 536870912
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"message": {
"id": 0,
"method": "mining.submit",
"params": ["username", "0", "0000000000000000", "641577b0", "7a600640"]
"params": ["username", "0", "0000000000", "641577b0", "7a600640"]
},
"id": "mining.submit"
}
Expand Down

0 comments on commit 0a6f3d7

Please sign in to comment.