Browse Source

State reworked slightly.

Additional experimentation for State to demo how easily it is to create
states.
cl-refactor
Gav Wood 10 years ago
parent
commit
a068543f21
  1. 80
      exp/main.cpp
  2. 16
      libethereum/State.h

80
exp/main.cpp

@ -28,6 +28,7 @@
#include <libp2p/All.h>
#include <libdevcore/RangeMask.h>
#include <libethereum/DownloadMan.h>
#include <libethereum/All.h>
#include <libwhisper/WhisperPeer.h>
#include <libwhisper/WhisperHost.h>
using namespace std;
@ -36,7 +37,7 @@ using namespace dev::eth;
using namespace dev::p2p;
using namespace dev::shh;
#if 1
#if 0
int main()
{
DownloadMan man;
@ -72,72 +73,17 @@ int main()
cnote << i;*/
return 0;
}
#endif
/*int other(bool& o_started)
#else
int main()
{
setThreadName("other");
short listenPort = 30300;
Host ph("Test", NetworkPreferences(listenPort, "", false, true));
auto wh = ph.registerCapability(new WhisperHost());
ph.start();
o_started = true;
/// Only interested in odd packets
auto w = wh->installWatch(BuildTopicMask()("odd"));
unsigned last = 0;
unsigned total = 0;
for (int i = 0; i < 100 && last < 81; ++i)
{
for (auto i: wh->checkWatch(w))
{
Message msg = wh->envelope(i).open();
last = RLP(msg.payload()).toInt<unsigned>();
cnote << "New message from:" << msg.from().abridged() << RLP(msg.payload()).toInt<unsigned>();
total += last;
}
this_thread::sleep_for(chrono::milliseconds(50));
}
return total;
KeyPair u = KeyPair::create();
KeyPair cb = KeyPair::create();
OverlayDB db;
State s(cb.address(), db);
cnote << s.rootHash();
s.addBalance(u.address(), 1000 * ether);
s.commit();
cnote << s.rootHash();
}
#endif
int main(int, char**)
{
g_logVerbosity = 0;
bool started = false;
unsigned result;
std::thread listener([&](){ return (result = other(started)); });
while (!started)
this_thread::sleep_for(chrono::milliseconds(50));
short listenPort = 30303;
string remoteHost = "127.0.0.1";
short remotePort = 30300;
Host ph("Test", NetworkPreferences(listenPort, "", false, true));
auto wh = ph.registerCapability(new WhisperHost());
ph.start();
if (!remoteHost.empty())
ph.connect(remoteHost, remotePort);
KeyPair us = KeyPair::create();
for (int i = 0; i < 10; ++i)
{
wh->post(us.sec(), RLPStream().append(i * i).out(), BuildTopic(i)(i % 2 ? "odd" : "even"));
this_thread::sleep_for(chrono::milliseconds(250));
}
listener.join();
assert(result == 1 + 9 + 25 + 49 + 81);
return 0;
}*/

16
libethereum/State.h

@ -244,6 +244,12 @@ public:
/// the block since all state changes are ultimately reversed.
void cleanup(bool _fullCommit);
/// Commit all changes waiting in the address cache to the DB.
void commit();
/// Sets m_currentBlock to a clean state, (i.e. no change from m_previousBlock).
void resetCurrent();
private:
/// Undo the changes to the state for committing to mine.
void uncommitToMine();
@ -257,25 +263,19 @@ private:
/// Retrieve all information about a given address into a cache.
void ensureCached(std::map<Address, Account>& _cache, Address _a, bool _requireCode, bool _forceCreate) const;
/// Commit all changes waiting in the address cache to the DB.
void commit();
/// Execute the given block, assuming it corresponds to m_currentBlock. If _bc is passed, it will be used to check the uncles.
/// Throws on failure.
u256 enact(bytesConstRef _block, BlockChain const* _bc = nullptr, bool _checkNonce = true);
/// Sets m_currentBlock to a clean state, (i.e. no change from m_previousBlock).
void resetCurrent();
/// Finalise the block, applying the earned rewards.
void applyRewards(Addresses const& _uncleAddresses);
void refreshManifest(RLPStream* _txs = nullptr);
/// @returns gas used by transactions thus far executed.
u256 gasUsed() const { return m_receipts.size() ? m_receipts.back().gasUsed() : 0; }
/// Debugging only. Good for checking the Trie is in shape.
bool isTrieGood(bool _enforceRefs, bool _requireNoLeftOvers) const;
/// Debugging only. Good for checking the Trie is in shape.
void paranoia(std::string const& _when, bool _enforceRefs = false) const;
OverlayDB m_db; ///< Our overlay for the state tree.

Loading…
Cancel
Save