-
Notifications
You must be signed in to change notification settings - Fork 266
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
Feature/add submit bitcoin solution new methods #486
Conversation
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.
My comments are mostly style issues, but looks good overall.
Regarding functionality, I would appreciate if someone who knew this better could review the mnr_
methods implementations.
* Full responsibility for processing the request is delegated to MinerServer. | ||
* | ||
* @author Adrian Eidelman | ||
* @author Martin Medina | ||
*/ | ||
public class Web3RskImpl extends Web3Impl { |
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.
Please consider extracting a Web3MnrModule
like here: #483 (in a separate PR!)
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.
Issue created to tackle this in a near future
|
||
int rskTagPosition = Collections.lastIndexOfSubList(coinbaseAsByteList, rskTagAsByteList); | ||
byte[] blockHashForMergedMiningArray = new byte[Keccak256Helper.Size.S256.getValue()/8]; | ||
System.arraycopy(coinbaseAsByteArray, rskTagPosition+ RskMiningConstants.RSK_TAG.length, blockHashForMergedMiningArray, 0, blockHashForMergedMiningArray.length); |
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.
Use Arrays.copyOf
.
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.
Elements needs to be copied into a certain position of an existing array and that can not be done with Arrays.copyOf.
|
||
co.rsk.bitcoinj.core.NetworkParameters params = co.rsk.bitcoinj.params.RegTestParams.get(); | ||
|
||
NetworkParameters params = co.rsk.bitcoinj.params.RegTestParams.get(); | ||
new co.rsk.bitcoinj.core.Context(params); |
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.
Is this dangling new co.rsk.bitcoinj.core.Context
necessary?
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.
good catch, fixed!
} | ||
|
||
public SubmittedBlockInfo mnr_submitBitcoinSolution(String blockHashHex, String blockHeaderHex, String coinbaseHex, String txnHashesHex) { | ||
if (logger.isDebugEnabled()) { |
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.
Using if (logger.isDebugEnabled())
is an antipattern when your log statement doesn't do any 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.
Fixed
} | ||
|
||
private SubmittedBlockInfo parseResultAndReturn(SubmitBlockResult result) { | ||
if("OK".equals(result.getStatus())) { |
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.
How about result.isSuccessful()
?
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.
as a method of the SubmitBlockResult object ?
@@ -32,6 +33,11 @@ | |||
|
|||
boolean isRunning(); | |||
|
|||
SubmitBlockResult submitBitcoinSolution(String blockHashForMergedMining, |
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.
Indent correctly and remove fully-qualified name.
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.
done!
BtcBlock blockWithHeaderOnly, | ||
BtcTransaction coinbase, | ||
List<String> txHashes) { | ||
logger.debug("Received solution with hash {} for merged mining", blockHashForMergedMining); |
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.
All your logs are debug
, but maybe you should consider using info
or trace
|
||
private List<String> parseTransactionHashes(String txnHashesHex) { | ||
List<String> txnHashes = new ArrayList<>(); | ||
for (int start = 0; start < txnHashesHex.length(); start += 64) { |
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.
Please create a constant for 64
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.
Since a last minute optimization this code no longer exists
|
||
public SubmitBlockResult submitBitcoinBlock(String blockHashForMergedMining, co.rsk.bitcoinj.core.BtcBlock bitcoinMergedMiningBlock, boolean lastTag) { | ||
SubmitBlockResult submitBitcoinBlock(String blockHashForMergedMining, BtcBlock bitcoinMergedMiningBlock, boolean lastTag) { |
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.
should this be private?
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.
It's okay to keep it package private
cfd5741
to
534100b
Compare
|
||
// bits indicates which nodes are going to be used for building the partial merkle tree | ||
// for more information please refer to {@link co.rsk.bitcoinj.core.PartialMerkleTree#buildFromLeaves } method | ||
byte[] bits = new byte[(int) Math.ceil(bitList.size() / 8.0)]; |
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.
(bitList.size() + 7) / 8 with integer arithmetic
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.
good idea! change done.
byte[] bitvector = new byte[(int) Math.ceil(txs.size() / 8.0)]; | ||
co.rsk.bitcoinj.core.Utils.setBitLE(bitvector, 0); | ||
return co.rsk.bitcoinj.core.PartialMerkleTree.buildFromLeaves(bitcoinMergedMiningBlock.getParams(), bitvector, txHashes); | ||
byte[] bitvector = new byte[(int) Math.ceil(txHashes.size() / 8.0)]; |
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.
same as before
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.
done!
… hashes. Data sent over network is now of size log_2(block_txs_hash) vs block_txs_hash.
bbd3de0
to
ab52e54
Compare
SonarQube analysis reported 40 issues Top 10 issues
|
New methods to support submission of merged mining solution:
Both receive less information than old submitBitcoinBlock method which is still available for backward compatibility reasons.