Refactor FeeVote into IFeeVote abstract interface

This commit is contained in:
Vinnie Falco
2013-05-31 07:13:21 -07:00
parent a38795b3c5
commit fd6172273c
12 changed files with 249 additions and 117 deletions

View File

@@ -72,7 +72,6 @@
#include "src/cpp/ripple/CanonicalTXSet.h"
#include "src/cpp/ripple/ChangeTransactor.h"
#include "src/cpp/ripple/Config.h"
#include "src/cpp/ripple/FeatureTable.h"
#include "src/cpp/ripple/HashPrefixes.h"
#include "src/cpp/ripple/Ledger.h"
#include "src/cpp/ripple/LedgerAcquire.h"
@@ -121,8 +120,17 @@
#include "src/cpp/ripple/Interpreter.h"
#include "src/cpp/ripple/Operation.h"
// New abstract interfaces
#include "src/cpp/ripple/ripple_IFeatures.h"
#include "src/cpp/ripple/ripple_IFeeVote.h"
#include "src/cpp/ripple/FeatureTable.h"
//------------------------------------------------------------------------------
// main
#include "src/cpp/ripple/Application.cpp"
// contracts
#include "src/cpp/ripple/Contract.cpp" // no log
#include "src/cpp/ripple/Interpreter.cpp" // no log
@@ -181,6 +189,10 @@
#include "src/cpp/ripple/Wallet.cpp"
#include "src/cpp/ripple/WalletAddTransactor.cpp"
// Implementation of interfaces
#include "src/cpp/ripple/ripple_FeeVote.cpp"
#ifdef _MSC_VER
//#pragma warning (pop)
#endif

View File

@@ -34,7 +34,6 @@
#pragma warning (disable: 4535) // call requires /EHa
#endif
#include "src/cpp/ripple/Application.cpp"
#include "src/cpp/ripple/Config.cpp" // no log
#include "src/cpp/ripple/JobQueue.cpp"
#include "src/cpp/ripple/LoadManager.cpp"

View File

@@ -974,6 +974,12 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_FeeVote.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\cpp\ripple\rpc.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -1634,6 +1640,8 @@
<ClInclude Include="src\cpp\ripple\RegularKeySetTransactor.h" />
<ClInclude Include="src\cpp\ripple\RippleCalc.h" />
<ClInclude Include="src\cpp\ripple\RippleState.h" />
<ClInclude Include="src\cpp\ripple\ripple_IFeatures.h" />
<ClInclude Include="src\cpp\ripple\ripple_IFeeVote.h" />
<ClInclude Include="src\cpp\ripple\RPC.h" />
<ClInclude Include="src\cpp\ripple\RPCDoor.h" />
<ClInclude Include="src\cpp\ripple\RPCErr.h" />

View File

@@ -136,6 +136,9 @@
<Filter Include="1. Modules\ripple_data\protobuf">
<UniqueIdentifier>{9f8ed40a-9f16-42fe-82fd-caf72d3d6a2b}</UniqueIdentifier>
</Filter>
<Filter Include="1. Modules\ripple_ledger\main">
<UniqueIdentifier>{1ccfc5ad-5cd7-4a8e-b305-08f663c2397c}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\cpp\database\sqlite3.c">
@@ -603,9 +606,6 @@
<ClCompile Include="src\cpp\database\SqliteDatabase.cpp">
<Filter>1. Modules\ripple_db\storage</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\Application.cpp">
<Filter>1. Modules\ripple_main\_old</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\Config.cpp">
<Filter>1. Modules\ripple_main\_old</Filter>
</ClCompile>
@@ -786,6 +786,12 @@
<ClCompile Include="build\proto\ripple.pb.cc">
<Filter>1. Modules\ripple_data\protobuf</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\ripple_FeeVote.cpp">
<Filter>1. Modules\ripple_ledger\processing</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\Application.cpp">
<Filter>1. Modules\ripple_ledger\main</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="database\sqlite3ext.h">
@@ -1241,9 +1247,6 @@
<ClInclude Include="src\cpp\database\SqliteDatabase.h">
<Filter>1. Modules\ripple_db\storage</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\Application.h">
<Filter>1. Modules\ripple_main\_old</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\Config.h">
<Filter>1. Modules\ripple_main\_old</Filter>
</ClInclude>
@@ -1460,6 +1463,15 @@
<ClInclude Include="build\proto\ripple.pb.h">
<Filter>1. Modules\ripple_data\protobuf</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_IFeatures.h">
<Filter>1. Modules\ripple_ledger\processing</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\ripple_IFeeVote.h">
<Filter>1. Modules\ripple_ledger\processing</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\Application.h">
<Filter>1. Modules\ripple_ledger\main</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="SConstruct" />

