Browse Source

Fixes for Go interop.

cl-refactor
Gav Wood 11 years ago
parent
commit
607e380a4b
  1. 2
      CMakeLists.txt
  2. 2
      alethzero/MainWin.cpp
  3. 10
      libethereum/BlockChain.cpp
  4. 2
      libethereum/BlockInfo.cpp
  5. 2
      libethereum/Common.cpp
  6. 2
      libethereum/Common.h
  7. 2
      libethereum/Exceptions.h
  8. 4
      libethereum/PeerNetwork.cpp
  9. 2
      libethereum/State.cpp
  10. 2
      libethereum/Transaction.cpp
  11. 24
      test/crypto.cpp
  12. 8
      test/main.cpp

2
CMakeLists.txt

@ -5,7 +5,7 @@ set(CMAKE_AUTOMOC ON)
cmake_policy(SET CMP0015 NEW) cmake_policy(SET CMP0015 NEW)
set(ETH_VERSION 0.2.2) set(ETH_VERSION 0.2.3)
set(ETH_BUILD_TYPE ${CMAKE_BUILD_TYPE}) set(ETH_BUILD_TYPE ${CMAKE_BUILD_TYPE})
set(TARGET_PLATFORM CACHE STRING "linux") set(TARGET_PLATFORM CACHE STRING "linux")

2
alethzero/MainWin.cpp

@ -64,7 +64,7 @@ Main::~Main()
void Main::on_about_triggered() void Main::on_about_triggered()
{ {
QMessageBox::about(this, "About AlethZero PoC-2", "AlethZero/v" ADD_QUOTES(ETH_VERSION) "/" ADD_QUOTES(ETH_BUILD_TYPE) "/" ADD_QUOTES(ETH_BUILD_PLATFORM) "\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nTeam Ethereum++ includes: Eric Lombrozo, Marko Simovic, Subtly and several others."); QMessageBox::about(this, "About AlethZero PoC-2", "AlethZero/v" ADD_QUOTES(ETH_VERSION) "/" ADD_QUOTES(ETH_BUILD_TYPE) "/" ADD_QUOTES(ETH_BUILD_PLATFORM) "\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nTeam Ethereum++ includes: Eric Lombrozo, Marko Simovic, Alex Leverington and several others.");
} }
void Main::writeSettings() void Main::writeSettings()

10
libethereum/BlockChain.cpp

