Browse Source

Merge branch 'develop' of github.com:ethereum/cpp-ethereum into develop

cl-refactor
Vitalik Buterin 10 years ago
parent
commit
1ed125e23b
  1. 2
      alethzero/MainWin.cpp
  2. 2
      libethcore/BlockInfo.cpp
  3. 2
      libethcore/CommonEth.cpp
  4. 5
      libethential/CMakeLists.txt
  5. 2
      libethential/Common.cpp
  6. 2
      libethereum/BlockChain.cpp
  7. 4
      libethereum/Executive.cpp
  8. 8
      libethereum/ExtVM.h
  9. 14
      libethereum/State.cpp
  10. 4
      libethereum/State.h
  11. 3
      libevm/ExtVMFace.h
  12. 2
      libserpent/rewriter.cpp
  13. 49
      test/genesis.cpp

2
alethzero/MainWin.cpp

@ -93,7 +93,7 @@ static void initUnits(QComboBox* _b)
_b->addItem(QString::fromStdString(units()[n].second), n);
}
Address c_config = Address("9ef0f0d81e040012600b0c1abdef7c48f720f88a");
Address c_config = Address("661005d2720d855f1d9976f88bb10c1a3398c77f");
Main::Main(QWidget *parent) :
QMainWindow(parent),

2
libethcore/BlockInfo.cpp

@ -158,7 +158,7 @@ u256 BlockInfo::calculateGasLimit(BlockInfo const& _parent) const
if (!parentHash)
return 1000000;
else
return max<u256>(10000, (_parent.gasLimit * (1024 - 1) + (_parent.gasUsed * 6 / 5)) / 1024);
return max<u256>(125000, (_parent.gasLimit * (1024 - 1) + (_parent.gasUsed * 6 / 5)) / 1024);
}
u256 BlockInfo::calculateDifficulty(BlockInfo const& _parent) const

2
libethcore/CommonEth.cpp

