diff --git a/eth/main.cpp b/eth/main.cpp index 382858ae7..43d865346 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -102,6 +102,9 @@ void interactiveHelp() << " listaccounts List the accounts on the network." << endl << " listcontracts List the contracts on the network." << endl << " balanceat
Gives the balance of the given account." << endl + << " balanceatblock
Gives the balance of the given account." << endl + << " storageat
Gives the storage of the given account." << endl + << " storageatblock
Gives the storahe of the given account at a given blocknumber." << endl << " codeat
Gives the code of the given account." << endl #endif << " setsigningkey Set the address with which to sign transactions." << endl @@ -168,6 +171,9 @@ void help() << " --port Connect to remote port (default: 30303)." << endl << " --network-id Only connect to other hosts with this network id (default:0)." << endl << " --upnp Use UPnP for NAT (default: on)." << endl + << " --no-discovery Disable Node discovery. (experimental)" << endl + << " --pin Only connect to required (trusted) peers. (experimental)" << endl +// << " --require-peers List of required (trusted) peers. (experimental)" << endl << endl; MinerCLI::streamHelp(cout); cout @@ -304,6 +310,8 @@ int main(int argc, char** argv) unsigned short remotePort = 30303; unsigned peers = 11; bool bootstrap = false; + bool disableDiscovery = false; + bool pinning = false; unsigned networkId = 0; /// Mining params @@ -592,6 +600,10 @@ int main(int argc, char** argv) } else if (arg == "-b" || arg == "--bootstrap") bootstrap = true; + else if (arg == "--no-discovery") + disableDiscovery = true; + else if (arg == "--pin") + pinning = true; else if (arg == "-f" || arg == "--force-mining") forceMining = true; else if (arg == "-i" || arg == "--interactive") @@ -684,6 +696,8 @@ int main(int argc, char** argv) StructuredLogger::get().initialize(structuredLogging, structuredLoggingFormat, structuredLoggingURL); VMFactory::setKind(jit ? VMKind::JIT : VMKind::Interpreter); auto netPrefs = publicIP.empty() ? NetworkPreferences(listenIP ,listenPort, upnp) : NetworkPreferences(publicIP, listenIP ,listenPort, upnp); + netPrefs.discovery = !disableDiscovery; + netPrefs.pin = pinning; auto nodesState = contents((dbPath.size() ? dbPath : getDataDir()) + "/network.rlp"); dev::WebThreeDirect web3( WebThreeDirect::composeClientVersion("++eth", clientName), @@ -1358,19 +1372,48 @@ int main(int argc, char** argv) cout << "balance of " << stringHash << " is: " << toString(c->balanceAt(address)) << endl; } } - // TODO implement << operator for std::unorderd_map -// else if (c && cmd == "storageat") -// { -// if (iss.peek() != -1) -// { -// string stringHash; -// iss >> stringHash; + else if (c && cmd == "balanceatblock") + { + if (iss.peek() != -1) + { + string stringHash; + unsigned blocknumber; + iss >> stringHash >> blocknumber; -// Address address = h160(fromHex(stringHash)); + Address address = h160(fromHex(stringHash)); + + cout << "balance of " << stringHash << " is: " << toString(c->balanceAt(address, blocknumber)) << endl; + } + } + else if (c && cmd == "storageat") + { + if (iss.peek() != -1) + { + string stringHash; + iss >> stringHash; -// cout << "storage at " << stringHash << " is: " << c->storageAt(address) << endl; -// } -// } + Address address = h160(fromHex(stringHash)); + + cout << "storage at " << stringHash << " is: " << endl; + for (auto s: c->storageAt(address)) + cout << toHex(s.first) << " : " << toHex(s.second) << endl; + } + } + else if (c && cmd == "storageatblock") + { + if (iss.peek() != -1) + { + string stringHash; + unsigned blocknumber; + iss >> stringHash >> blocknumber; + + Address address = h160(fromHex(stringHash)); + + cout << "storage at " << stringHash << " is: " << endl; + for (auto s: c->storageAt(address, blocknumber)) + cout << "\"0x" << toHex(s.first) << "\" : \"0x" << toHex(s.second) << "\"," << endl; + } + } else if (c && cmd == "codeat") { if (iss.peek() != -1) @@ -1384,6 +1427,7 @@ int main(int argc, char** argv) } } #endif + else if (c && cmd == "send") { if (iss.peek() != -1) diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index 2d1822b2c..922a6ec30 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -158,16 +158,17 @@ public: template inline FixedHash& shiftBloom(FixedHash const& _h) { - return (*this |= _h.template bloom()); + return (*this |= _h.template bloomPart()); } template inline bool containsBloom(FixedHash const& _h) { - return contains(_h.template bloom()); + return contains(_h.template bloomPart()); } - template inline FixedHash bloom() const + template inline FixedHash bloomPart() const { + static_assert((M & (M - 1)) == 0, "M must be power-of-two"); static const unsigned c_bloomBits = M * 8; unsigned mask = c_bloomBits - 1; unsigned bloomBytes = (dev::toLog2(c_bloomBits) + 7) / 8; diff --git a/libethash-cl/ethash_cl_miner.cpp b/libethash-cl/ethash_cl_miner.cpp index 6c2f8269a..b160cdd94 100644 --- a/libethash-cl/ethash_cl_miner.cpp +++ b/libethash-cl/ethash_cl_miner.cpp @@ -429,7 +429,8 @@ void ethash_cl_miner::search(uint8_t const* header, uint64_t target, search_hook }; queue pending; - static uint32_t const c_zero = 0; + // this can't be a static because in MacOSX OpenCL implementation a segfault occurs when a static is passed to OpenCL functions + uint32_t const c_zero = 0; // update header constant buffer m_queue.enqueueWriteBuffer(m_header, false, 0, 32, header); diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index 1482719c6..a0d8e1297 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -326,7 +326,8 @@ void Host::onNodeTableEvent(NodeId const& _n, NodeTableEventType const& _e) { clog(NetP2PNote) << "p2p.host.nodeTable.events.NodeEntryDropped " << _n; RecursiveGuard l(x_sessions); - m_peers.erase(_n); + if (m_peers.count(_n) && !m_peers[_n]->required) + m_peers.erase(_n); } } @@ -637,27 +638,40 @@ void Host::run(boost::system::error_code const&) // updated. // disconnectLatePeers(); // todo: update peerSlotsAvailable() - unsigned pendingCount = 0; - DEV_GUARDED(x_pendingNodeConns) - pendingCount = m_pendingPeerConns.size(); - int openSlots = m_idealPeerCount - peerCount() - pendingCount; - if (openSlots > 0) + + list> toConnect; + unsigned reqConn = 0; { - list> toConnect; + RecursiveGuard l(x_sessions); + for (auto const& p: m_peers) { - RecursiveGuard l(x_sessions); - for (auto p: m_peers) - if (p.second->shouldReconnect() && !havePeerSession(p.second->id)) - toConnect.push_back(p.second); + bool haveSession = havePeerSession(p.second->id); + bool required = p.second->required; + if (haveSession && required) + reqConn++; + else if (!haveSession && p.second->shouldReconnect() && (!m_netPrefs.pin || required)) + toConnect.push_back(p.second); } + } + + for (auto p: toConnect) + if (p->required && reqConn++ < m_idealPeerCount) + connect(p); + + if (!m_netPrefs.pin) + { + unsigned pendingCount = 0; + DEV_GUARDED(x_pendingNodeConns) + pendingCount = m_pendingPeerConns.size(); + int openSlots = m_idealPeerCount - peerCount() - pendingCount + reqConn; + if (openSlots > 0) + { + for (auto p: toConnect) + if (!p->required && openSlots--) + connect(p); - for (auto p: toConnect) - if (openSlots--) - connect(p); - else - break; - - m_nodeTable->discover(); + m_nodeTable->discover(); + } } auto runcb = [this](boost::system::error_code const& error) { run(error); }; @@ -698,7 +712,7 @@ void Host::startedWorking() else clog(NetP2PNote) << "p2p.start.notice id:" << id() << "TCP Listen port is invalid or unavailable."; - shared_ptr nodeTable(new NodeTable(m_ioService, m_alias, NodeIPEndpoint(bi::address::from_string(listenAddress()), listenPort(), listenPort()))); + shared_ptr nodeTable(new NodeTable(m_ioService, m_alias, NodeIPEndpoint(bi::address::from_string(listenAddress()), listenPort(), listenPort()), m_netPrefs.discovery)); nodeTable->setEventHandler(new HostNodeTableHandler(*this)); m_nodeTable = nodeTable; restoreNetwork(&m_restoreNetwork); diff --git a/libp2p/Network.h b/libp2p/Network.h index d02ce3cbe..e70dd89ea 100644 --- a/libp2p/Network.h +++ b/libp2p/Network.h @@ -52,6 +52,8 @@ struct NetworkPreferences std::string listenIPAddress; unsigned short listenPort = 30303; bool traverseNAT = true; + bool discovery = true; // Discovery is activated with network. + bool pin = false; // Only connect to trusted ("required") peers. }; /** diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 6344dc263..1a0b11734 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -40,14 +40,15 @@ const char* NodeTableIngress::name() { return "<connect(); - doRefreshBuckets(boost::system::error_code()); + if (!m_disabled) + { + m_socketPointer->connect(); + doRefreshBuckets(boost::system::error_code()); + } } NodeTable::~NodeTable() diff --git a/libp2p/NodeTable.h b/libp2p/NodeTable.h index 0ec13c828..d31a356ef 100644 --- a/libp2p/NodeTable.h +++ b/libp2p/NodeTable.h @@ -130,7 +130,7 @@ public: enum NodeRelation { Unknown = 0, Known }; /// Constructor requiring host for I/O, credentials, and IP Address and port to listen on. - NodeTable(ba::io_service& _io, KeyPair const& _alias, NodeIPEndpoint const& _endpoint); + NodeTable(ba::io_service& _io, KeyPair const& _alias, NodeIPEndpoint const& _endpoint, bool _enabled = true); ~NodeTable(); /// Returns distance based on xor metric two node ids. Used by NodeEntry and NodeTable. @@ -271,6 +271,8 @@ private: boost::asio::deadline_timer m_bucketRefreshTimer; ///< Timer which schedules and enacts bucket refresh. boost::asio::deadline_timer m_evictionCheckTimer; ///< Timer for handling node evictions. + + bool m_disabled; ///< Disable discovery. }; inline std::ostream& operator<<(std::ostream& _out, NodeTable const& _nodeTable) diff --git a/libp2p/Peer.cpp b/libp2p/Peer.cpp index 6f368a4b4..a8b4a993d 100644 --- a/libp2p/Peer.cpp +++ b/libp2p/Peer.cpp @@ -38,6 +38,8 @@ bool Peer::shouldReconnect() const unsigned Peer::fallbackSeconds() const { + if (required) + return 5; switch (m_lastDisconnect) { case BadProtocol: diff --git a/test/libevm/vm.cpp b/test/libevm/vm.cpp index 5bbab2e1c..ea9339f05 100644 --- a/test/libevm/vm.cpp +++ b/test/libevm/vm.cpp @@ -323,6 +323,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress)); fev.code = fev.thisTxCode; } + fev.codeHash = sha3(fev.code); bytes output; bool vmExceptionOccured = false;