Add a new RPC parity_submitWorkDetail
similar eth_submitWork
but return block hash
#9404
Conversation
It has more details (block hash, error message, and more in future) in its response and not only the `true` or `false`.
It looks like @YihaoPeng hasn't signed our Contributor License Agreement, yet.
You can read and sign our full Contributor License Agreement at the following URL: https://cla.parity.io Once you've signed, please reply to this thread with Many thanks, Parity Technologies CLA Bot |
[clabot:check] |
It looks like @YihaoPeng signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
The issue is the same as #9126 -- it's recommended to have an EIP first before modifying the However, if you want, you can change this PR to use |
rpc/src/v1/impls/eth.rs
Outdated
@@ -801,6 +801,36 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> Eth for EthClient< | |||
} | |||
} | |||
|
|||
fn submit_work_detail(&self, nonce: RpcH64, pow_hash: RpcH256, mix_hash: RpcH256) -> Result<SubmitDetailResult> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And just a small grumble -- we can refactor L806 to L813 to a helper function to avoid duplicate codes with submit_work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your advice. I have modified it.
Does I need to move codes from |
@YihaoPeng For |
OK, I will try to move the code. The problem is that the implementation of this feature is in |
Opps, a wrong click... I'm sorry. |
@sorpaas The code is moved to I reseted my However, I cannot avoid to duplicate codes because my low Rust skills. 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that this new RPC is nearly identical to eth_submitWork
, where the only change is the return type (from bool
to H256
). However, it indeed looks like a valid usecase and cannot be fit it into eth_submitWork
without breaking existing users' code.
Not sure if there're better ways to handle this.
eth_submitWorkDetail
similar eth_submitWork
but response block hashparity_submitWorkDetail
similar eth_submitWork
but return block hash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A final grumble and I think this should be ready for merge!
@@ -449,4 +450,26 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where | |||
.map(|res| res.into_iter().map(|res| res.output.into()).collect()) | |||
.map_err(errors::call) | |||
} | |||
|
|||
fn submit_work_detail(&self, nonce: H64, pow_hash: H256, mix_hash: H256) -> Result<H256> { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am trying to make such a change, but I am having trouble.
The question is what type of miner
and client
should be.
I noticed that in paraity.rs
and eth.rs
they are all defined as generics and two definitions are different.
I tried to use generics but I encountered an error like this:
pub fn submit_work_detail<C: BlockChainClient, M: MinerService>(client: C, miner: M, nonce: H64, pow_hash: H256, mix_hash: H256) -> Result<H256, Error> {...}
The trait bound `std::sync::Arc<C>: ethcore::miner::BlockChainClient` is not satisfied
rpc/src/v1/impls/eth.rs:785:9
the trait `ethcore::miner::BlockChainClient` is not implemented for `std::sync::Arc<C>`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I have got it. This works:
pub fn submit_work_detail<C: BlockChainClient, M: MinerService>(client: &Arc<C>, miner: &Arc<M>, nonce: H64, pow_hash: H256, mix_hash: H256) -> Result<H256, Error> {...}
Please rebase on master |
I tried rebase but every commit needs to resolve the conflict. A ---- (@SwimmingTiger == @YihaoPeng) |
@SwimmingTiger I think you'll just need to do a merge ( |
OK, I have pushed the merging. |
Purpose
There is a problem with Ethereum's current RPC
eth_submitWork
: the miner cannot know the real block hash after a submission, so it is impossible to query the block from a blockchain browser or perform any subsequent automated processing.So I added a new RPC
parity_submitWorkDetail
to Parity. It is similar toeth_submitWork
but will return the block hash on success, and return an explicit error message on failure.Params and Response
Example:
call RPC with curl:
response with error message:
response with block hash:
Personal Description
I am a complete Rust newcomer and this is the first time I read and change Rust's code. I have completed the function and tested it and it works fine. But I don't know if it is enough as a pull request.
If I need to do something else, please let me know.
Testing and Usage
I tested it on the Ropsten chain and the submission worked fine. (This is a very simple patch and I think it may not require further testing.)
Open source POW pool BTCPool uses this patch to record its submited block to database.
BTC.COM pool has mined 17 blocks in Ethereum Mainnet with its Parity node with this patch.