@ -120,7 +120,15 @@ void BlockChain::import(bytes const& _block, Overlay const& _db)
{ {
// VERIFY: populates from the block and checks the block is internally coherent. // VERIFY: populates from the block and checks the block is internally coherent.
BlockInfo bi(&_block); BlockInfo bi(&_block);
bi.verifyInternals(&_block); try
{
bi.verifyInternals(&_block);
}
catch (Exception const& _e)
{
clog(BlockChainNote) << " Malformed block (" << _e.description() << ").";
throw;
}
auto newHash = eth::sha3(_block); auto newHash = eth::sha3(_block);

2
libethereum/BlockInfo.cpp

@ -131,7 +131,7 @@ void BlockInfo::verifyInternals(bytesConstRef _block) const
RLP root(_block); RLP root(_block);
if (sha3Transactions != sha3(root[1].data())) if (sha3Transactions != sha3(root[1].data()))
throw InvalidTransactionsHash(); throw InvalidTransactionsHash(sha3Transactions, sha3(root[1].data()));
if (sha3Uncles != sha3(root[2].data())) if (sha3Uncles != sha3(root[2].data()))
throw InvalidUnclesHash(); throw InvalidUnclesHash();

2
libethereum/Common.cpp

@ -38,6 +38,8 @@
using namespace std; using namespace std;
using namespace eth; using namespace eth;
#define ETH_ADDRESS_DEBUG 1
// Logging // Logging
int eth::g_logVerbosity = 8; int eth::g_logVerbosity = 8;
map<type_info const*, bool> eth::g_logOverride; map<type_info const*, bool> eth::g_logOverride;

2
libethereum/Common.h

@ -366,7 +366,7 @@ uint commonPrefix(_T const& _t, _U const& _u)
inline h160 right160(h256 const& _t) inline h160 right160(h256 const& _t)
{ {
h160 ret; h160 ret;
memcpy(ret.data(), _t.data() + 10, 20); memcpy(ret.data(), _t.data() + 12, 20);
return ret; return ret;
} }

2
libethereum/Exceptions.h

@ -29,7 +29,7 @@ class InvalidBlockHeaderFormat: public Exception { public: InvalidBlockHeaderFor
class InvalidUnclesHash: public Exception {}; class InvalidUnclesHash: public Exception {};
class InvalidUncle: public Exception {}; class InvalidUncle: public Exception {};
class InvalidStateRoot: public Exception {}; class InvalidStateRoot: public Exception {};
class InvalidTransactionsHash: public Exception {}; class InvalidTransactionsHash: public Exception { public: InvalidTransactionsHash(h256 _head, h256 _real): m_head(_head), m_real(_real) {} h256 m_head; h256 m_real; virtual std::string description() const { return "Invalid transactions hash: header says: " + asHex(m_head.ref()) + " block is:" + asHex(m_real.ref()); } };
class InvalidTransaction: public Exception {}; class InvalidTransaction: public Exception {};
class InvalidDifficulty: public Exception {}; class InvalidDifficulty: public Exception {};
class InvalidTimestamp: public Exception {}; class InvalidTimestamp: public Exception {};

4
libethereum/PeerNetwork.cpp

@ -43,7 +43,7 @@ using namespace eth;
#define clogS(X) eth::LogOutputStream<X, true>(false) << "| " << std::setw(2) << m_socket.native_handle() << "] " #define clogS(X) eth::LogOutputStream<X, true>(false) << "| " << std::setw(2) << m_socket.native_handle() << "] "
static const int c_protocolVersion = 3; static const int c_protocolVersion = 4;
static const eth::uint c_maxHashes = 256; ///< Maximum number of hashes GetChain will ever send. static const eth::uint c_maxHashes = 256; ///< Maximum number of hashes GetChain will ever send.
static const eth::uint c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send. BUG: if this gets too big (e.g. 2048) stuff starts going wrong. static const eth::uint c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send. BUG: if this gets too big (e.g. 2048) stuff starts going wrong.
@ -304,13 +304,13 @@ bool PeerSession::interpret(RLP const& _r)
{ {
if (m_server->m_mode == NodeMode::PeerServer) if (m_server->m_mode == NodeMode::PeerServer)
break; break;
clogS(NetMessageSummary) << "GetChain (" << (_r.itemCount() - 2) << " hashes, " << (_r[_r.itemCount() - 1].toInt<bigint>()) << ")";
// ******************************************************************** // ********************************************************************
// NEEDS FULL REWRITE! // NEEDS FULL REWRITE!
h256s parents; h256s parents;
parents.reserve(_r.itemCount() - 2); parents.reserve(_r.itemCount() - 2);
for (unsigned i = 1; i < _r.itemCount() - 1; ++i) for (unsigned i = 1; i < _r.itemCount() - 1; ++i)
parents.push_back(_r[i].toHash<h256>()); parents.push_back(_r[i].toHash<h256>());
clogS(NetMessageSummary) << "GetChain (" << (_r.itemCount() - 2) << " hashes, " << (_r[_r.itemCount() - 1].toInt<bigint>()) << ")";
if (_r.itemCount() == 2) if (_r.itemCount() == 2)
break; break;
// return 2048 block max. // return 2048 block max.

2
libethereum/State.cpp

@ -62,7 +62,7 @@ std::map<Address, AddressState> const& eth::genesisState()
if (s_ret.empty()) if (s_ret.empty())
{ {
// Initialise. // Initialise.
s_ret[Address(fromUserHex("07598a40bfaa73256b60764c1bf40675a99083ef"))] = AddressState(u256(1) << 200, 0); s_ret[Address(fromUserHex("8a40bfaa73256b60764c1bf40675a99083efb075"))] = AddressState(u256(1) << 200, 0);
s_ret[Address(fromUserHex("93658b04240e4bd4046fd2d6d417d20f146f4b43"))] = AddressState(u256(1) << 200, 0); s_ret[Address(fromUserHex("93658b04240e4bd4046fd2d6d417d20f146f4b43"))] = AddressState(u256(1) << 200, 0);
s_ret[Address(fromUserHex("1e12515ce3e0f817a4ddef9ca55788a1d66bd2df"))] = AddressState(u256(1) << 200, 0); s_ret[Address(fromUserHex("1e12515ce3e0f817a4ddef9ca55788a1d66bd2df"))] = AddressState(u256(1) << 200, 0);
s_ret[Address(fromUserHex("80c01a26338f0d905e295fccb71fa9ea849ffa12"))] = AddressState(u256(1) << 200, 0); s_ret[Address(fromUserHex("80c01a26338f0d905e295fccb71fa9ea849ffa12"))] = AddressState(u256(1) << 200, 0);

2
libethereum/Transaction.cpp

@ -26,6 +26,8 @@
using namespace std; using namespace std;
using namespace eth; using namespace eth;
#define ETH_ADDRESS_DEBUG 0
Transaction::Transaction(bytesConstRef _rlpData) Transaction::Transaction(bytesConstRef _rlpData)
{ {
RLP rlp(_rlpData); RLP rlp(_rlpData);

24
test/crypto.cpp

@ -30,6 +30,29 @@ using namespace eth;
int cryptoTest() int cryptoTest()
{ {
secp256k1_start();
KeyPair p(Secret(fromUserHex("3ecb44df2159c26e0f995712d4f39b6f6e499b40749b1cf1246c37f9516cb6a4")));
assert(p.pub() == Public(fromUserHex("97466f2b32bc3bb76d4741ae51cd1d8578b48d3f1e68da206d47321aec267ce78549b514e4453d74ef11b0cd5e4e4c364effddac8b51bcfc8de80682f952896f")));
assert(p.address() == Address(fromUserHex("8a40bfaa73256b60764c1bf40675a99083efb075")));
{
Transaction t;
t.nonce = 0;
t.receiveAddress = h160(fromUserHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
t.value = 1000;
t.data = u256s();
cnote << RLP(t.rlp(false));
cnote << asHex(t.rlp(false));
cnote << t.sha3(false);
t.sign(p.secret());
cnote << RLP(t.rlp(true));
cnote << asHex(t.rlp(true));
cnote << t.sha3(true);
assert(t.sender() == p.address());
}
#if 0
// Test transaction. // Test transaction.
bytes tx = fromUserHex("88005401010101010101010101010101010101010101011f0de0b6b3a76400001ce8d4a5100080181c373130a009ba1f10285d4e659568bfcfec85067855c5a3c150100815dad4ef98fd37cf0593828c89db94bd6c64e210a32ef8956eaa81ea9307194996a3b879441f5d"); bytes tx = fromUserHex("88005401010101010101010101010101010101010101011f0de0b6b3a76400001ce8d4a5100080181c373130a009ba1f10285d4e659568bfcfec85067855c5a3c150100815dad4ef98fd37cf0593828c89db94bd6c64e210a32ef8956eaa81ea9307194996a3b879441f5d");
cout << "TX: " << RLP(tx) << endl; cout << "TX: " << RLP(tx) << endl;
@ -94,6 +117,7 @@ int cryptoTest()
cout << "RECPUB: " << dec << ret << " " << pubkeylen << " " << asHex(pubkey) << endl; cout << "RECPUB: " << dec << ret << " " << pubkeylen << " " << asHex(pubkey) << endl;
cout << "SENDER: " << hex << low160(eth::sha3(bytesConstRef(&pubkey).cropped(1))) << dec << endl; cout << "SENDER: " << hex << low160(eth::sha3(bytesConstRef(&pubkey).cropped(1))) << dec << endl;
} }
#endif
return 0; return 0;
} }

8
test/main.cpp

@ -41,11 +41,11 @@ int main(int argc, char** argv)
std::cout << asHex(s.out()) << std::endl; std::cout << asHex(s.out()) << std::endl;
std::cout << sha3(s.out()) << std::endl;*/ std::cout << sha3(s.out()) << std::endl;*/
hexPrefixTest(); // hexPrefixTest();
rlpTest(); // rlpTest();
trieTest(); // trieTest();
// daggerTest(); // daggerTest();
// cryptoTest(); cryptoTest();
// stateTest(); // stateTest();
// peerTest(argc, argv); // peerTest(argc, argv);
return 0; return 0;

Loading…
Cancel
Save