Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Remove todos in protocols #854

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions .github/workflows/release-libs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,26 @@

name: Release Libs

on:
# Manually run by going to "Actions/Release" in Github and running the workflow
workflow_dispatch:
on:
pull_request:
branches:
- main

jobs:
libs_publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Run check-versioning-lib-release.sh
run: |
./check-versioning-lib-release.sh
if [ $? -eq 1 ]; then
echo "Script returned exit code 1, halting the workflow"
exit 1
fi

- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -138,20 +150,25 @@ jobs:
- name: Publish crate jd_client
continue-on-error: true
run: |
cargo publish --manifest-path=roles/jd-client/Cargo.toml
cd roles/jd-client
cargo publish
- name: Publish crate jd_server
continue-on-error: true
run: |
cargo publish --manifest-path=roles/jd-server/Cargo.toml
cd roles/jd-server
cargo publish
- name: Publish crate mining_proxy_sv2
continue-on-error: true
run: |
cargo publish --manifest-path=roles/mining-proxy/Cargo.toml
cd roles/mining-proxy
cargo publish
- name: Publish crate pool_sv2
continue-on-error: true
run: |
cargo publish --manifest-path=roles/pool/Cargo.toml
cd roles/pool
cargo publish
- name: Publish crate translator_sv2
continue-on-error: true
run: |
cargo publish --manifest-path=roles/translator/Cargo.toml
cd roles/translator
cargo publish
53 changes: 53 additions & 0 deletions check-versioning-lib-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

git fetch origin main
git fetch origin dev

crates=(
"utils/buffer"
"protocols/v2/binary-sv2/no-serde-sv2/derive_codec"
"protocols/v2/binary-sv2/no-serde-sv2/codec"
"protocols/v2/binary-sv2/serde-sv2"
"protocols/v2/binary-sv2/binary-sv2"
"protocols/v2/const-sv2"
"protocols/v2/framing-sv2"
"protocols/v2/noise-sv2"
"protocols/v2/codec-sv2"
"protocols/v2/subprotocols/common-messages"
"protocols/v2/subprotocols/job-declaration"
"protocols/v2/subprotocols/mining"
"protocols/v2/subprotocols/template-distribution"
"protocols/v2/sv2-ffi"
"protocols/v2/roles-logic-sv2"
"protocols/v1"
"utils/bip32-key-derivation"
"utils/error-handling"
"utils/key-utils"
"roles/roles-utils/network-helpers"
"roles/roles-utils/rpc"
"roles/jd-client"
"roles/jd-server"
"roles/mining-proxy"
"roles/pool"
"roles/translator"
)

# Loop through each crate
for crate in "${crates[@]}"; do
cd "$crate"

# Check if there were any changes between dev and main
git diff --quiet "origin/dev" "origin/main" -- .
if [ $? -ne 0 ]; then

# Check if crate versions on dev and main are identical
version_dev=$(git show origin/dev:./Cargo.toml | awk -F' = ' '$1 == "version" {gsub(/[ "]+/, "", $2); print $2}')
version_main=$(git show origin/main:./Cargo.toml | awk -F' = ' '$1 == "version" {gsub(/[ "]+/, "", $2); print $2}')
if [ "$version_dev" = "$version_main" ]; then
echo "Changes detected in crate $crate between dev and main branches! Versions on dev and main branches are identical ($version_dev), so you should bump the crate version on dev before merging into main."
exit 1
fi
fi

