Browse Source

Gas fix & GUI enhancements.

cl-refactor
Gav Wood 11 years ago
parent
commit
4e9b4323c0
  1. 9
      alethzero/Main.ui
  2. 1
      libethereum/Instruction.cpp
  3. 35
      libethereum/State.cpp
  4. 10
      libethereum/State.h

9
alethzero/Main.ui

@ -398,6 +398,12 @@
</property> </property>
</widget> </widget>
<widget class="QTextBrowser" name="pendingInfo"> <widget class="QTextBrowser" name="pendingInfo">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
@ -947,6 +953,9 @@
<property name="text"> <property name="text">
<string>&amp;Quit</string> <string>&amp;Quit</string>
</property> </property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action> </action>
<action name="upnp"> <action name="upnp">
<property name="checkable"> <property name="checkable">

1
libethereum/Instruction.cpp

@ -661,7 +661,6 @@ static int compileLispFragment(char const*& d, char const* e, bool _quiet, bytes
int o = compileLispFragment(d, e, _quiet, codes[i], locs[i], _vars); int o = compileLispFragment(d, e, _quiet, codes[i], locs[i], _vars);
if (o == -1 || (i == 0 && o != 1)) if (o == -1 || (i == 0 && o != 1))
return false; return false;
cnote << "FOR " << i << o;
if (i > 0) if (i > 0)
for (int j = 0; j < o; ++j) for (int j = 0; j < o; ++j)
codes[i].push_back((byte)Instruction::POP); // pop additional items off stack for the previous item (final item's returns get left on). codes[i].push_back((byte)Instruction::POP); // pop additional items off stack for the previous item (final item's returns get left on).

35
libethereum/State.cpp

@ -561,17 +561,12 @@ u256 State::playbackRaw(bytesConstRef _block, BlockInfo const& _grandParent, boo
void State::uncommitToMine() void State::uncommitToMine()
{ {
if (m_currentBlock.sha3Uncles != h256()) m_cache.clear();
{ if (!m_transactions.size())
// cnote << "Unapplying rewards: " << balance(m_currentBlock.coinbaseAddress); m_state.setRoot(m_previousBlock.stateRoot);
Addresses uncleAddresses; else
for (auto i: RLP(m_currentUncles)) m_state.setRoot(m_transactions[m_transactions.size() - 1].stateRoot);
uncleAddresses.push_back(i[2].toHash<Address>()); m_currentBlock.sha3Uncles = h256();
unapplyRewards(uncleAddresses);
// cnote << "Unapplied rewards: " << balance(m_currentBlock.coinbaseAddress);
m_currentBlock.sha3Uncles = h256();
}
} }
bool State::amIJustParanoid(BlockChain const& _bc) bool State::amIJustParanoid(BlockChain const& _bc)
@ -972,7 +967,6 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
State State::fromPending(unsigned _i) const State State::fromPending(unsigned _i) const
{ {
State ret = *this; State ret = *this;
ret.uncommitToMine();
ret.m_cache.clear(); ret.m_cache.clear();
_i = min<unsigned>(_i, m_transactions.size()); _i = min<unsigned>(_i, m_transactions.size());
if (!_i) if (!_i)
@ -1001,23 +995,6 @@ void State::applyRewards(Addresses const& _uncleAddresses)
addBalance(m_currentBlock.coinbaseAddress, r); addBalance(m_currentBlock.coinbaseAddress, r);
} }
void State::unapplyRewards(Addresses const&)
{
m_cache.clear();
if (!m_transactions.size())
m_state.setRoot(m_previousBlock.stateRoot);
else
m_state.setRoot(m_transactions[m_transactions.size() - 1].stateRoot);
/* u256 r = m_blockReward;
for (auto const& i: _uncleAddresses)
{
subBalance(i, m_blockReward * 3 / 4);
r += m_blockReward / 8;
}
subBalance(m_currentBlock.coinbaseAddress, r);*/
}
std::ostream& eth::operator<<(std::ostream& _out, State const& _s) std::ostream& eth::operator<<(std::ostream& _out, State const& _s)
{ {
_out << "--- " << _s.rootHash() << std::endl; _out << "--- " << _s.rootHash() << std::endl;

10
libethereum/State.h

@ -238,11 +238,14 @@ public:
/// This might throw. /// This might throw.
u256 playback(bytesConstRef _block, BlockInfo const& _bi, BlockInfo const& _parent, BlockInfo const& _grandParent, bool _fullCommit); u256 playback(bytesConstRef _block, BlockInfo const& _bi, BlockInfo const& _parent, BlockInfo const& _grandParent, bool _fullCommit);
/// Get the fee associated for a transaction with the given data.
u256 txGas(uint _dataCount, u256 _gas = 0) const { return c_txDataGas * _dataCount + c_txGas + _gas; }
/// Get the fee associated for a contract created with the given data. /// Get the fee associated for a contract created with the given data.
u256 createGas(uint _dataCount, u256 _gas = 0) const { return c_txDataGas * _dataCount + c_createGas + _gas; } u256 createGas(uint _dataCount, u256 _gas = 0) const { return txGas(_dataCount, _gas); }
/// Get the fee associated for a normal transaction. /// Get the fee associated for a normal transaction.
u256 callGas(uint _dataCount, u256 _gas = 0) const { return c_txDataGas * _dataCount + c_callGas + _gas; } u256 callGas(uint _dataCount, u256 _gas = 0) const { return txGas(_dataCount, _gas); }
/// @return the difference between this state (origin) and @a _c (destination). /// @return the difference between this state (origin) and @a _c (destination).
StateDiff diff(State const& _c) const; StateDiff diff(State const& _c) const;
@ -290,9 +293,6 @@ private:
void refreshManifest(RLPStream* _txs = nullptr); void refreshManifest(RLPStream* _txs = nullptr);
/// Unfinalise the block, unapplying the earned rewards.
void unapplyRewards(Addresses const& _uncleAddresses);
/// @returns gas used by transactions thus far executed. /// @returns gas used by transactions thus far executed.
u256 gasUsed() const { return m_transactions.size() ? m_transactions.back().gasUsed : 0; } u256 gasUsed() const { return m_transactions.size() ? m_transactions.back().gasUsed : 0; }

Loading…
Cancel
Save