View File

@@ -1,3 +1,7 @@
#ifndef RIPPLE_SQLITEDATABASE_H
#define RIPPLE_SQLITEDATABASE_H
#include "database.h"
#include <string>
@@ -112,4 +116,7 @@ public:
std::string getError(int);
};
#endif
// vim:ts=4

View File

@@ -52,7 +52,7 @@ Application::Application() :
mTempNodeCache("NodeCache", 16384, 90), mHashedObjectStore(16384, 300), mSLECache("LedgerEntryCache", 4096, 120),
mSNTPClient(mAuxService), mJobQueue(mIOService), mFeeTrack(),
mFeeVote(10, 50 * SYSTEM_CURRENCY_PARTS, 12.5 * SYSTEM_CURRENCY_PARTS),
mFeeVote (IFeeVote::New (10, 50 * SYSTEM_CURRENCY_PARTS, 12.5 * SYSTEM_CURRENCY_PARTS)),
mFeatureTable(2 * 7 * 24 * 60 * 60, 200), // two weeks, 200/256
mRpcDB(NULL), mTxnDB(NULL), mLedgerDB(NULL), mWalletDB(NULL),
@@ -407,6 +407,7 @@ void Application::sweep()
Application::~Application()
{
delete mFeeVote;
delete mTxnDB;
delete mLedgerDB;
delete mWalletDB;

View File

@@ -29,6 +29,10 @@
#include "TransactionQueue.h"
#include "OrderBookDB.h"
// VFALCO: TODO, Fix forward declares required for header dependency loops
class IFeatureTable;
class IFeeVote;
class RPCDoor;
class PeerDoor;
typedef TaggedCache< uint256, std::vector<unsigned char>, UptimeTimerAdapter> NodeCache;
@@ -74,7 +78,7 @@ class Application
LoadFeeTrack mFeeTrack;
TXQueue mTxnQueue;
OrderBookDB mOrderBookDB;
FeeVote mFeeVote;
IFeeVote* mFeeVote;
FeatureTable mFeatureTable;
DatabaseCon *mRpcDB, *mTxnDB, *mLedgerDB, *mWalletDB, *mNetNodeDB, *mPathFindDB, *mHashNodeDB;
@@ -133,7 +137,7 @@ public:
PeerDoor& getPeerDoor() { return *mPeerDoor; }
OrderBookDB& getOrderBookDB() { return mOrderBookDB; }
SLECache& getSLECache() { return mSLECache; }
FeeVote& getFeeVote() { return mFeeVote; }
IFeeVote& getFeeVote() { return *mFeeVote; }
FeatureTable& getFeatureTable() { return mFeatureTable; }

View File

@@ -363,87 +363,4 @@ public:
}
};
void FeeVote::doValidation(Ledger::ref lastClosedLedger, STObject& validation)
{
if (lastClosedLedger->getBaseFee() != mTargetBaseFee)
{
WriteLog (lsINFO, FeatureTable) << "Voting for base fee of " << mTargetBaseFee;
validation.setFieldU64(sfBaseFee, mTargetBaseFee);
}
if (lastClosedLedger->getReserve(0) != mTargetReserveBase)
{
WriteLog (lsINFO, FeatureTable) << "Voting for base resrve of " << mTargetReserveBase;
validation.setFieldU32(sfReserveBase, mTargetReserveBase);
}
if (lastClosedLedger->getReserveInc() != mTargetReserveIncrement)
{
WriteLog (lsINFO, FeatureTable) << "Voting for reserve increment of " << mTargetReserveIncrement;
validation.setFieldU32(sfReserveIncrement, mTargetReserveIncrement);
}
}
void FeeVote::doVoting(Ledger::ref lastClosedLedger, SHAMap::ref initialPosition)
{
// LCL must be flag ledger
assert((lastClosedLedger->getLedgerSeq() % 256) == 0);
VotableInteger<uint64> baseFeeVote(lastClosedLedger->getBaseFee(), mTargetBaseFee);
VotableInteger<uint32> baseReserveVote(lastClosedLedger->getReserve(0), mTargetReserveBase);
VotableInteger<uint32> incReserveVote(lastClosedLedger->getReserveInc(), mTargetReserveIncrement);
// get validations for ledger before flag
ValidationSet set = theApp->getValidations().getValidations(lastClosedLedger->getParentHash());
BOOST_FOREACH(ValidationSet::value_type& value, set)
{
SerializedValidation& val = *value.second;
if (val.isTrusted())
{
if (val.isFieldPresent(sfBaseFee))
baseFeeVote.addVote(val.getFieldU64(sfBaseFee));
else
baseFeeVote.noVote();
if (val.isFieldPresent(sfReserveBase))
baseReserveVote.addVote(val.getFieldU32(sfReserveBase));
else
baseReserveVote.noVote();
if (val.isFieldPresent(sfReserveIncrement))
incReserveVote.addVote(val.getFieldU32(sfReserveIncrement));
else
incReserveVote.noVote();
}
}
// choose our positions
uint64 baseFee = baseFeeVote.getVotes();
uint32 baseReserve = baseReserveVote.getVotes();
uint32 incReserve = incReserveVote.getVotes();
// add transactions to our position
if ((baseFee != lastClosedLedger->getBaseFee()) ||
(baseReserve != lastClosedLedger->getReserve(0)) ||
(incReserve != lastClosedLedger->getReserveInc()))
{
WriteLog (lsWARNING, FeatureTable) << "We are voting for a fee change: " << baseFee << "/" << baseReserve << "/" << incReserve;
SerializedTransaction trans(ttFEE);
trans.setFieldAccount(sfAccount, uint160());
trans.setFieldU64(sfBaseFee, baseFee);
trans.setFieldU32(sfReferenceFeeUnits, 10);
trans.setFieldU32(sfReserveBase, baseReserve);
trans.setFieldU32(sfReserveIncrement, incReserve);
uint256 txID = trans.getTransactionID();
WriteLog (lsWARNING, FeatureTable) << "Vote: " << txID;
Serializer s;
trans.add(s, true);
SHAMapItem::pointer tItem = boost::make_shared<SHAMapItem>(txID, s.peekData());
if (!initialPosition->addGiveItem(tItem, true, false))
{
WriteLog (lsWARNING, FeatureTable) << "Ledger already had fee change";
}
}
}
// vim:ts=4