cd - >/dev/null
done
2 changes: 1 addition & 1 deletion protocols/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions protocols/v2/binary-sv2/binary-sv2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pub use binary_codec_sv2::{self, Decodable as Deserialize, Encodable as Serializ
#[cfg(not(feature = "with_serde"))]
pub use derive_codec_sv2::{Decodable as Deserialize, Encodable as Serialize};

pub fn clone_message<T: Serialize>(_: T) -> T {
todo!()
}
//pub fn clone_message<T: Serialize>(_: T) -> T {
// todo!()
//}

pub fn u256_from_int<V: Into<u64>>(value: V) -> U256<'static> {
// initialize u256 as a bytes vec of len 24
Expand Down
26 changes: 16 additions & 10 deletions protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ pub enum OnNewShare {

impl OnNewShare {
/// convert standard share into extended share
pub fn into_extended(&mut self, extranonce: Vec<u8>, up_id: u32) {
pub fn into_extended(&mut self, extranonce: Vec<u8>, up_id: u32) -> Result<(), Error> {
match self {
OnNewShare::SendErrorDownstream(_) => (),
OnNewShare::SendErrorDownstream(_) => Ok(()),
OnNewShare::SendSubmitShareUpstream((share, template_id)) => match share {
Share::Extended(_) => (),
Share::Extended(_) => Ok(()),
Share::Standard((share, _)) => {
let share = SubmitSharesExtended {
channel_id: up_id,
Expand All @@ -90,11 +90,12 @@ impl OnNewShare {
extranonce: extranonce.try_into().unwrap(),
};
*self = Self::SendSubmitShareUpstream((Share::Extended(share), *template_id));
Ok(())
}
},
OnNewShare::RelaySubmitShareUpstream => (),
OnNewShare::RelaySubmitShareUpstream => Ok(()),
OnNewShare::ShareMeetBitcoinTarget((share, t_id, coinbase, ext)) => match share {
Share::Extended(_) => (),
Share::Extended(_) => Ok(()),
Share::Standard((share, _)) => {
let share = SubmitSharesExtended {
channel_id: up_id,
Expand All @@ -111,9 +112,10 @@ impl OnNewShare {
coinbase.clone(),
ext.to_vec(),
));
Ok(())
}
},
OnNewShare::ShareMeetDownstreamTarget => todo!(),
OnNewShare::ShareMeetDownstreamTarget => Err(Error::ShareDownstreamTargetNowAllowed),
}
}
}
Expand Down Expand Up @@ -859,8 +861,10 @@ impl ChannelFactory {
coinbase,
extranonce.to_vec(),
));
res.into_extended(extranonce_, up_id);
Ok(res)
match res.into_extended(extranonce_, up_id) {
Ok(()) => Ok(res),
Err(e) => Err(e),
}
}
ExtendedChannelKind::Pool => Ok(OnNewShare::ShareMeetBitcoinTarget((
m,
Expand All @@ -875,8 +879,10 @@ impl ChannelFactory {
let upstream_extranonce_space = self.extranonces.get_range0_len();
let extranonce = extranonce[upstream_extranonce_space..].to_vec();
let mut res = OnNewShare::SendSubmitShareUpstream((m, template_id));
res.into_extended(extranonce, up_id);
Ok(res)
match res.into_extended(extranonce, up_id) {
Ok(()) => Ok(res),
Err(e) => Err(e),
}
}
ExtendedChannelKind::Pool => {
Ok(OnNewShare::SendSubmitShareUpstream((m, template_id)))
Expand Down
2 changes: 2 additions & 0 deletions protocols/v2/roles-logic-sv2/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub enum Error {
HashrateError(InputError),
LogicErrorMessage(std::boxed::Box<AllMessages<'static>>),
JDSMissingTransactions,
ShareDownstreamTargetNowAllowed,
}

impl From<BinarySv2Error> for Error {
Expand Down Expand Up @@ -153,6 +154,7 @@ impl Display for Error {
HashrateError(e) => write!(f, "Impossible to get Hashrate: {:?}", e),
LogicErrorMessage(e) => write!(f, "Message is well formatted but can not be handled: {:?}", e),
JDSMissingTransactions => write!(f, "JD server cannot propagate the block: missing transactions"),
ShareDownstreamTargetNowAllowed => write!(f, "Share that meets downstream target is not allowed"),
}
}
}
15 changes: 12 additions & 3 deletions protocols/v2/roles-logic-sv2/src/handlers/job_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ where
.safe_lock(|x| x.handle_provide_missing_transactions(message))
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
}
Ok(_) => todo!(),
// the following messsages are not supposed to be received from the server
Ok(JobDeclaration::AllocateMiningJobToken(_)) => panic!(),
Ok(JobDeclaration::DeclareMiningJob(_)) => panic!(),
Ok(JobDeclaration::IdentifyTransactionsSuccess(_)) => panic!(),
Ok(JobDeclaration::ProvideMissingTransactionsSuccess(_)) => panic!(),
Ok(JobDeclaration::SubmitSolution(_)) => panic!(),
Err(e) => Err(e),
}
}
Expand Down Expand Up @@ -176,8 +181,12 @@ where
.safe_lock(|x| x.handle_submit_solution(message))
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
}

Ok(_) => todo!(),
// the following messsages are not supposed to be received from the client
Ok(JobDeclaration::DeclareMiningJobError(_)) => panic!(),
Ok(JobDeclaration::DeclareMiningJobSuccess(_)) => panic!(),
Ok(JobDeclaration::AllocateMiningJobTokenSuccess(_)) => panic!(),
Ok(JobDeclaration::IdentifyTransactions(_)) => panic!(),
Ok(JobDeclaration::ProvideMissingTransactions(_)) => panic!(),
Err(e) => Err(e),
}
}
Expand Down
2 changes: 2 additions & 0 deletions protocols/v2/roles-logic-sv2/src/job_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ impl JobsCreators {
.copied()
}
// TODO how many templates can we have at max
// reported as issue on github
// https://github.com/stratum-mining/stratum/issues/842
_ => todo!("{:#?}", template.len()),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ impl<'decoder> SetupConnection<'decoder> {
work_selection && version_rolling
}
// TODO
// this todo requires a bit of restructuring and it is reported as an issue
// https://github.com/stratum-mining/stratum/issues/853
_ => todo!(),
}
}
Expand Down
Loading
Loading