Browse Source

optimization - higher precision and single gas price handling

cl-refactor
CJentzsch 10 years ago
parent
commit
94c84a75ec
  1. 24
      libethereum/Client.cpp
  2. 20
      test/libethereum/BlockTestsFiller/bcGasPricerTestFiller.json
  3. 18
      test/libethereum/gaspricer.cpp

24
libethereum/Client.cpp

@ -124,15 +124,23 @@ void BasicGasPricer::update(BlockChain const& _bc)
for (auto const& i: dist)
sdSquared += i.second * (i.first - mean) * (i.first - mean);
sdSquared /= total;
double sd = sqrt(sdSquared.convert_to<double>());
double normalizedSd = 4.0 * sd / mean.convert_to<double>();
// calc octiles normalized to gaussian distribution
boost::math::normal gauss(4, normalizedSd ? normalizedSd : 1);
for (int i = 1; i < 8; i++)
m_octiles[i] = mean / 4000 * int(boost::math::quantile(gauss, i / 8.0) * 1000);
m_octiles[8] = dist.rbegin()->first;
if (sdSquared)
{
long double sd = sqrt(sdSquared.convert_to<long double>());
long double normalizedSd = sd / mean.convert_to<long double>();
// calc octiles normalized to gaussian distribution
boost::math::normal gauss(1.0, (normalizedSd > 0.01) ? normalizedSd : 0.01);
for (size_t i = 1; i < 8; i++)
m_octiles[i] = u256(mean.convert_to<long double>() * boost::math::quantile(gauss, i / 8.0));
m_octiles[8] = dist.rbegin()->first;
}
else
{
for (size_t i = 0; i < 9; i++)
m_octiles[i] = (i + 1) * mean / 5;
}
}
}

20
test/libethereum/BlockTestsFiller/bcGasPricerTestFiller.json