View File

@@ -81,27 +81,4 @@ public:
void doVoting(Ledger::ref lastClosedLedger, SHAMap::ref initialPosition);
};
class FeeVote
{
protected:
// What we'd like to see
uint64 mTargetBaseFee;
uint32 mTargetReserveBase, mTargetReserveIncrement;
public:
FeeVote(uint64 targetBaseFee, uint32 targetReserveBase, uint32 targetReserveIncrement) :
mTargetBaseFee(targetBaseFee),
mTargetReserveBase(targetReserveBase),
mTargetReserveIncrement(targetReserveIncrement)
{ ; }
// add our wishes to our validation
void doValidation(Ledger::ref lastClosedLedger, STObject& baseValidation);
// vote on the fee we want
void doVoting(Ledger::ref lastClosedLedger, SHAMap::ref initialPosition);
};
#endif

View File

@@ -0,0 +1,136 @@
class FeatureTable;
//------------------------------------------------------------------------------
class FeeVote : public IFeeVote
{
public:
FeeVote (uint64 targetBaseFee, uint32 targetReserveBase, uint32 targetReserveIncrement)
: mTargetBaseFee (targetBaseFee)
, mTargetReserveBase (targetReserveBase)
, mTargetReserveIncrement (targetReserveIncrement)
{
}
//--------------------------------------------------------------------------
void doValidation (Ledger::ref lastClosedLedger, STObject& baseValidation)
{
if (lastClosedLedger->getBaseFee() != mTargetBaseFee)
{
WriteLog (lsINFO, FeatureTable) << "Voting for base fee of " << mTargetBaseFee;
baseValidation.setFieldU64(sfBaseFee, mTargetBaseFee);
}
if (lastClosedLedger->getReserve(0) != mTargetReserveBase)
{
WriteLog (lsINFO, FeatureTable) << "Voting for base resrve of " << mTargetReserveBase;
baseValidation.setFieldU32(sfReserveBase, mTargetReserveBase);
}
if (lastClosedLedger->getReserveInc() != mTargetReserveIncrement)
{
WriteLog (lsINFO, FeatureTable) << "Voting for reserve increment of " << mTargetReserveIncrement;
baseValidation.setFieldU32(sfReserveIncrement, mTargetReserveIncrement);
}
}
//--------------------------------------------------------------------------
void doVoting (Ledger::ref lastClosedLedger, SHAMap::ref initialPosition)
{
// LCL must be flag ledger
assert((lastClosedLedger->getLedgerSeq() % 256) == 0);
VotableInteger<uint64> baseFeeVote(lastClosedLedger->getBaseFee(), mTargetBaseFee);
VotableInteger<uint32> baseReserveVote(lastClosedLedger->getReserve(0), mTargetReserveBase);
VotableInteger<uint32> incReserveVote(lastClosedLedger->getReserveInc(), mTargetReserveIncrement);
// get validations for ledger before flag
ValidationSet set = theApp->getValidations().getValidations(lastClosedLedger->getParentHash());
BOOST_FOREACH(ValidationSet::value_type const& value, set)
{
SerializedValidation const& val = *value.second;
if (val.isTrusted())
{
if (val.isFieldPresent(sfBaseFee))
{
baseFeeVote.addVote(val.getFieldU64(sfBaseFee));
}
else
{
baseFeeVote.noVote();
}
if (val.isFieldPresent(sfReserveBase))
{
baseReserveVote.addVote(val.getFieldU32(sfReserveBase));
}
else
{
baseReserveVote.noVote();
}
if (val.isFieldPresent(sfReserveIncrement))
{
incReserveVote.addVote(val.getFieldU32(sfReserveIncrement));
}
else
{
incReserveVote.noVote();
}
}
}
// choose our positions
uint64 baseFee = baseFeeVote.getVotes();
uint32 baseReserve = baseReserveVote.getVotes();
uint32 incReserve = incReserveVote.getVotes();
// add transactions to our position
if ((baseFee != lastClosedLedger->getBaseFee()) ||
(baseReserve != lastClosedLedger->getReserve(0)) ||
(incReserve != lastClosedLedger->getReserveInc()))
{
WriteLog (lsWARNING, FeatureTable) << "We are voting for a fee change: " << baseFee << "/" << baseReserve << "/" << incReserve;
SerializedTransaction trans(ttFEE);
trans.setFieldAccount(sfAccount, uint160());
trans.setFieldU64(sfBaseFee, baseFee);
trans.setFieldU32(sfReferenceFeeUnits, 10);
trans.setFieldU32(sfReserveBase, baseReserve);
trans.setFieldU32(sfReserveIncrement, incReserve);
uint256 txID = trans.getTransactionID();
WriteLog (lsWARNING, FeatureTable) << "Vote: " << txID;
Serializer s;
trans.add(s, true);
SHAMapItem::pointer tItem = boost::make_shared<SHAMapItem>(txID, s.peekData());
if (!initialPosition->addGiveItem(tItem, true, false))
{
WriteLog (lsWARNING, FeatureTable) << "Ledger already had fee change";
}
}
}
private:
uint64 mTargetBaseFee;
uint32 mTargetReserveBase;
uint32 mTargetReserveIncrement;
};
//------------------------------------------------------------------------------
IFeeVote* IFeeVote::New (uint64 targetBaseFee,
uint32 targetReserveBase,
uint32 targetReserveIncrement)
{
return new FeeVote (targetBaseFee, targetReserveBase, targetReserveIncrement);
}
// vim:ts=4