@ -29,7 +29,7 @@ using namespace eth;
//#define ETH_ADDRESS_DEBUG 1
const unsigned eth::c_protocolVersion = 20;
const unsigned eth::c_protocolVersion = 21;
static const vector<pair<u256, string>> g_units =
{

5
libethential/CMakeLists.txt

@ -1,5 +1,8 @@
cmake_policy(SET CMP0015 NEW)
cmake_policy(SET CMP0022 NEW)
if (CMAKE_MAJOR_VERSION GREATER 1 AND CMAKE_MINOR_VERSION GREATER 7 AND CMAKE_PATCH_VERSION GREATER 11)
cmake_policy(SET CMP0022 NEW)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB")

2
libethential/Common.cpp

@ -27,6 +27,6 @@ using namespace eth;
namespace eth
{
char const* EthVersion = "0.5.12";
char const* EthVersion = "0.5.13";
}

2
libethereum/BlockChain.cpp

@ -74,7 +74,7 @@ std::map<Address, AddressState> const& eth::genesisState()
for (auto i: vector<string>({
"51ba59315b3a95761d0863b05ccc7a7f54703d99",
"e6716f9544a56c530d868e4bfbacb172315bdead",
"1e12515ce3e0f817a4ddef9ca55788a1d66bd2df",
"b9c015918bdaba24b4ff057a92a3873d6eb201be",
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4",
"2ef47100e0787b915105fd5e3f4ff6752079d5cb",
"cd2a3d9f938e13cd947ec05abc7fe734df8dd826",

4
libethereum/Executive.cpp

@ -229,4 +229,8 @@ void Executive::finalize()
u256 feesEarned = gasSpentInEth;
// cnote << "Transferring" << formatBalance(gasSpent) << "to miner.";
m_s.addBalance(m_s.m_currentBlock.coinbaseAddress, feesEarned);
// Suicides...
for (auto a: m_ext->suicides)
m_s.m_cache[a].kill();
}

8
libethereum/ExtVM.h

@ -30,7 +30,7 @@ namespace eth
{
/**
* @brief Externalality interface for the Virtual Machine providing access to world state.
* @brief Externality interface for the Virtual Machine providing access to world state.
*/
class ExtVM: public ExtVMFace
{
@ -53,13 +53,13 @@ public:
{
// Increment associated nonce for sender.
m_s.noteSending(myAddress);
return m_s.create(myAddress, _endowment, gasPrice, _gas, _code, origin);
return m_s.create(myAddress, _endowment, gasPrice, _gas, _code, origin, &suicides);
}
/// Create a new message call.
bool call(Address _receiveAddress, u256 _txValue, bytesConstRef _txData, u256* _gas, bytesRef _out)
{
return m_s.call(_receiveAddress, myAddress, _txValue, gasPrice, _txData, _gas, _out, origin);
return m_s.call(_receiveAddress, myAddress, _txValue, gasPrice, _txData, _gas, _out, origin, &suicides);
}
/// Read address's balance.
@ -75,7 +75,7 @@ public:
void suicide(Address _a)
{
m_s.addBalance(_a, m_s.balance(myAddress));
m_s.m_cache[myAddress].kill();
ExtVMFace::suicide(_a);
}
/// Revert any changes made (by any of the other calls).

14
libethereum/State.cpp

@ -1004,7 +1004,7 @@ u256 State::execute(bytesConstRef _rlp)
return e.gasUsed();
}
bool State::call(Address _receiveAddress, Address _senderAddress, u256 _value, u256 _gasPrice, bytesConstRef _data, u256* _gas, bytesRef _out, Address _originAddress)
bool State::call(Address _receiveAddress, Address _senderAddress, u256 _value, u256 _gasPrice, bytesConstRef _data, u256* _gas, bytesRef _out, Address _originAddress, std::set<Address>* o_suicides)
{
if (!_originAddress)
_originAddress = _senderAddress;
@ -1022,6 +1022,9 @@ bool State::call(Address _receiveAddress, Address _senderAddress, u256 _value, u
{
auto out = vm.go(evm);
memcpy(_out.data(), out.data(), std::min(out.size(), _out.size()));
if (o_suicides)
for (auto i: evm.suicides)
o_suicides->insert(i);
}
catch (OutOfGas const& /*_e*/)
{
@ -1052,7 +1055,7 @@ bool State::call(Address _receiveAddress, Address _senderAddress, u256 _value, u
return true;
}
h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _origin)
h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _origin, std::set<Address>* o_suicides)
{
if (!_origin)
_origin = _sender;
@ -1064,7 +1067,7 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
// Set up new account...
m_cache[newAddress] = AddressState(0, 0, h256(), h256());
// Execute _init.
// Execute init code.
VM vm(*_gas);
ExtVM evm(*this, newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _code);
bool revert = false;
@ -1073,6 +1076,9 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
try
{
out = vm.go(evm);
if (o_suicides)
for (auto i: evm.suicides)
o_suicides->insert(i);
}
catch (OutOfGas const& /*_e*/)
{
@ -1096,7 +1102,7 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
if (revert)
evm.revert();
// Set code as long as we didn't suicide.
// Set code.
if (addressInUse(newAddress))
m_cache[newAddress].setCode(out);

4
libethereum/State.h

@ -289,12 +289,12 @@ private:
// We assume all instrinsic fees are paid up before this point.
/// Execute a contract-creation transaction.
h160 create(Address _txSender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _originAddress = Address());
h160 create(Address _txSender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _originAddress = Address(), std::set<Address>* o_suicides = nullptr);
/// Execute a call.
/// @a _gas points to the amount of gas to use for the call, and will lower it accordingly.
/// @returns false if the call ran out of gas before completion. true otherwise.
bool call(Address _myAddress, Address _txSender, u256 _txValue, u256 _gasPrice, bytesConstRef _txData, u256* _gas, bytesRef _out, Address _originAddress = Address());
bool call(Address _myAddress, Address _txSender, u256 _txValue, u256 _gasPrice, bytesConstRef _txData, u256* _gas, bytesRef _out, Address _originAddress = Address(), std::set<Address>* o_suicides = nullptr);
/// Sets m_currentBlock to a clean state, (i.e. no change from m_previousBlock).
void resetCurrent();

3
libevm/ExtVMFace.h

@ -59,7 +59,7 @@ public:
u256 txCount(Address) { return 0; }
/// Suicide the associated contract to the given address.
void suicide(Address) {}
void suicide(Address _a) { suicides.insert(_a); }
/// Create a new (contract) account.
h160 create(u256, u256*, bytesConstRef, bytesConstRef) { return h160(); }
@ -79,6 +79,7 @@ public:
bytesConstRef code; ///< Current code that is executing.
BlockInfo previousBlock; ///< The previous block's information.
BlockInfo currentBlock; ///< The current block's information.
std::set<Address> suicides; ///< Any accounts that have suicided.
};
}

2
libserpent/rewriter.cpp

@ -350,7 +350,7 @@ Node array_lit_transform(Node node) {
o2.push_back(astnode("alloc", o1, node.metadata));
std::vector<Node> o3;
o3.push_back(astnode("set", o2, node.metadata));
for (int i = 0; i < node.args.size(); i++) {
for (unsigned i = 0; i < node.args.size(); i++) {
// (mstore (add (get symb) i*32) v)
std::vector<Node> o5;
o5.push_back(token(symb, node.metadata));

49
test/genesis.cpp

@ -0,0 +1,49 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file trie.cpp
* @author Gav Wood <i@gavwood.com>
* @date 2014
* Trie test functions.
*/
#include <fstream>
#include <random>
#include "JsonSpiritHeaders.h"
#include <libethential/CommonIO.h>
#include <libethereum/BlockChain.h>
#include <boost/test/unit_test.hpp>
using namespace std;
using namespace eth;
namespace js = json_spirit;
BOOST_AUTO_TEST_CASE(genesis_tests)
{
cnote << "Testing Genesis block...";
js::mValue v;
string s = asString(contents("../../../tests/genesishashestest.json"));
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'genesishashestest.json' is empty. Have you cloned the 'tests' repo branch develop?");
js::read_string(s, v);
js::mObject o = v.get_obj();
BOOST_CHECK_EQUAL(BlockChain::genesis().stateRoot, h256(o["genesis_state_root"].get_str()));
BOOST_CHECK_EQUAL(toHex(BlockChain::createGenesisBlock()), toHex(fromHex(o["genesis_rlp_hex"].get_str())));
BOOST_CHECK_EQUAL(sha3(BlockChain::createGenesisBlock()), h256(o["genesis_hash"].get_str()));
}
Loading…
Cancel
Save