diff options
author | Gav Wood <i@gavwood.com> | 2015-03-04 18:55:22 +0800 |
---|---|---|
committer | Gav Wood <i@gavwood.com> | 2015-03-06 19:45:25 +0800 |
commit | bdab1475d6bb4af99149fb399a21d1c71cc6cda8 (patch) | |
tree | e991e1437719de45adb140041116f7e4e0ba9f4e | |
parent | 983514a42ad56e2082d95a60e6c4e2f356c2e343 (diff) | |
download | dexon-solidity-bdab1475d6bb4af99149fb399a21d1c71cc6cda8.tar.gz dexon-solidity-bdab1475d6bb4af99149fb399a21d1c71cc6cda8.tar.zst dexon-solidity-bdab1475d6bb4af99149fb399a21d1c71cc6cda8.zip |
New Proof-of-Work.
-rw-r--r-- | block.cpp | 112 | ||||
-rw-r--r-- | dagger.cpp | 2 | ||||
-rw-r--r-- | webthreestubclient.h | 3 |
3 files changed, 97 insertions, 20 deletions
@@ -201,8 +201,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); @@ -281,27 +285,97 @@ 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; - overwriteBlockHeader(o, current_BlockHeader); + + if (o.count("blockHeader")) + { + if (o["blockHeader"].get_obj().size() != 14) + { + + BlockInfo tmp = currentBlockHeader; + + if (o["blockHeader"].get_obj().count("parentHash")) + tmp.parentHash = h256(o["blockHeader"].get_obj()["parentHash"].get_str()); + + if (o["blockHeader"].get_obj().count("uncleHash")) + tmp.sha3Uncles = h256(o["blockHeader"].get_obj()["uncleHash"].get_str()); + + if (o["blockHeader"].get_obj().count("coinbase")) + tmp.coinbaseAddress = Address(o["blockHeader"].get_obj()["coinbase"].get_str()); + + if (o["blockHeader"].get_obj().count("stateRoot")) + tmp.stateRoot = h256(o["blockHeader"].get_obj()["stateRoot"].get_str()); + + if (o["blockHeader"].get_obj().count("transactionsTrie")) + tmp.transactionsRoot = h256(o["blockHeader"].get_obj()["transactionsTrie"].get_str()); + + if (o["blockHeader"].get_obj().count("receiptTrie")) + tmp.receiptsRoot = h256(o["blockHeader"].get_obj()["receiptTrie"].get_str()); + + if (o["blockHeader"].get_obj().count("bloom")) + tmp.logBloom = LogBloom(o["blockHeader"].get_obj()["bloom"].get_str()); + + if (o["blockHeader"].get_obj().count("difficulty")) + tmp.difficulty = toInt(o["blockHeader"].get_obj()["difficulty"]); + + if (o["blockHeader"].get_obj().count("number")) + tmp.number = toInt(o["blockHeader"].get_obj()["number"]); + + if (o["blockHeader"].get_obj().count("gasLimit")) + tmp.gasLimit = toInt(o["blockHeader"].get_obj()["gasLimit"]); + + if (o["blockHeader"].get_obj().count("gasUsed")) + tmp.gasUsed = toInt(o["blockHeader"].get_obj()["gasUsed"]); + + if (o["blockHeader"].get_obj().count("timestamp")) + tmp.timestamp = toInt(o["blockHeader"].get_obj()["timestamp"]); + + if (o["blockHeader"].get_obj().count("extraData")) + tmp.extraData = importByteArray(o["blockHeader"].get_obj()["extraData"].get_str()); + + // find new valid nonce + + if (tmp != currentBlockHeader) + { + currentBlockHeader = tmp; + cout << "new header!\n"; + ProofOfWork pow; + MineInfo ret; + ProofOfWork::Proof proof; + while (!ProofOfWork::verify(currentBlockHeader)) + { + tie(ret, proof) = pow.mine(currentBlockHeader, 10000, true, true); + ProofOfWork::assignResult(proof, currentBlockHeader); + } + } + } + else + { + // take the blockheader as is + const bytes c_blockRLP = createBlockRLPFromFields(o["blockHeader"].get_obj()); + const RLP c_bRLP(c_blockRLP); + 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; @@ -321,7 +395,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()); @@ -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(); |