diff --git a/eth/main.cpp b/eth/main.cpp index da8943e46..606b1d6c5 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -1115,13 +1115,33 @@ int main(int argc, char** argv) else if (c && cmd == "setblockfees") { iss >> blockFees; - gasPricer->setRefBlockFees(u256(blockFees * 1000)); + try + { + gasPricer->setRefBlockFees(u256(blockFees * 1000)); + } + catch(Overflow const& _e) + { + cout << boost::diagnostic_information(_e); + } + cout << "Block fees: " << blockFees << endl; } else if (c && cmd == "setetherprice") { iss >> etherPrice; - gasPricer->setRefPrice(u256(double(ether / 1000) / etherPrice)); + if (etherPrice == 0) + cout << "ether price can not be set to zero" << endl; + else + { + try + { + gasPricer->setRefPrice(u256(double(ether / 1000) / etherPrice)); + } + catch(Overflow const& _e) + { + cout << boost::diagnostic_information(_e); + } + } cout << "ether Price: " << etherPrice << endl; } else if (c && cmd == "setpriority") diff --git a/libdevcore/Exceptions.h b/libdevcore/Exceptions.h index 377420003..219047827 100644 --- a/libdevcore/Exceptions.h +++ b/libdevcore/Exceptions.h @@ -51,6 +51,7 @@ struct NoUPnPDevice: virtual Exception {}; struct RootNotFound: virtual Exception {}; struct BadRoot: virtual Exception {}; struct FileError: virtual Exception {}; +struct Overflow: virtual Exception {}; struct InterfaceNotSupported: virtual Exception { public: InterfaceNotSupported(std::string _f): Exception("Interface " + _f + " not supported.") {} }; // error information to be added to exceptions diff --git a/libethereum/Client.h b/libethereum/Client.h index d4c55ef55..aaa79e39f 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -77,8 +77,8 @@ class BasicGasPricer: public GasPricer public: explicit BasicGasPricer(u256 _weiPerRef, u256 _refsPerBlock): m_weiPerRef(_weiPerRef), m_refsPerBlock(_refsPerBlock) {} - void setRefPrice(u256 _weiPerRef) { m_weiPerRef = _weiPerRef; } - void setRefBlockFees(u256 _refsPerBlock) { m_refsPerBlock = _refsPerBlock; } + void setRefPrice(u256 _weiPerRef) { if ((bigint)m_refsPerBlock * _weiPerRef > std::numeric_limits::max() ) BOOST_THROW_EXCEPTION(Overflow() << errinfo_comment("ether price * block fees is larger than 2**256-1, choose a smaller number.") ); else m_weiPerRef = _weiPerRef; } + void setRefBlockFees(u256 _refsPerBlock) { if ((bigint)m_weiPerRef * _refsPerBlock > std::numeric_limits::max() ) BOOST_THROW_EXCEPTION(Overflow() << errinfo_comment("ether price * block fees is larger than 2**256-1, choose a smaller number.") ); else m_refsPerBlock = _refsPerBlock; } u256 ask(State const&) const override { return m_weiPerRef * m_refsPerBlock / m_gasPerBlock; } u256 bid(TransactionPriority _p = TransactionPriority::Medium) const override { return m_octiles[(int)_p] > 0 ? m_octiles[(int)_p] : (m_weiPerRef * m_refsPerBlock / m_gasPerBlock); } diff --git a/neth/main.cpp b/neth/main.cpp index 4e83f64bc..e4ab18466 100644 --- a/neth/main.cpp +++ b/neth/main.cpp @@ -718,13 +718,33 @@ int main(int argc, char** argv) else if (c && cmd == "setblockfees") { iss >> blockFees; - gasPricer->setRefBlockFees(u256(blockFees * 1000)); + try + { + gasPricer->setRefBlockFees(u256(blockFees * 1000)); + } + catch(Overflow const& _e) + { + cout << boost::diagnostic_information(_e); + } + cout << "Block fees: " << blockFees << endl; } else if (c && cmd == "setetherprice") { iss >> etherPrice; - gasPricer->setRefPrice(u256(double(ether / 1000) / etherPrice)); + if (etherPrice == 0) + cout << "ether price can not be set to zero" << endl; + else + { + try + { + gasPricer->setRefPrice(u256(double(ether / 1000) / etherPrice)); + } + catch(Overflow const& _e) + { + cout << boost::diagnostic_information(_e); + } + } cout << "ether Price: " << etherPrice << endl; } else if (c && cmd == "setpriority") diff --git a/test/libethereum/gaspricer.cpp b/test/libethereum/gaspricer.cpp new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/test/libethereum/gaspricer.cpp @@ -0,0 +1 @@ +