Browse Source

Latest PoC-5 protocol changes.

cl-refactor
Gav Wood 11 years ago
parent
commit
f96ab229ec
  1. 2
      libethcore/BlockInfo.cpp
  2. 2
      libethcore/CommonEth.cpp
  3. 2
      libethential/Common.cpp
  4. 2
      libethereum/BlockChain.cpp
  5. 4
      libethereum/Executive.cpp
  6. 8
      libethereum/ExtVM.h
  7. 14
      libethereum/State.cpp
  8. 4
      libethereum/State.h
  9. 3
      libevm/ExtVMFace.h
  10. 2
      libserpent/rewriter.cpp

2
libethcore/BlockInfo.cpp

@ -158,7 +158,7 @@ u256 BlockInfo::calculateGasLimit(BlockInfo const& _parent) const
if (!parentHash) if (!parentHash)
return 1000000; return 1000000;
else 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 u256 BlockInfo::calculateDifficulty(BlockInfo const& _parent) const

2
libethcore/CommonEth.cpp

@ -29,7 +29,7 @@ using namespace eth;
//#define ETH_ADDRESS_DEBUG 1 //#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 = static const vector<pair<u256, string>> g_units =
{ {

2
libethential/Common.cpp

@ -27,6 +27,6 @@ using namespace eth;
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>({ for (auto i: vector<string>({
"51ba59315b3a95761d0863b05ccc7a7f54703d99", "51ba59315b3a95761d0863b05ccc7a7f54703d99",
"e6716f9544a56c530d868e4bfbacb172315bdead", "e6716f9544a56c530d868e4bfbacb172315bdead",
"1e12515ce3e0f817a4ddef9ca55788a1d66bd2df", "b9c015918bdaba24b4ff057a92a3873d6eb201be",
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4", "1a26338f0d905e295fccb71fa9ea849ffa12aaf4",
"2ef47100e0787b915105fd5e3f4ff6752079d5cb", "2ef47100e0787b915105fd5e3f4ff6752079d5cb",
"cd2a3d9f938e13cd947ec05abc7fe734df8dd826", "cd2a3d9f938e13cd947ec05abc7fe734df8dd826",

4
libethereum/Executive.cpp

@ -229,4 +229,8 @@ void Executive::finalize()
u256 feesEarned = gasSpentInEth; u256 feesEarned = gasSpentInEth;
// cnote << "Transferring" << formatBalance(gasSpent) << "to miner."; // cnote << "Transferring" << formatBalance(gasSpent) << "to miner.";
m_s.addBalance(m_s.m_currentBlock.coinbaseAddress, feesEarned); 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 class ExtVM: public ExtVMFace
{ {
@ -53,13 +53,13 @@ public:
{ {
// Increment associated nonce for sender. // Increment associated nonce for sender.
m_s.noteSending(myAddress); 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. /// Create a new message call.
bool call(Address _receiveAddress, u256 _txValue, bytesConstRef _txData, u256* _gas, bytesRef _out) 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. /// Read address's balance.
@ -75,7 +75,7 @@ public:
void suicide(Address _a) void suicide(Address _a)
{ {
m_s.addBalance(_a, m_s.balance(myAddress)); 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). /// 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(); 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) if (!_originAddress)
_originAddress = _senderAddress; _originAddress = _senderAddress;
@ -1022,6 +1022,9 @@ bool State::call(Address _receiveAddress, Address _senderAddress, u256 _value, u
{ {
auto out = vm.go(evm); auto out = vm.go(evm);
memcpy(_out.data(), out.data(), std::min(out.size(), _out.size())); 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*/) catch (OutOfGas const& /*_e*/)
{ {
@ -1052,7 +1055,7 @@ bool State::call(Address _receiveAddress, Address _senderAddress, u256 _value, u
return true; 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) if (!_origin)
_origin = _sender; _origin = _sender;
@ -1064,7 +1067,7 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
// Set up new account... // Set up new account...
m_cache[newAddress] = AddressState(0, 0, h256(), h256()); m_cache[newAddress] = AddressState(0, 0, h256(), h256());
// Execute _init. // Execute init code.
VM vm(*_gas); VM vm(*_gas);
ExtVM evm(*this, newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _code); ExtVM evm(*this, newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _code);
bool revert = false; bool revert = false;
@ -1073,6 +1076,9 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
try try
{ {
out = vm.go(evm); out = vm.go(evm);
if (o_suicides)
for (auto i: evm.suicides)
o_suicides->insert(i);
} }
catch (OutOfGas const& /*_e*/) catch (OutOfGas const& /*_e*/)
{ {
@ -1096,7 +1102,7 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
if (revert) if (revert)
evm.revert(); evm.revert();
// Set code as long as we didn't suicide. // Set code.
if (addressInUse(newAddress)) if (addressInUse(newAddress))
m_cache[newAddress].setCode(out); 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. // We assume all instrinsic fees are paid up before this point.
/// Execute a contract-creation transaction. /// 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. /// Execute a call.
/// @a _gas points to the amount of gas to use for the call, and will lower it accordingly. /// @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. /// @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). /// Sets m_currentBlock to a clean state, (i.e. no change from m_previousBlock).
void resetCurrent(); void resetCurrent();

3
libevm/ExtVMFace.h

@ -59,7 +59,7 @@ public:
u256 txCount(Address) { return 0; } u256 txCount(Address) { return 0; }
/// Suicide the associated contract to the given address. /// Suicide the associated contract to the given address.
void suicide(Address) {} void suicide(Address _a) { suicides.insert(_a); }
/// Create a new (contract) account. /// Create a new (contract) account.
h160 create(u256, u256*, bytesConstRef, bytesConstRef) { return h160(); } h160 create(u256, u256*, bytesConstRef, bytesConstRef) { return h160(); }
@ -79,6 +79,7 @@ public:
bytesConstRef code; ///< Current code that is executing. bytesConstRef code; ///< Current code that is executing.
BlockInfo previousBlock; ///< The previous block's information. BlockInfo previousBlock; ///< The previous block's information.
BlockInfo currentBlock; ///< The current 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)); o2.push_back(astnode("alloc", o1, node.metadata));
std::vector<Node> o3; std::vector<Node> o3;
o3.push_back(astnode("set", o2, node.metadata)); 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) // (mstore (add (get symb) i*32) v)
std::vector<Node> o5; std::vector<Node> o5;
o5.push_back(token(symb, node.metadata)); o5.push_back(token(symb, node.metadata));

Loading…
Cancel
Save