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

Add stratum style mining protocol #444

Merged
merged 2 commits into from
Jul 24, 2018

Conversation

kakao-jun-e
Copy link
Contributor

@kakao-jun-e kakao-jun-e commented Jul 20, 2018

Fix #352

I have tested as below:

RUST_LOG="stratum=trace,miner=trace" cargo run -- -c blake_pow --author "0000000000000000000000000000000000000001"

#517784000 2018-07-20 15:57:59  main TRACE miner  Set author to 0x0000000000000000000000000000000000000001
#517784000 2018-07-20 15:57:59  main INFO codechain  Starting client
#517784000 2018-07-20 15:57:59  main INFO codechain  Handshake Listening on 127.0.0.1:3485
#517784000 2018-07-20 15:57:59  main INFO discovery  Node runs with unstructured discovery
#517784000 2018-07-20 15:57:59  main INFO codechain  RPC Listening on 8080
#517784000 2018-07-20 15:57:59  IO Worker #2 INFO sync  Sync extension initialized
#517784000 2018-07-20 15:57:59  main INFO codechain  IPC Listening on /tmp/jsonrpc.ipc
#517784000 2018-07-20 15:57:59  main INFO codechain  STRATUM Listening on 8008
#517784000 2018-07-20 15:57:59  main INFO test_script  Initialization complete
#517784000 2018-07-20 15:58:03  http.worker0 TRACE miner  prepare_work_sealing: entering
#517784000 2018-07-20 15:58:03  http.worker0 TRACE miner  prepare_work_sealing: have_work=false
#517784000 2018-07-20 15:58:03  http.worker0 TRACE miner  prepare_block: No existing work - making new block
#517784000 2018-07-20 15:58:03  http.worker0 TRACE miner  Adding parcel 0xadc81db96da9ff107fd9f23f53a58c8ae8a043ea128078ec56c2dd1437c5fbb0 took 880.88µs
#517784000 2018-07-20 15:58:03  http.worker0 TRACE miner  Pushed 1/1 parcels
#517784000 2018-07-20 15:58:03  http.worker0 TRACE miner  prepare_work: Checking whether we need to reseal: orig=None last=None, this=0xbaed3dec4a0e529d5e0a5d6be433ee1e568c4f899f64a993e4254ce7209ed0ec
#517784000 2018-07-20 15:58:03  http.worker0 TRACE miner  prepare_work: Pushing a new, refreshed or borrowed pending 0xbaed…d0ec...
#517784000 2018-07-20 15:58:03  http.worker0 TRACE miner  prepare_work: leaving (last=Some(0xbaed3dec4a0e529d5e0a5d6be433ee1e568c4f899f64a993e4254ce7209ed0ec))
#517784000 2018-07-20 15:58:03  http.worker0 TRACE stratum  Notify work
#517784000 2018-07-20 15:58:03  http.worker0 TRACE stratum  pushing work for 0 workers (payload: '{ "id": 17, "method": "mining.notify", "params": ["0xbaed3dec4a0e529d5e0a5d6be433ee1e568c4f899f64a993e4254ce7209ed0ec","0x7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"] }')

@sgkim126 sgkim126 requested review from kseo and remagpie July 20, 2018 05:22
@sgkim126 sgkim126 added the miner label Jul 20, 2018
fn can_respond_to_submition() {
let addr = SocketAddr::from_str("127.0.0.1:19990").unwrap();
let _stratum =
Stratum::start(&addr, Arc::new(DummyManager::build().of_initial(r#"["dummy autorize payload"]"#)), None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autorize -> authorize

impl Default for Config {
fn default() -> Self {
Config {
listen_addr: "0.0.0.0:0".parse().unwrap(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove :0 here. We already have port number in Config.


/// Start STRATUM job dispatcher and register it in the miner
pub fn register(cfg: &Config, miner: Arc<Miner>, client: Arc<Client>) -> Result<(), Error> {
let stratum = Stratum::start(cfg, miner.clone(), client.clone())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to clone client here.

use std::sync::Arc;

use cstratum::PushWorkHandler;
use cstratum::{Error as StratumServiceError, JobDispatcher, Stratum as StratumService};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge these two lines.

}

/// Start STRATUM job dispatcher and register it in the miner
pub fn register(cfg: &Config, miner: Arc<Miner>, client: Arc<Client>) -> Result<(), Error> {
Copy link
Contributor

@remagpie remagpie Jul 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason for implementing this here?
This kind of registering logics are usually implemented in main.rs.

self.job()
}

fn job(&self) -> Option<String> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this function always return None.
What is expected behavior of this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not needed at the moment, so it may be good to delete, but it is needed to operate a minor (reward, ...). 0c69701

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you expand your comment a bit more?
I can't understand what it means that it's safe to delete, but miner wouldn't operate with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kais-DkM I think this commit is the basic of stratum protocol for codechain. so I aim to provide the same degree as getwork and submit JSON-RPC.

As you know that, stratum protocols for bitcoin and ethereum provide additional information in this part to a miner.

Could you discuss it with me at the developer meeting?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I was confused with miner module in codechain.
I guess it's okay for now, but it's worth a discussion. Let's talk about this later again.

@@ -496,4 +486,44 @@ mod tests {
response
);
}

#[test]
fn can_respond_to_submition() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt if we can call this test as "unit test".
Usually scenarios included in source code is for unit testing, but this one seems to test operations on real world environment(e.g. opening tcp stream).
I think it'd be better test this kind of operations on integration tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a new one to existing test.
But I agree with you, so I will apply this to an integrated test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually meant that we should remove this test from this file..... but it seems there already exists similar test cases here.
I think we should file an issue about this problem, and revisit this issue later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed an issue at #457

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kais-DkM Thank you, I checked #457 out

@remagpie
Copy link
Contributor

Please merge your commits into one commit.

@kakao-jun-e kakao-jun-e force-pushed the release/stratum branch 2 times, most recently from 8509cc3 to b49c7db Compare July 24, 2018 04:26
remagpie
remagpie previously approved these changes Jul 24, 2018
@remagpie
Copy link
Contributor

@redongjun Why was this PR closed?

@kakao-jun-e kakao-jun-e reopened this Jul 24, 2018
@kakao-jun-e
Copy link
Contributor Author

@Kais-DkM Sorry, I think I made a mistake.

@kakao-jun-e
Copy link
Contributor Author

@Kais-DkM I merged the latest changes from master.

@remagpie remagpie merged commit 68b9d83 into CodeChain-io:master Jul 24, 2018
@kakao-jun-e kakao-jun-e deleted the release/stratum branch August 8, 2018 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants