Skip to content

Commit

Permalink
Bumber rustc to 1.75, Add MSRV, Fix clippy and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
UnidenifiedUser committed Jan 3, 2024
1 parent 4f9a1f0 commit 6aad5df
Show file tree
Hide file tree
Showing 22 changed files with 74 additions and 91 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.70.0
toolchain: 1.75.0
override: true

- name: Checkout repository
Expand All @@ -35,7 +35,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.70.0
toolchain: 1.75.0
override: true

- name: Checkout repository
Expand All @@ -59,7 +59,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.70.0
toolchain: 1.75.0
override: true

- name: Checkout repository
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.70.0
toolchain: 1.75.0
override: true

- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clippy-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.70.0
toolchain: 1.75.0
override: true
components: clippy
- uses: actions-rs/cargo@v1
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

[![codecov](https://codecov.io/gh/stratum-mining/stratum/branch/main/graph/badge.svg)](https://codecov.io/gh/stratum-mining/stratum)

**DEVELOPMENT IS DONE IN THE DEV BRANCH**
**LATEST WORKING CODE IS IN THE DEV BRANCH**
**MAIN BRANCH IS LATEST RELEASED SOURCES**

The Stratum protocol defines how miners, proxies, and pools communicate to contribute hashrate to
the Bitcoin network.

## MSRV
Minimum Supported Rust Version: 1.75.0

## Table of Contents

Expand Down
4 changes: 2 additions & 2 deletions examples/sv1-client-and-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl<'a> IsServer<'a> for Server<'a> {

fn notify(&mut self) -> Result<json_rpc::Message, Error<'a>> {
let hex = "ffff";
server_to_client::Notify {
Ok(server_to_client::Notify {
job_id: "ciao".to_string(),
prev_hash: prevhash_from_hex(hex),
coin_base1: hex.try_into()?,
Expand All @@ -304,7 +304,7 @@ impl<'a> IsServer<'a> for Server<'a> {
time: HexU32Be(5609),
clean_jobs: true,
}
.try_into()
.into())
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/template-provider-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async fn test_1() {
let message_type = submit_solution.message_type();
let frame: StdFrame =
Sv2Frame::from_message(submit_solution, message_type, extension_type, channel_bit).unwrap();
let frame: EitherFrame = frame.try_into().unwrap();
let frame: EitherFrame = frame.into();
dbg!(sender.send(frame).await.unwrap());
async_std::task::sleep(std::time::Duration::from_secs(10)).await;
}
6 changes: 3 additions & 3 deletions protocols/v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ pub trait IsServer<'a> {
self.set_extranonce1(Some(extra_nonce1.clone()));
self.set_extranonce2_size(Some(extra_nonce2_size));

server_to_client::SetExtranonce {
Ok(server_to_client::SetExtranonce {
extra_nonce1,
extra_nonce2_size,
}
.try_into()
.into())
}
// {"params":["00003000"], "id":null, "method": "mining.set_version_mask"}
// fn update_version_rolling_mask
Expand All @@ -228,7 +228,7 @@ pub trait IsServer<'a> {

fn handle_set_difficulty(&mut self, value: f64) -> Result<json_rpc::Message, Error> {
let set_difficulty = server_to_client::SetDifficulty { value };
Ok(set_difficulty.try_into()?)
Ok(set_difficulty.into())
}
}

Expand Down
18 changes: 6 additions & 12 deletions protocols/v1/src/methods/client_to_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,9 @@ impl<'a> Subscribe<'a> {
extra_nonce2_size,
id: self.id,
};
match Message::try_from(response) {
Ok(r) => match r {
Message::OkResponse(r) => r,
_ => todo!(),
},
Err(_) => todo!(),
match Message::from(response) {
Message::OkResponse(r) => r,
_ => unreachable!(),
}
}
}
Expand Down Expand Up @@ -377,12 +374,9 @@ impl Configure {
version_rolling,
minimum_difficulty,
};
match Message::try_from(response) {
Ok(r) => match r {
Message::OkResponse(r) => r,
_ => todo!(),
},
Err(_) => todo!(),
match Message::from(response) {
Message::OkResponse(r) => r,
_ => unreachable!(),
}
}

Expand Down
64 changes: 27 additions & 37 deletions protocols/v1/src/methods/server_to_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,21 @@ pub struct Notify<'a> {
pub clean_jobs: bool,
}

