Browse Source

Use sha3(header) rather than sha3(block) for hash.

cl-refactor
Gav Wood 11 years ago
parent
commit
278995e19a
  1. 12
      exp/main.cpp
  2. 5
      libethcore/BlockInfo.cpp
  3. 6
      libethereum/BlockChain.cpp
  4. 5
      libethereum/BlockQueue.cpp
  5. 4
      libethereum/EthereumSession.cpp

12
exp/main.cpp

@ -25,19 +25,24 @@
#include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp> #include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/support_utree.hpp> #include <boost/spirit/include/support_utree.hpp>
#endif
#include <libethential/Log.h> #include <libethential/Log.h>
#include <libethential/Common.h> #include <libethential/Common.h>
#include <libethential/CommonData.h> #include <libethential/CommonData.h>
#include <libethential/RLP.h>
#if 0
#include <libevm/VM.h> #include <libevm/VM.h>
#include "BuildInfo.h" #include "BuildInfo.h"
#endif
using namespace std; using namespace std;
using namespace eth; using namespace eth;
#if 0
#if 0
namespace qi = boost::spirit::qi; namespace qi = boost::spirit::qi;
namespace px = boost::phoenix; namespace px = boost::phoenix;
namespace sp = boost::spirit; namespace sp = boost::spirit;
#if 0
class ASTSymbol: public string class ASTSymbol: public string
{ {
public: public:
@ -291,5 +296,8 @@ int main(int, char**)
killBigints(out); killBigints(out);
cout << endl; cout << endl;
#endif #endif
cnote << RLP(fromHex("f837c0c0b4600160003556601359506301000000600035040f6018590060005660805460016080530160005760003560805760203560003557"));
cnote << toHex(RLPStream(1).append(bytes(54, 0)).out());
return 0; return 0;
} }

5
libethcore/BlockInfo.cpp

@ -71,6 +71,8 @@ h256 BlockInfo::headerHash(bytesConstRef _block)
void BlockInfo::populateFromHeader(RLP const& _header, bool _checkNonce) void BlockInfo::populateFromHeader(RLP const& _header, bool _checkNonce)
{ {
hash = eth::sha3(_header.data());
int field = 0; int field = 0;
try try
{ {
@ -106,10 +108,9 @@ void BlockInfo::populateFromHeader(RLP const& _header, bool _checkNonce)
void BlockInfo::populate(bytesConstRef _block, bool _checkNonce) void BlockInfo::populate(bytesConstRef _block, bool _checkNonce)
{ {
hash = eth::sha3(_block);
RLP root(_block); RLP root(_block);
RLP header = root[0]; RLP header = root[0];
if (!header.isList()) if (!header.isList())
throw InvalidBlockFormat(0, header.data()); throw InvalidBlockFormat(0, header.data());
populateFromHeader(header, _checkNonce); populateFromHeader(header, _checkNonce);

6
libethereum/BlockChain.cpp

@ -193,7 +193,7 @@ h256s BlockChain::sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max
} }
catch (UnknownParent) catch (UnknownParent)
{ {
cwarn << "Unknown parent of block!!!" << eth::sha3(block).abridged(); cwarn << "Unknown parent of block!!!" << BlockInfo::headerHash(block).abridged();
_bq.import(&block, *this); _bq.import(&block, *this);
} }
catch (...){} catch (...){}
@ -233,7 +233,7 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db)
throw; throw;
} }
#endif #endif
auto newHash = eth::sha3(_block); auto newHash = BlockInfo::headerHash(_block);
// Check block doesn't already exist first! // Check block doesn't already exist first!
if (details(newHash)) if (details(newHash))
@ -416,7 +416,7 @@ h256Set BlockChain::allUnclesFrom(h256 _parent) const
h256 p = _parent; h256 p = _parent;
for (unsigned i = 0; i < 6 && p != m_genesisHash; ++i, p = details(p).parent) for (unsigned i = 0; i < 6 && p != m_genesisHash; ++i, p = details(p).parent)
{ {
ret.insert(sha3(RLP(block(p))[0].data())); ret.insert(p); // TODO: check: should this be details(p).parent?
for (auto i: RLP(block(p))[2]) for (auto i: RLP(block(p))[2])
ret.insert(sha3(i.data())); ret.insert(sha3(i.data()));
} }

5
libethereum/BlockQueue.cpp

@ -31,7 +31,7 @@ using namespace eth;
bool BlockQueue::import(bytesConstRef _block, BlockChain const& _bc) bool BlockQueue::import(bytesConstRef _block, BlockChain const& _bc)
{ {
// Check if we already know this block. // Check if we already know this block.
h256 h = sha3(_block); h256 h = BlockInfo::headerHash(_block);
cnote << "Queuing block" << h.abridged() << "for import..."; cnote << "Queuing block" << h.abridged() << "for import...";
@ -61,10 +61,9 @@ bool BlockQueue::import(bytesConstRef _block, BlockChain const& _bc)
return false; return false;
} }
#endif #endif
auto newHash = eth::sha3(_block);
// Check block doesn't already exist first! // Check block doesn't already exist first!
if (_bc.details(newHash)) if (_bc.details(h))
{ {
cnote << "Already known in chain."; cnote << "Already known in chain.";
return false; return false;

4
libethereum/EthereumSession.cpp

@ -319,7 +319,7 @@ bool EthereumSession::interpret(RLP const& _r)
unsigned used = 0; unsigned used = 0;
for (unsigned i = 1; i < _r.itemCount(); ++i) for (unsigned i = 1; i < _r.itemCount(); ++i)
{ {
auto h = sha3(_r[i].data()); auto h = BlockInfo::headerHash(_r[i].data());
if (m_server->noteBlock(h, _r[i].data())) if (m_server->noteBlock(h, _r[i].data()))
used++; used++;
m_askedBlocks.erase(h); m_askedBlocks.erase(h);
@ -332,7 +332,7 @@ bool EthereumSession::interpret(RLP const& _r)
{ {
for (unsigned i = 1; i < _r.itemCount(); ++i) for (unsigned i = 1; i < _r.itemCount(); ++i)
{ {
auto h = sha3(_r[i].data()); auto h = BlockInfo::headerHash(_r[i].data());
BlockInfo bi(_r[i].data()); BlockInfo bi(_r[i].data());
if (!m_server->m_chain->details(bi.parentHash) && !m_knownBlocks.count(bi.parentHash)) if (!m_server->m_chain->details(bi.parentHash) && !m_knownBlocks.count(bi.parentHash))
{ {

Loading…
Cancel
Save