Browse Source

Bug fix for state transitioning - don't change nonce until after

guaranteed no collision has occured.
cl-refactor
Gav Wood 11 years ago
parent
commit
df5ce4302b
  1. 1
      TODO
  2. 30
      libethereum/State.cpp
  3. 2
      libethereum/State.h
  4. 6
      walleth/MainWin.cpp
  5. 7
      walleth/MainWin.h
  6. 17
      walleth/Simple.qml

1
TODO

@ -44,6 +44,7 @@ Robustness
- Store version alongside BC DB.
- Better handling of corrupt blocks.
- Kill DB & restart.
- Avoid transactions with future invalid nonces until additional transactions are processed.
GUI
- Make address/block chain list model-based, JIT populated.

30
libethereum/State.cpp

@ -624,12 +624,19 @@ void State::unapplyRewards(Addresses const& _uncleAddresses)
void State::executeBare(Transaction const& _t, Address _sender)
{
commit();
clog(StateChat) << "State:" << rootHash();
clog(StateChat) << "Executing TX:" << _t;
// Entry point for a contract-originated transaction.
// Ignore invalid transactions.
auto nonceReq = transactionsFrom(_sender);
if (_t.nonce != nonceReq)
{
clog(StateChat) << "Invalid Nonce.";
throw InvalidNonce(nonceReq, _t.nonce);
}
unsigned nonZeroData = 0;
for (auto i: _t.data)
@ -639,13 +646,16 @@ void State::executeBare(Transaction const& _t, Address _sender)
// Not considered invalid - just pointless.
if (balance(_sender) < _t.value + fee)
{
clog(StateChat) << "Not enough cash.";
throw NotEnoughCash();
// Increment associated nonce for sender.
noteSending(_sender);
}
if (_t.receiveAddress)
{
// Increment associated nonce for sender.
noteSending(_sender);
subBalance(_sender, _t.value + fee);
addBalance(_t.receiveAddress, _t.value);
@ -658,8 +668,7 @@ void State::executeBare(Transaction const& _t, Address _sender)
}
catch (VMException const& _e)
{
cnote << "VM Exception: " << _e.description();
throw;
clog(StateChat) << "VM Exception: " << _e.description();
}
}
}
@ -670,12 +679,21 @@ void State::executeBare(Transaction const& _t, Address _sender)
#else
if (_t.value < fee)
#endif
{
clog(StateChat) << "Not enough cash.";
throw NotEnoughCash();
}
Address newAddress = right160(_t.sha3());
if (isContractAddress(newAddress) || isNormalAddress(newAddress))
{
clog(StateChat) << "Contract address collision.";
throw ContractAddressCollision();
}
// Increment associated nonce for sender.
noteSending(_sender);
// All OK - set it up.
m_cache[newAddress] = AddressState(0, 0, AddressType::Contract);
@ -698,6 +716,8 @@ void State::executeBare(Transaction const& _t, Address _sender)
addBalance(newAddress, _t.value - fee);
#endif
}
commit();
clog(StateChat) << "New state:" << rootHash();
}
void State::execute(Address _myAddress, Address _txSender, u256 _txValue, u256s const& _txData, u256* _totalFee)

2
libethereum/State.h

@ -48,6 +48,8 @@ std::map<Address, AddressState> const& genesisState();
static const std::map<u256, u256> EmptyMapU256U256;
struct StateChat: public LogChannel { static const char* name() { return "=S="; } static const int verbosity = 4; };
class ExtVM;
/**

6
walleth/MainWin.cpp

@ -1,5 +1,6 @@
#include <QtNetwork/QNetworkReply>
#include <QtQuick/QQuickView>
#include <QtQml/QQmlContext>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QInputDialog>
#include <QtGui/QClipboard>
@ -77,8 +78,8 @@ Main::Main(QWidget *parent) :
*/
m_view = new QQuickView();
QQmlContext* context = m_view->rootContext();
/* context->setContextProperty("libs", libs());
context->setContextProperty("compute", compute());
// context->setContextProperty("eth", m_eth);
/* context->setContextProperty("compute", compute());
context->setContextProperty("data", data());
context->setContextProperty("graphs", graphs());
context->setContextProperty("audio", audio());
@ -87,7 +88,6 @@ Main::Main(QWidget *parent) :
QWidget* w = QWidget::createWindowContainer(m_view);
w->setAcceptDrops(true);
m_view->setResizeMode(QQuickView::SizeRootObjectToView);
ui->fullDisplay->insertWidget(0, w);
m_view->create();

7
walleth/MainWin.h

@ -18,6 +18,11 @@ class State;
class QQuickView;
class QEthereum
{
};
class Main : public QMainWindow
{
Q_OBJECT
@ -71,6 +76,8 @@ private:
QQuickView* m_view;
QNetworkAccessManager m_webCtrl;
QEthereum m_eth;
};
#endif // MAIN_H

17
walleth/Simple.qml

@ -0,0 +1,17 @@
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Layouts 1.0
Item {
id: main
anchors.fill: parent
anchors.margins: 9
Label {
text: "This fills the whole cell"
Layout.minimumHeight: 30
Layout.fillHeight: true
Layout.fillWidth: true
}
}
Loading…
Cancel
Save