Browse Source

Bunch of repotting/curating.

[10:59:28] Vitalik Buterin: block.parent.gas_limit * 1023 / 1024 <=
block.gas_limit <= block.parent.gas_limit * 1025/1024
cl-refactor
Gav Wood 10 years ago
parent
commit
c187452a1d
  1. 7
      libethcore/BlockInfo.cpp
  2. 2
      libethcore/Exceptions.cpp
  3. 4
      libethcore/Exceptions.h
  4. 2
      libethcore/ProofOfWork.h
  5. 2
      libethereum/Precompiled.cpp
  6. 128
      rlp/base64.cpp
  7. 40
      rlp/base64.h
  8. 94
      rlp/main.cpp

7
libethcore/BlockInfo.cpp

@ -203,8 +203,6 @@ u256 BlockInfo::calculateDifficulty(BlockInfo const& _parent) const
return max<u256>(c_minimumDifficulty, timestamp >= _parent.timestamp + c_durationLimit ? _parent.difficulty - (_parent.difficulty / c_difficultyBoundDivisor) : (_parent.difficulty + (_parent.difficulty / c_difficultyBoundDivisor)));
}
template <class N> inline N diff(N const& _a, N const& _b) { return max(_a, _b) - min(_a, _b); }
void BlockInfo::verifyParent(BlockInfo const& _parent) const
{
// Check difficulty is correct given the two timestamps.
@ -215,8 +213,9 @@ void BlockInfo::verifyParent(BlockInfo const& _parent) const
gasLimit > _parent.gasLimit * (c_gasLimitBoundDivisor + 1) / c_gasLimitBoundDivisor)
BOOST_THROW_EXCEPTION(InvalidGasLimit(gasLimit, _parent.gasLimit * (c_gasLimitBoundDivisor - 1) / c_gasLimitBoundDivisor, _parent.gasLimit * (c_gasLimitBoundDivisor + 1) / c_gasLimitBoundDivisor));
if (diff(gasLimit, _parent.gasLimit) <= _parent.gasLimit / c_gasLimitBoundDivisor)
BOOST_THROW_EXCEPTION(InvalidGasLimit(gasLimit, calculateGasLimit(_parent), diff(gasLimit, _parent.gasLimit), _parent.gasLimit / c_gasLimitBoundDivisor));
if (gasLimit < _parent.gasLimit * (c_gasLimitBoundDivisor - 1) / c_gasLimitBoundDivisor ||
gasLimit > _parent.gasLimit * (c_gasLimitBoundDivisor + 1) / c_gasLimitBoundDivisor)
BOOST_THROW_EXCEPTION(InvalidGasLimit(gasLimit, _parent.gasLimit * (c_gasLimitBoundDivisor - 1) / c_gasLimitBoundDivisor, _parent.gasLimit * (c_gasLimitBoundDivisor + 1) / c_gasLimitBoundDivisor));
if (seedHash != calculateSeedHash(_parent))
BOOST_THROW_EXCEPTION(InvalidSeedHash());

2
libethcore/Exceptions.cpp

@ -39,7 +39,7 @@ static boost::thread_specific_ptr<string> g_exceptionMessage;
const char* InvalidBlockFormat::what() const noexcept { ETH_RETURN_STRING("Invalid block format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"); }
const char* UncleInChain::what() const noexcept { ETH_RETURN_STRING("Uncle in block already mentioned: Uncles " + toString(m_uncles) + " (" + m_block.abridged() + ")"); }
const char* InvalidTransactionsHash::what() const noexcept { ETH_RETURN_STRING("Invalid transactions hash: header says: " + toHex(m_head.ref()) + " block is:" + toHex(m_real.ref())); }
const char* InvalidGasLimit::what() const noexcept { ETH_RETURN_STRING("Invalid gas limit (provided: " + toString(provided) + " default:" + toString(valid) + " givenDiff:" + toString(givenDiff) + " maxDiff:" + toString(maxDiff) + ")"); }
const char* InvalidGasLimit::what() const noexcept { ETH_RETURN_STRING("Invalid gas limit (provided: " + toString(provided) + " minimum:" + toString(minimum) + " max:" + toString(maximum) + ")"); }
const char* InvalidMinGasPrice::what() const noexcept { ETH_RETURN_STRING("Invalid minimum gas price (provided: " + toString(provided) + " limit:" + toString(limit) + ")"); }
const char* InvalidNonce::what() const noexcept { ETH_RETURN_STRING("Invalid nonce (r: " + toString(required) + " c:" + toString(candidate) + ")"); }
const char* InvalidBlockNonce::what() const noexcept { ETH_RETURN_STRING("Invalid nonce (h: " + toString(h) + " n:" + toString(n) + " d:" + toString(d) + ")"); }