impl<'a> TryFrom<Notify<'a>> for Message {
type Error = Error<'a>;

fn try_from(notify: Notify) -> Result<Self, Error> {
let prev_hash: Value = notify.prev_hash.try_into()?;
let coin_base1: Value = notify.coin_base1.try_into()?;
let coin_base2: Value = notify.coin_base2.try_into()?;
impl<'a> From<Notify<'a>> for Message {
fn from(notify: Notify) -> Self {
let prev_hash: Value = notify.prev_hash.into();
let coin_base1: Value = notify.coin_base1.into();
let coin_base2: Value = notify.coin_base2.into();
let mut merkle_branch: Vec<Value> = vec![];
for mb in notify.merkle_branch {
let mb: Value = mb.try_into()?;
let mb: Value = mb.into();
merkle_branch.push(mb);
}
let merkle_branch = JArrary(merkle_branch);
let version: Value = notify.version.try_into()?;
let bits: Value = notify.bits.try_into()?;
let time: Value = notify.time.try_into()?;
Ok(Message::Notification(Notification {
let version: Value = notify.version.into();
let bits: Value = notify.bits.into();
let time: Value = notify.time.into();
Message::Notification(Notification {
method: "mining.notify".to_string(),
params: (&[
notify.job_id.into(),
Expand All @@ -79,7 +77,7 @@ impl<'a> TryFrom<Notify<'a>> for Message {
notify.clean_jobs.into(),
][..])
.into(),
}))
})
}
}

Expand Down Expand Up @@ -202,16 +200,14 @@ pub struct SetExtranonce<'a> {
pub extra_nonce2_size: usize,
}

impl<'a> TryFrom<SetExtranonce<'a>> for Message {
type Error = Error<'a>;

fn try_from(se: SetExtranonce) -> Result<Self, Error> {
let extra_nonce1: Value = se.extra_nonce1.try_into()?;
impl<'a> From<SetExtranonce<'a>> for Message {
fn from(se: SetExtranonce) -> Self {
let extra_nonce1: Value = se.extra_nonce1.into();
let extra_nonce2_size: Value = se.extra_nonce2_size.into();
Ok(Message::Notification(Notification {
Message::Notification(Notification {
method: "mining.set_extranonce".to_string(),
params: (&[extra_nonce1, extra_nonce2_size][..]).into(),
}))
})
}
}

Expand Down Expand Up @@ -245,15 +241,13 @@ pub struct SetVersionMask {
version_mask: HexU32Be,
}

impl TryFrom<SetVersionMask> for Message {
type Error = Error<'static>;

fn try_from(sv: SetVersionMask) -> Result<Self, Error<'static>> {
let version_mask: Value = sv.version_mask.try_into()?;
Ok(Message::Notification(Notification {
impl From<SetVersionMask> for Message {
fn from(sv: SetVersionMask) -> Self {
let version_mask: Value = sv.version_mask.into();
Message::Notification(Notification {
method: "mining.set_version".to_string(),
params: (&[version_mask][..]).into(),
}))
})
}
}

Expand Down Expand Up @@ -467,9 +461,7 @@ impl From<Configure> for Message {
fn from(co: Configure) -> Self {
let mut params = serde_json::Map::new();
if let Some(version_rolling_) = co.version_rolling {
let mut version_rolling: serde_json::Map<String, Value> =
// infallible
version_rolling_.try_into().unwrap();
let mut version_rolling: serde_json::Map<String, Value> = version_rolling_.into();
params.append(&mut version_rolling);
};
if let Some(min_diff) = co.minimum_difficulty {
Expand Down Expand Up @@ -628,20 +620,18 @@ impl VersionRollingParams {
}
}

impl TryFrom<VersionRollingParams> for serde_json::Map<String, Value> {
type Error = Error<'static>;

fn try_from(vp: VersionRollingParams) -> Result<Self, Error<'static>> {
impl From<VersionRollingParams> for serde_json::Map<String, Value> {
fn from(vp: VersionRollingParams) -> Self {
let version_rolling: Value = vp.version_rolling.into();
let version_rolling_mask: Value = vp.version_rolling_mask.try_into()?;
let version_rolling_min_bit_count: Value = vp.version_rolling_min_bit_count.try_into()?;
let version_rolling_mask: Value = vp.version_rolling_mask.into();
let version_rolling_min_bit_count: Value = vp.version_rolling_min_bit_count.into();
let mut params = serde_json::Map::new();
params.insert("version-rolling".to_string(), version_rolling);
params.insert("version-rolling.mask".to_string(), version_rolling_mask);
params.insert(
"version-rolling.min-bit-count".to_string(),
version_rolling_min_bit_count,
);
Ok(params)
params
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl ChannelFactory {
extranonce_size: u16,
) -> Option<()> {
self.channel_to_group_id.insert(channel_id, 0);
let extranonce_prefix = extranonce.try_into().unwrap();
let extranonce_prefix = extranonce.into();
let success = OpenExtendedMiningChannelSuccess {
request_id: 0,
channel_id,
Expand Down Expand Up @@ -827,7 +827,7 @@ impl ChannelFactory {
|| tracing::level_enabled!(tracing::Level::TRACE)
{
debug!("Bitcoin target: {:?}", bitcoin_target);
let upstream_target: binary_sv2::U256 = upstream_target.clone().try_into().unwrap();
let upstream_target: binary_sv2::U256 = upstream_target.clone().into();
let mut upstream_target = upstream_target.to_vec();
upstream_target.reverse();
debug!("Upstream target: {:?}", upstream_target.to_vec().to_hex());
Expand Down
1 change: 0 additions & 1 deletion protocols/v2/roles-logic-sv2/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ pub fn hash_rate_to_target(
// if we want 5 shares per minute, this means that s=60/5=12 seconds interval between shares
// this quantity will be at the numerator, so we multiply the result by 100 again later
let shares_occurrency_frequence = 60_f64 / share_per_min;
let shares_occurrency_frequence = shares_occurrency_frequence;

let h_times_s = hashrate * shares_occurrency_frequence;
let h_times_s = h_times_s as u128;
Expand Down
5 changes: 2 additions & 3 deletions protocols/v2/sv2-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,8 @@ fn encode_(
#[no_mangle]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub extern "C" fn free_decoder(decoder: *mut DecoderWrapper) {
// let mut decoder = unsafe { Box::from_raw(decoder) };
unsafe { Box::from_raw(decoder) };
// Box::into_raw(decoder);
let decoder = unsafe { Box::from_raw(decoder) };
drop(decoder);
}

/// # Safety
Expand Down
2 changes: 1 addition & 1 deletion roles/jd-client/src/downstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ impl ParseDownstreamCommonMessages<roles_logic_sv2::routing_logic::NoRouting>
version_rolling: true,
};
self.status.pair(data);
Ok(SendToCommon::Respond(response.try_into().unwrap()))
Ok(SendToCommon::Respond(response.into()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion roles/jd-client/src/job_declarator/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ParseServerJobDeclarationMessages for JobDeclarator {
) -> Result<SendTo, Error> {
let message_identify_transactions = IdentifyTransactionsSuccess {
request_id: message.request_id,
tx_data_hashes: Vec::new().try_into().unwrap(),
tx_data_hashes: Vec::new().into(),
};
let message_enum =
JobDeclaration::IdentifyTransactionsSuccess(message_identify_transactions);
Expand Down
12 changes: 4 additions & 8 deletions roles/jd-client/src/upstream_sv2/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,18 +723,14 @@ impl ParseUpstreamMiningMessages<Downstream, NullDownstreamMiningSelector, NoRou
m: roles_logic_sv2::mining_sv2::SetTarget,
) -> Result<roles_logic_sv2::handlers::mining::SendTo<Downstream>, RolesLogicError> {
if let Some(factory) = self.channel_factory.as_mut() {
factory.update_target_for_channel(
m.channel_id,
m.maximum_target.clone().try_into().unwrap(),
);
factory.set_target(&mut m.maximum_target.clone().try_into().unwrap());
factory.update_target_for_channel(m.channel_id, m.maximum_target.clone().into());
factory.set_target(&mut m.maximum_target.clone().into());
}
if let Some(downstream) = &self.downstream {
let _ = downstream.safe_lock(|d| {
let factory = d.status.get_channel();
factory.set_target(&mut m.maximum_target.clone().try_into().unwrap());
factory
.update_target_for_channel(m.channel_id, m.maximum_target.try_into().unwrap());
factory.set_target(&mut m.maximum_target.clone().into());
factory.update_target_for_channel(m.channel_id, m.maximum_target.into());
});
}
Ok(SendTo::RelaySameMessageToRemote(
Expand Down
2 changes: 1 addition & 1 deletion roles/jd-server/src/lib/job_declarator/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
} else {
let message_provide_missing_transactions = ProvideMissingTransactions {
request_id: message.request_id,
unknown_tx_position_list: missing_txs.try_into().unwrap(),
unknown_tx_position_list: missing_txs.into(),
};
let message_enum_provide_missing_transactions =
JobDeclaration::ProvideMissingTransactions(
Expand Down
2 changes: 1 addition & 1 deletion roles/mining-proxy/src/lib/downstream_mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ impl
self.status.pair(data);
Ok(SendToCommon::RelayNewMessageToRemote(
Arc::new(Mutex::new(())),
message.try_into().unwrap(),
message.into(),
))
}
}
Expand Down
7 changes: 3 additions & 4 deletions roles/mining-proxy/src/lib/upstream_mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,7 @@ impl UpstreamMiningNode {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
]
.try_into()
.unwrap(),
.into(),
min_extranonce_size: crate::MIN_EXTRANONCE_SIZE,
},
));
Expand Down Expand Up @@ -934,7 +933,7 @@ impl
&mut self,
m: OpenExtendedMiningChannelSuccess,
) -> Result<SendTo<DownstreamMiningNode>, Error> {
let extranonce_prefix: Extranonce = m.extranonce_prefix.clone().try_into().unwrap();
let extranonce_prefix: Extranonce = m.extranonce_prefix.clone().into();
let range_0 = 0..m.extranonce_prefix.clone().to_vec().len();
let range_1 = range_0.end..(range_0.end + EXTRANONCE_RANGE_1_LENGTH);
let range_2 = range_1.end..(range_0.end + m.extranonce_size as usize);
Expand All @@ -950,7 +949,7 @@ impl
self.group_id.clone(),
extranonces,
self.downstream_share_per_minute,
m.target.clone().try_into().unwrap(),
m.target.clone().into(),
m.channel_id,
);
Ok(SendTo::None(None))
Expand Down
Loading

0 comments on commit 6aad5df

Please sign in to comment.