aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <i@gavwood.com>2015-03-04 18:55:22 +0800
committerGav Wood <i@gavwood.com>2015-03-04 18:55:22 +0800
commit366b9e8b712453bb1c6b34ba6a8d155fa6733952 (patch)
tree70b86885864c220fe02e75ac03f29f71347870bf
parent14067cb7ed49573caffa6b2ab445a7d625e980bb (diff)
downloaddexon-solidity-366b9e8b712453bb1c6b34ba6a8d155fa6733952.tar.gz
dexon-solidity-366b9e8b712453bb1c6b34ba6a8d155fa6733952.tar.zst
dexon-solidity-366b9e8b712453bb1c6b34ba6a8d155fa6733952.zip
New Proof-of-Work.
-rw-r--r--block.cpp56
-rw-r--r--dagger.cpp2
-rw-r--r--webthreestubclient.h3
3 files changed, 36 insertions, 25 deletions
diff --git a/block.cpp b/block.cpp
index fdf65aff..4441da29 100644
--- a/block.cpp
+++ b/block.cpp
@@ -131,8 +131,12 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin)
// find new valid nonce
ProofOfWork pow;
MineInfo ret;
- while (!ProofOfWork::verify(blockFromFields.headerHash(WithoutNonce), blockFromFields.nonce, blockFromFields.difficulty))
- tie(ret, blockFromFields.nonce) = pow.mine(blockFromFields.headerHash(WithoutNonce), blockFromFields.difficulty, 1000, true, true);
+ ProofOfWork::Proof proof;
+ while (!ProofOfWork::verify(blockFromFields))
+ {
+ tie(ret, proof) = pow.mine(blockFromFields, 1000, true, true);
+ ProofOfWork::assignResult(proof, blockFromFields);
+ }
//update genesis block in json file
o["genesisBlockHeader"].get_obj()["stateRoot"] = toString(blockFromFields.stateRoot);
@@ -211,7 +215,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin)
o["transactions"] = txArray;
o["rlp"] = "0x" + toHex(state.blockData());
- BlockInfo current_BlockHeader = state.info();
+ BlockInfo currentBlockHeader = state.info();
// overwrite blockheader with (possible wrong) data from "blockheader" in filler;
@@ -220,7 +224,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin)
if (o["blockHeader"].get_obj().size() != 14)
{
- BlockInfo tmp = current_BlockHeader;
+ BlockInfo tmp = currentBlockHeader;
if (o["blockHeader"].get_obj().count("parentHash"))
tmp.parentHash = h256(o["blockHeader"].get_obj()["parentHash"].get_str());
@@ -263,14 +267,18 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin)
// find new valid nonce
- if (tmp != current_BlockHeader)
+ if (tmp != currentBlockHeader)
{
- current_BlockHeader = tmp;
+ currentBlockHeader = tmp;
cout << "new header!\n";
ProofOfWork pow;
MineInfo ret;
- while (!ProofOfWork::verify(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.nonce, current_BlockHeader.difficulty))
- tie(ret, current_BlockHeader.nonce) = pow.mine(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.difficulty, 10000, true, true);
+ ProofOfWork::Proof proof;
+ while (!ProofOfWork::verify(currentBlockHeader))
+ {
+ tie(ret, proof) = pow.mine(currentBlockHeader, 10000, true, true);
+ ProofOfWork::assignResult(proof, currentBlockHeader);
+ }
}
}
else
@@ -278,27 +286,27 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin)
// take the blockheader as is
const bytes c_blockRLP = createBlockRLPFromFields(o["blockHeader"].get_obj());
const RLP c_bRLP(c_blockRLP);
- current_BlockHeader.populateFromHeader(c_bRLP, false);
+ currentBlockHeader.populateFromHeader(c_bRLP, false);
}
}
// write block header
mObject oBlockHeader;
- oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash);
- oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles);
- oBlockHeader["coinbase"] = toString(current_BlockHeader.coinbaseAddress);
- oBlockHeader["stateRoot"] = toString(current_BlockHeader.stateRoot);
- oBlockHeader["transactionsTrie"] = toString(current_BlockHeader.transactionsRoot);
- oBlockHeader["receiptTrie"] = toString(current_BlockHeader.receiptsRoot);
- oBlockHeader["bloom"] = toString(current_BlockHeader.logBloom);
- oBlockHeader["difficulty"] = toString(current_BlockHeader.difficulty);
- oBlockHeader["number"] = toString(current_BlockHeader.number);
- oBlockHeader["gasLimit"] = toString(current_BlockHeader.gasLimit);
- oBlockHeader["gasUsed"] = toString(current_BlockHeader.gasUsed);
- oBlockHeader["timestamp"] = toString(current_BlockHeader.timestamp);
- oBlockHeader["extraData"] = toHex(current_BlockHeader.extraData);
- oBlockHeader["nonce"] = toString(current_BlockHeader.nonce);
+ oBlockHeader["parentHash"] = toString(currentBlockHeader.parentHash);
+ oBlockHeader["uncleHash"] = toString(currentBlockHeader.sha3Uncles);
+ oBlockHeader["coinbase"] = toString(currentBlockHeader.coinbaseAddress);
+ oBlockHeader["stateRoot"] = toString(currentBlockHeader.stateRoot);
+ oBlockHeader["transactionsTrie"] = toString(currentBlockHeader.transactionsRoot);
+ oBlockHeader["receiptTrie"] = toString(currentBlockHeader.receiptsRoot);
+ oBlockHeader["bloom"] = toString(currentBlockHeader.logBloom);
+ oBlockHeader["difficulty"] = toString(currentBlockHeader.difficulty);
+ oBlockHeader["number"] = toString(currentBlockHeader.number);
+ oBlockHeader["gasLimit"] = toString(currentBlockHeader.gasLimit);
+ oBlockHeader["gasUsed"] = toString(currentBlockHeader.gasUsed);
+ oBlockHeader["timestamp"] = toString(currentBlockHeader.timestamp);
+ oBlockHeader["extraData"] = toHex(currentBlockHeader.extraData);
+ oBlockHeader["nonce"] = toString(currentBlockHeader.nonce);
o["blockHeader"] = oBlockHeader;
@@ -318,7 +326,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin)
}
RLPStream rlpStream2;
- current_BlockHeader.streamRLP(rlpStream2, WithNonce);
+ currentBlockHeader.streamRLP(rlpStream2, WithNonce);
RLPStream block2(3);
block2.appendRaw(rlpStream2.out());
diff --git a/dagger.cpp b/dagger.cpp
index 9422b6a9..87c49bd7 100644
--- a/dagger.cpp
+++ b/dagger.cpp
@@ -30,6 +30,7 @@ using namespace dev::eth;
int daggerTest()
{
+#if 0
cnote << "Testing ProofOfWork...";
// Test dagger
{
@@ -46,6 +47,7 @@ int daggerTest()
cout << hex << ProofOfWork().eval((h256)(u256)1, (h256)(u256)1);
cout << " " << dec << duration_cast<milliseconds>(steady_clock::now() - s).count() << " ms" << endl;
}
+#endif
return 0;
}
diff --git a/webthreestubclient.h b/webthreestubclient.h
index 70aa9db9..6d97ea67 100644
--- a/webthreestubclient.h
+++ b/webthreestubclient.h
@@ -437,10 +437,11 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
- bool eth_submitWork(const std::string& param1) throw (jsonrpc::JsonRpcException)
+ bool eth_submitWork(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
+ p.append(param2);
Json::Value result = this->CallMethod("eth_submitWork",p);
if (result.isBool())
return result.asBool();