@ -55,7 +55,7 @@
{
"transactions" : [
{
"data" : "0xfffffffffffff",
"data" : "0xffffffffffff",
"gasLimit" : "850000",
"gasPrice" : "12000000000000",
"nonce" : "1",
@ -70,7 +70,7 @@
{
"transactions" : [
{
"data" : "0xffffffffffffff",
"data" : "0xffffffffffff",
"gasLimit" : "850000",
"gasPrice" : "14000000000000",
"nonce" : "2",
@ -85,7 +85,7 @@
{
"transactions" : [
{
"data" : "0xfffffffffffffff",
"data" : "0xffffffffffff",
"gasLimit" : "850000",
"gasPrice" : "16000000000000",
"nonce" : "3",
@ -100,7 +100,7 @@
{
"transactions" : [
{
"data" : "0xfffffffffffffffffffffffffffffff",
"data" : "0xffffffffffff",
"gasLimit" : "850000",
"gasPrice" : "18000000000000",
"nonce" : "4",
@ -115,7 +115,7 @@
{
"transactions" : [
{
"data" : "0xffffffffffffffffffffffffffffffff",
"data" : "0xffffffffffff",
"gasLimit" : "850000",
"gasPrice" : "20000000000000",
"nonce" : "5",
@ -130,7 +130,7 @@
{
"transactions" : [
{
"data" : "0xffffffffffffffffffffffffffffffff",
"data" : "0xffffffffffff",
"gasLimit" : "850000",
"gasPrice" : "22000000000000",
"nonce" : "6",
@ -145,7 +145,7 @@
{
"transactions" : [
{
"data" : "0xffffffffffffffffffffffffffffffff",
"data" : "0xffffffffffff",
"gasLimit" : "850000",
"gasPrice" : "24000000000000",
"nonce" : "7",
@ -160,7 +160,7 @@
{
"transactions" : [
{
"data" : "0xffffffffffffffffffffffffffffffff",
"data" : "0xffffffffffff",
"gasLimit" : "850000",
"gasPrice" : "26000000000000",
"nonce" : "8",
@ -175,7 +175,7 @@
{
"transactions" : [
{
"data" : "0xffffffffffffffffffffffffffffffff",
"data" : "0xffffffffffff",
"gasLimit" : "850000",
"gasPrice" : "28000000000000",
"nonce" : "9",
@ -190,7 +190,7 @@
{
"transactions" : [
{
"data" : "0xffffffffffffffffffffffffffffffff",
"data" : "0xffffffffffff",
"gasLimit" : "850000",
"gasPrice" : "30000000000000",
"nonce" : "10",

18
test/libethereum/gaspricer.cpp

@ -90,22 +90,22 @@ BOOST_AUTO_TEST_CASE(basicGasPricerNoUpdate)
BOOST_AUTO_TEST_CASE(basicGasPricer_RPC_API_Test)
{
dev::test::executeGasPricerTest("RPC_API_Test", 30.679, 15.0, "/BlockTests/bcRPC_API_Test.json", TransactionPriority::Medium, 155632494086, 155632494086);
dev::test::executeGasPricerTest("RPC_API_Test", 30.679, 15.0, "/BlockTests/bcRPC_API_Test.json", TransactionPriority::Medium, 155632494086, 1);
}
BOOST_AUTO_TEST_CASE(basicGasPricer_bcValidBlockTest)
{
dev::test::executeGasPricerTest("SimpleTx", 30.679, 15.0, "/BlockTests/bcValidBlockTest.json", TransactionPriority::Medium, 155632494086, 155632494086);
dev::test::executeGasPricerTest("SimpleTx", 30.679, 15.0, "/BlockTests/bcValidBlockTest.json", TransactionPriority::Medium, 155632494086, 10);
}
BOOST_AUTO_TEST_CASE(basicGasPricer_bcUncleTest)
{
dev::test::executeGasPricerTest("twoUncle", 30.679, 15.0, "/BlockTests/bcUncleTest.json", TransactionPriority::Medium, 155632494086, 155632494086);
dev::test::executeGasPricerTest("twoUncle", 30.679, 15.0, "/BlockTests/bcUncleTest.json", TransactionPriority::Medium, 155632494086, 1);
}
BOOST_AUTO_TEST_CASE(basicGasPricer_bcUncleHeaderValiditiy)
{
dev::test::executeGasPricerTest("correct", 30.679, 15.0, "/BlockTests/bcUncleHeaderValiditiy.json", TransactionPriority::Medium, 155632494086, 155632494086);
dev::test::executeGasPricerTest("correct", 30.679, 15.0, "/BlockTests/bcUncleHeaderValiditiy.json", TransactionPriority::Medium, 155632494086, 1);
}
BOOST_AUTO_TEST_CASE(basicGasPricer_notxs)
@ -115,26 +115,26 @@ BOOST_AUTO_TEST_CASE(basicGasPricer_notxs)
BOOST_AUTO_TEST_CASE(basicGasPricer_highGasUsage_LowestPrio)
{
dev::test::executeGasPricerTest("highGasUsage", 30.679, 15.0, "/BlockTests/bcGasPricerTest.json", TransactionPriority::Lowest, 15731290119, 10000000000000);
dev::test::executeGasPricerTest("highGasUsage", 30.679, 15.0, "/BlockTests/bcGasPricerTest.json", TransactionPriority::Lowest, 15731292650, 10000000000000);
}
BOOST_AUTO_TEST_CASE(basicGasPricer_highGasUsage_LowPrio)
{
dev::test::executeGasPricerTest("highGasUsage", 30.679, 15.0, "/BlockTests/bcGasPricerTest.json", TransactionPriority::Low, 15731290119, 15812460025839);
dev::test::executeGasPricerTest("highGasUsage", 30.679, 15.0, "/BlockTests/bcGasPricerTest.json", TransactionPriority::Low, 15731292650, 15734152261884);
}
BOOST_AUTO_TEST_CASE(basicGasPricer_highGasUsage_MediumPrio)
{
dev::test::executeGasPricerTest("highGasUsage", 30.679, 15.0, "/BlockTests/bcGasPricerTest.json", TransactionPriority::Medium, 15731290119, 20072941956000);
dev::test::executeGasPricerTest("highGasUsage", 30.679, 15.0, "/BlockTests/bcGasPricerTest.json", TransactionPriority::Medium, 15731292650, 20000000000000);
}
BOOST_AUTO_TEST_CASE(basicGasPricer_highGasUsage_HighPrio)
{
dev::test::executeGasPricerTest("highGasUsage", 30.679, 15.0, "/BlockTests/bcGasPricerTest.json", TransactionPriority::High, 15731290119, 24328405650672);
dev::test::executeGasPricerTest("highGasUsage", 30.679, 15.0, "/BlockTests/bcGasPricerTest.json", TransactionPriority::High, 15731292650, 24265847738115);
}
BOOST_AUTO_TEST_CASE(basicGasPricer_highGasUsage_HighestPrio)
{
dev::test::executeGasPricerTest("highGasUsage", 30.679, 15.0, "/BlockTests/bcGasPricerTest.json", TransactionPriority::Highest, 15731290119, 30000000000000);
dev::test::executeGasPricerTest("highGasUsage", 30.679, 15.0, "/BlockTests/bcGasPricerTest.json", TransactionPriority::Highest, 15731292650, 30000000000000);
}
BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save