Skip to content

Commit b2dd540

Browse files
author
fi3
committed
Fix MG tests
1 parent 798106a commit b2dd540

File tree

8 files changed

+53
-23
lines changed

8 files changed

+53
-23
lines changed

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

+43-13
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,18 @@ impl ChannelFactory {
357357
.extranonces
358358
.next_extended(max_extranonce_size as usize)
359359
.unwrap();
360+
let extranonce_with_stripped_data = extranonce
361+
.into_prefix(self.extranonces.get_prefix_len(), &[])
362+
.unwrap();
363+
let success_with_stirpped_extranonce_add_data = OpenExtendedMiningChannelSuccess {
364+
request_id,
365+
channel_id,
366+
target: target.clone(),
367+
extranonce_size: max_extranonce_size,
368+
extranonce_prefix: extranonce_with_stripped_data,
369+
};
370+
self.extended_channels
371+
.insert(channel_id, success_with_stirpped_extranonce_add_data);
360372
let extranonce_prefix = extranonce
361373
.into_prefix(
362374
self.extranonces.get_prefix_len(),
@@ -370,7 +382,6 @@ impl ChannelFactory {
370382
extranonce_size: max_extranonce_size,
371383
extranonce_prefix,
372384
};
373-
self.extended_channels.insert(channel_id, success.clone());
374385
let mut result = vec![Mining::OpenExtendedMiningChannelSuccess(success)];
375386
if let Some((job, _)) = &self.get_last_valid_job() {
376387
let mut job = job.clone();
@@ -909,9 +920,7 @@ impl ChannelFactory {
909920
} => upstream_target.clone(),
910921
};
911922

912-
let (downstream_target, extranonce) = self
913-
.get_channel_specific_mining_info(&m)
914-
.ok_or(Error::ShareDoNotMatchAnyChannel)?;
923+
let (downstream_target, extranonce) = self.get_channel_specific_mining_info(&m)?;
915924
let extranonce_1_len = self.extranonces.get_range0_len();
916925
let extranonce_2 = extranonce[extranonce_1_len..].to_vec();
917926
match &mut m {
@@ -1037,10 +1046,16 @@ impl ChannelFactory {
10371046
}
10381047
}
10391048
/// Returns the downstream target and extranonce for the channel
1040-
fn get_channel_specific_mining_info(&self, m: &Share) -> Option<(mining_sv2::Target, Vec<u8>)> {
1049+
fn get_channel_specific_mining_info(
1050+
&self,
1051+
m: &Share,
1052+
) -> Result<(mining_sv2::Target, Vec<u8>), Error> {
10411053
match m {
10421054
Share::Extended(share) => {
1043-
let channel = self.extended_channels.get(&m.get_channel_id())?;
1055+
let channel = self
1056+
.extended_channels
1057+
.get(&m.get_channel_id())
1058+
.ok_or(Error::ShareDoNotMatchAnyChannel)?;
10441059
let extranonce_prefix = channel.extranonce_prefix.to_vec();
10451060
let dowstream_target = channel.target.clone().into();
10461061
let extranonce = [&extranonce_prefix[..], &share.extranonce.to_vec()[..]]
@@ -1052,8 +1067,9 @@ impl ChannelFactory {
10521067
self.extranonces.get_len(),
10531068
extranonce.len()
10541069
);
1070+
return Err(Error::InvalidCoinbase);
10551071
}
1056-
Some((dowstream_target, extranonce))
1072+
Ok((dowstream_target, extranonce))
10571073
}
10581074
Share::Standard((share, group_id)) => match &self.kind {
10591075
ExtendedChannelKind::Pool => {
@@ -1066,9 +1082,16 @@ impl ChannelFactory {
10661082
.standard_channels_for_hom_downstreams
10671083
.get(&share.channel_id);
10681084
};
1069-
Some((
1070-
channel?.target.clone(),
1071-
channel?.extranonce.clone().to_vec(),
1085+
Ok((
1086+
channel
1087+
.ok_or(Error::ShareDoNotMatchAnyChannel)?
1088+
.target
1089+
.clone(),
1090+
channel
1091+
.ok_or(Error::ShareDoNotMatchAnyChannel)?
1092+
.extranonce
1093+
.clone()
1094+
.to_vec(),
10721095
))
10731096
}
10741097
ExtendedChannelKind::Proxy { .. } | ExtendedChannelKind::ProxyJd { .. } => {
@@ -1081,9 +1104,16 @@ impl ChannelFactory {
10811104
.standard_channels_for_hom_downstreams
10821105
.get(&share.channel_id);
10831106
};
1084-
Some((
1085-
channel?.target.clone(),
1086-
channel?.extranonce.clone().to_vec(),
1107+
Ok((
1108+
channel
1109+
.ok_or(Error::ShareDoNotMatchAnyChannel)?
1110+
.target
1111+
.clone(),
1112+
channel
1113+
.ok_or(Error::ShareDoNotMatchAnyChannel)?
1114+
.extranonce
1115+
.clone()
1116+
.to_vec(),
10871117
))
10881118
}
10891119
},

test/config/pool-config-sri-tp.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ coinbase_outputs = [
1111
{ output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
1212
]
1313
# Pool signature (string to be included in coinbase tx)
14-
pool_signature = "Stratum v2 SRI Pool"
14+
pool_signature = "Stratum v2 SRI"

test/config/pool-mock-tp-standard-coverage.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ coinbase_outputs = [
1212
{ output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
1313
]
1414
# Pool signature (string to be included in coinbase tx)
15-
pool_signature = "Stratum v2 SRI Pool"
15+
pool_signature = "Stratum v2 SRI"

test/config/pool-mock-tp.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ coinbase_outputs = [
1212
{ output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
1313
]
1414
# Pool signature (string to be included in coinbase tx)
15-
pool_signature = "Stratum v2 SRI Pool"
15+
pool_signature = "Stratum v2 SRI"

test/message-generator/test/pool-sri-test-extended_0/pool-sri-test-extended_0.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"user_identity": "",
1515
"nominal_hash_rate": 10,
1616
"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],
17-
"min_extranonce_size": 16
17+
"min_extranonce_size": 8
1818
},
1919
"replace_fields": [["request_id", "ARBITRARY"]],
2020
"id": "open_extended_mining_channel"
@@ -54,7 +54,7 @@
5454
[
5555
[
5656
"extranonce_size",
57-
{"U16": 16}
57+
{"U16": 8}
5858
]
5959
]
6060
]

test/message-generator/test/pool-sri-test-extended_1/pool-sri-test-extended_1.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
[
6767
[
6868
"coinbase_tx_prefix",
69-
{"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]}
69+
{"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]}
7070
],
7171

7272
[

test/message-generator/test/standard-coverage-test/standard-coverage-test.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"type": "SubmitSharesStandard",
5555
"channel_id": 1,
5656
"sequence_number": 0,
57-
"job_id": 0,
57+
"job_id": 1,
5858
"nonce": 927894720,
5959
"ntime": 1671039088,
6060
"version": 536870912
@@ -66,8 +66,8 @@
6666
"type": "SubmitSharesStandard",
6767
"channel_id": 1,
6868
"sequence_number": 0,
69-
"job_id": 0,
70-
"nonce": 1751,
69+
"job_id": 1,
70+
"nonce": 1752,
7171
"ntime": 1671116742,
7272
"version": 536870912
7373
},

test/message-generator/test/translation-proxy-old-share/translation-proxy-old-share.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"message": {
2323
"id": 0,
2424
"method": "mining.submit",
25-
"params": ["username", "0", "0000000000000000", "641577b0", "7a600640"]
25+
"params": ["username", "0", "0000000000", "641577b0", "7a600640"]
2626
},
2727
"id": "mining.submit"
2828
}

0 commit comments

Comments
 (0)