View File

@@ -0,0 +1,21 @@
#ifndef RIPPLE_IFEATURES_H
#define RIPPLE_IFEATURES_H
/** Feature table interface.
The feature table stores the list of enabled and potential features.
Individuals features are voted on by validators during the consensus
process.
*/
class IFeatureTable
{
public:
static IFeatureTable* New (uint32 majorityTime, int majorityFraction);
virtual ~IFeatureTable () { }
virtual void doValidation (Ledger::ref lastClosedLedger, STObject& baseValidation) = 0;
virtual void doVoting (Ledger::ref lastClosedLedger, SHAMap::ref initialPosition) = 0;
};
#endif

View File

@@ -0,0 +1,38 @@
#ifndef RIPPLE_IFEEVOTE_H
#define RIPPLE_IFEEVOTE_H
/** Manager to process fee votes.
*/
class IFeeVote
{
public:
/** Create a new fee vote manager.
@param targetBaseFee
@param targetReserveBase
@param targetReserveIncrement
*/
static IFeeVote* New (uint64 targetBaseFee,
uint32 targetReserveBase,
uint32 targetReserveIncrement);
virtual ~IFeeVote () { }
/** Add local fee preference to validation.
@param lastClosedLedger
@param baseValidation
*/
virtual void doValidation (Ledger::ref lastClosedLedger,
STObject& baseValidation) = 0;
/** Cast our local vote on the fee.
@param lastClosedLedger
@param initialPosition
*/
virtual void doVoting (Ledger::ref lastClosedLedger,
SHAMap::ref initialPosition) = 0;
};
#endif