4
libethcore/Exceptions.h

@ -22,7 +22,7 @@
#pragma once
#include <libdevcore/Exceptions.h>
#include "CommonEth.h"
#include "Common.h"
namespace dev
{
@ -58,7 +58,7 @@ class InvalidTransactionsHash: virtual public dev::Exception { public: InvalidTr
struct InvalidTransaction: virtual dev::Exception {};
struct InvalidDifficulty: virtual dev::Exception {};
struct InvalidSeedHash: virtual dev::Exception {};
class InvalidGasLimit: virtual public dev::Exception { public: InvalidGasLimit(u256 _provided = 0, u256 _valid = 0, u256 _gD = 0, u256 _mD = 0): provided(_provided), valid(_valid), givenDiff(_gD), maxDiff(_mD) {} u256 provided; u256 valid; u256 givenDiff; u256 maxDiff; virtual const char* what() const noexcept; };
class InvalidGasLimit: virtual public dev::Exception { public: InvalidGasLimit(u256 _provided = 0, u256 _n = 0, u256 _x = 0): provided(_provided), minimum(_n), maximum(_x) {} u256 provided; u256 minimum; u256 maximum; virtual const char* what() const noexcept; };
class InvalidMinGasPrice: virtual public dev::Exception { public: InvalidMinGasPrice(u256 _provided = 0, u256 _limit = 0): provided(_provided), limit(_limit) {} u256 provided; u256 limit; virtual const char* what() const noexcept; };
struct InvalidTransactionGasUsed: virtual dev::Exception {};
struct InvalidTransactionsStateRoot: virtual dev::Exception {};

2
libethcore/ProofOfWork.h

@ -27,7 +27,7 @@
#include <thread>
#include <cstdint>
#include <libdevcrypto/SHA3.h>
#include "CommonEth.h"
#include "Common.h"
#include "BlockInfo.h"
#define FAKE_DAGGER 1

2
libethereum/Precompiled.cpp

@ -23,7 +23,7 @@
#include <libdevcrypto/SHA3.h>
#include <libdevcrypto/Common.h>
#include <libethcore/CommonEth.h>
#include <libethcore/Common.h>
#include <libethcore/Params.h>
using namespace std;
using namespace dev;

128
rlp/base64.cpp

@ -1,128 +0,0 @@
/*
base64.cpp and base64.h
Copyright (C) 2004-2008 René Nyffenegger
This source code is provided 'as-is', without any express or implied
warranty. In no event will the author be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
*/
/// code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c
/// originally by René Nyffenegger, modified by some other guy and then again by Gav Wood.
#include "base64.h"
#include <iostream>
using namespace std;
using namespace dev;
static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
static inline bool is_base64(byte c) {
return (isalnum(c) || (c == '+') || (c == '/'));
}
std::string dev::base64_encode(bytesConstRef _in) {
std::string ret;
int i = 0;
int j = 0;
byte char_array_3[3];
byte char_array_4[4];
auto buf = _in.data();
auto bufLen = _in.size();
while (bufLen--) {
char_array_3[i++] = *(buf++);
if (i == 3) {
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for(i = 0; (i <4) ; i++)
ret += base64_chars[char_array_4[i]];
i = 0;
}
}
if (i)
{
for(j = i; j < 3; j++)
char_array_3[j] = '\0';
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for (j = 0; (j < i + 1); j++)
ret += base64_chars[char_array_4[j]];
while((i++ < 3))
ret += '=';
}
return ret;
}
bytes dev::base64_decode(std::string const& encoded_string) {
int in_len = encoded_string.size();
int i = 0;
int j = 0;
int in_ = 0;
byte char_array_4[4], char_array_3[3];
bytes ret;
while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
char_array_4[i++] = encoded_string[in_]; in_++;
if (i ==4) {
for (i = 0; i <4; i++)
char_array_4[i] = base64_chars.find(char_array_4[i]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
for (i = 0; (i < 3); i++)
ret.push_back(char_array_3[i]);
i = 0;
}
}
if (i) {
for (j = i; j <4; j++)
char_array_4[j] = 0;
for (j = 0; j <4; j++)
char_array_4[j] = base64_chars.find(char_array_4[j]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
for (j = 0; (j < i - 1); j++) ret.push_back(char_array_3[j]);
}
return ret;
}

40
rlp/base64.h

@ -1,40 +0,0 @@
/*
base64.cpp and base64.h
Copyright (C) 2004-2008 René Nyffenegger
This source code is provided 'as-is', without any express or implied
warranty. In no event will the author be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
*/
/// code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c
/// originally by René Nyffenegger, modified by some other guy and then again by Gav Wood.
#pragma once
#include <vector>
#include <string>
#include <libdevcore/Common.h>
namespace dev
{
std::string base64_encode(bytesConstRef _in);
bytes base64_decode(std::string const& _in);
}

94
rlp/main.cpp

@ -22,11 +22,9 @@
#include <fstream>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h>
#include <libdevcore/RLP.h>
#include <libdevcrypto/SHA3.h>
#include "base64.h"
using namespace std;
using namespace dev;
@ -218,7 +216,7 @@ int main(int argc, char** argv)
boost::algorithm::replace_all(s, " ", "");
boost::algorithm::replace_all(s, "\n", "");
boost::algorithm::replace_all(s, "\t", "");
b = base64_decode(s);
b = fromBase64(s);
break;
}
default:
@ -228,60 +226,60 @@ int main(int argc, char** argv)
try
{
RLP rlp(b);
switch (mode)
{
case Mode::ListArchive:
{
if (!rlp.isList())
RLP rlp(b);
switch (mode)
{
cout << "Error: Invalid format; RLP data is not a list." << endl;
exit(1);
}
cout << rlp.itemCount() << " items:" << endl;
for (auto i: rlp)
case Mode::ListArchive:
{
if (!i.isData())
if (!rlp.isList())
{
cout << "Error: Invalid format; RLP list item is not data." << endl;
if (!lenience)
exit(1);
cout << "Error: Invalid format; RLP data is not a list." << endl;
exit(1);
}
cout << " " << i.size() << " bytes: " << sha3(i.data()) << endl;
}
break;
}
case Mode::ExtractArchive:
{
if (!rlp.isList())
{
cout << "Error: Invalid format; RLP data is not a list." << endl;
exit(1);
cout << rlp.itemCount() << " items:" << endl;
for (auto i: rlp)
{
if (!i.isData())
{
cout << "Error: Invalid format; RLP list item is not data." << endl;
if (!lenience)
exit(1);
}
cout << " " << i.size() << " bytes: " << sha3(i.data()) << endl;
}
break;
}
cout << rlp.itemCount() << " items:" << endl;
for (auto i: rlp)
case Mode::ExtractArchive:
{
if (!i.isData())
if (!rlp.isList())
{
cout << "Error: Invalid format; RLP list item is not data." << endl;
if (!lenience)
exit(1);
cout << "Error: Invalid format; RLP data is not a list." << endl;
exit(1);
}
ofstream fout;
fout.open(toString(sha3(i.data())));
fout.write(reinterpret_cast<char const*>(i.data().data()), i.data().size());
cout << rlp.itemCount() << " items:" << endl;
for (auto i: rlp)
{
if (!i.isData())
{
cout << "Error: Invalid format; RLP list item is not data." << endl;
if (!lenience)
exit(1);
}
ofstream fout;
fout.open(toString(sha3(i.data())));
fout.write(reinterpret_cast<char const*>(i.data().data()), i.data().size());
}
break;
}
case Mode::Render:
{
RLPStreamer s(cout, prefs);
s.output(rlp);
cout << endl;
break;
}
default:;
}
break;
}
case Mode::Render:
{
RLPStreamer s(cout, prefs);
s.output(rlp);
cout << endl;
break;
}
default:;
}
}
catch (...)
{

Loading…
Cancel
Save