mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Finish fee change logic.
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
#include "ChangeTransactor.h"
|
#include "ChangeTransactor.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
SETUP_LOG();
|
||||||
|
|
||||||
TER ChangeTransactor::doApply()
|
TER ChangeTransactor::doApply()
|
||||||
{
|
{
|
||||||
@@ -14,10 +17,16 @@ TER ChangeTransactor::doApply()
|
|||||||
TER ChangeTransactor::checkSig()
|
TER ChangeTransactor::checkSig()
|
||||||
{
|
{
|
||||||
if (mTxn.getFieldAccount160(sfAccount).isNonZero())
|
if (mTxn.getFieldAccount160(sfAccount).isNonZero())
|
||||||
|
{
|
||||||
|
cLog(lsWARNING) << "Change transaction had bad source account";
|
||||||
return temBAD_SRC_ACCOUNT;
|
return temBAD_SRC_ACCOUNT;
|
||||||
|
}
|
||||||
|
|
||||||
if (!mTxn.getSigningPubKey().empty() || !mTxn.getSignature().empty())
|
if (!mTxn.getSigningPubKey().empty() || !mTxn.getSignature().empty())
|
||||||
|
{
|
||||||
|
cLog(lsWARNING) << "Change transaction had bad signature";
|
||||||
return temBAD_SIGNATURE;
|
return temBAD_SIGNATURE;
|
||||||
|
}
|
||||||
|
|
||||||
return tesSUCCESS;
|
return tesSUCCESS;
|
||||||
}
|
}
|
||||||
@@ -25,15 +34,26 @@ TER ChangeTransactor::checkSig()
|
|||||||
TER ChangeTransactor::checkSeq()
|
TER ChangeTransactor::checkSeq()
|
||||||
{
|
{
|
||||||
if (mTxn.getSequence() != 0)
|
if (mTxn.getSequence() != 0)
|
||||||
|
{
|
||||||
|
cLog(lsWARNING) << "Change transaction had bad sequence";
|
||||||
return temBAD_SEQUENCE;
|
return temBAD_SEQUENCE;
|
||||||
|
}
|
||||||
return tesSUCCESS;
|
return tesSUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
TER ChangeTransactor::payFee()
|
TER ChangeTransactor::payFee()
|
||||||
{
|
{
|
||||||
|
if (isSetBit(mParams, tapOPEN_LEDGER))
|
||||||
|
{
|
||||||
|
cLog(lsWARNING) << "Change transaction against open ledger";
|
||||||
|
return temINVALID;
|
||||||
|
}
|
||||||
|
|
||||||
if (mTxn.getTransactionFee() != STAmount())
|
if (mTxn.getTransactionFee() != STAmount())
|
||||||
|
{
|
||||||
|
cLog(lsWARNING) << "Change transaction with non-zero fee";
|
||||||
return temBAD_FEE;
|
return temBAD_FEE;
|
||||||
|
}
|
||||||
|
|
||||||
return tesSUCCESS;
|
return tesSUCCESS;
|
||||||
}
|
}
|
||||||
@@ -70,5 +90,6 @@ TER ChangeTransactor::applyFee()
|
|||||||
feeObject->setFieldU32(sfReserveIncrement, mTxn.getFieldU32(sfReserveIncrement));
|
feeObject->setFieldU32(sfReserveIncrement, mTxn.getFieldU32(sfReserveIncrement));
|
||||||
|
|
||||||
mEngine->entryModify(feeObject);
|
mEngine->entryModify(feeObject);
|
||||||
|
cLog(lsWARNING) << "Fees have been changed";
|
||||||
return tesSUCCESS;
|
return tesSUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "Application.h"
|
||||||
|
#include "ValidationCollection.h"
|
||||||
|
#include "HashPrefixes.h"
|
||||||
|
|
||||||
SETUP_LOG();
|
SETUP_LOG();
|
||||||
|
|
||||||
@@ -243,6 +246,7 @@ protected:
|
|||||||
INT mTarget; // The setting we want
|
INT mTarget; // The setting we want
|
||||||
std::map<INT, int> mVoteMap;
|
std::map<INT, int> mVoteMap;
|
||||||
|
|
||||||
|
public:
|
||||||
VotableInteger(INT current, INT target) : mCurrent(current), mTarget(target)
|
VotableInteger(INT current, INT target) : mCurrent(current), mTarget(target)
|
||||||
{
|
{
|
||||||
++mVoteMap[mTarget]; // Add our vote
|
++mVoteMap[mTarget]; // Add our vote
|
||||||
@@ -268,8 +272,8 @@ protected:
|
|||||||
INT ourVote = mCurrent;
|
INT ourVote = mCurrent;
|
||||||
int weight = 0;
|
int weight = 0;
|
||||||
|
|
||||||
typedef std::pair<INT, int> INTint_pair_t;
|
typedef typename std::map<INT, int>::value_type mapVType;
|
||||||
BOOST_FOREACH(INTint_pair_t& value, mVoteMap)
|
BOOST_FOREACH(const mapVType& value, mVoteMap)
|
||||||
{ // Take most voted value between current and target, inclusive
|
{ // Take most voted value between current and target, inclusive
|
||||||
if ((value.first <= std::max(mTarget, mCurrent)) &&
|
if ((value.first <= std::max(mTarget, mCurrent)) &&
|
||||||
(value.first >= std::min(mTarget, mCurrent)) &&
|
(value.first >= std::min(mTarget, mCurrent)) &&
|
||||||
@@ -284,16 +288,88 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void FeeVote::doValidation(Ledger::ref lastClosedLedger, STObject& validation)
|
||||||
|
{
|
||||||
|
if (lastClosedLedger->getBaseFee() != mTargetBaseFee)
|
||||||
|
{
|
||||||
|
cLog(lsINFO) << "Voting for base fee of " << mTargetBaseFee;
|
||||||
|
validation.setFieldU64(sfBaseFee, mTargetBaseFee);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastClosedLedger->getReserve(0) != mTargetReserveBase)
|
||||||
|
{
|
||||||
|
cLog(lsINFO) << "Voting for base resrve of " << mTargetReserveBase;
|
||||||
|
validation.setFieldU32(sfReserveBase, mTargetReserveBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastClosedLedger->getReserveInc() != mTargetReserveIncrement)
|
||||||
|
{
|
||||||
|
cLog(lsINFO) << "Voting for reserve increment of " << mTargetReserveIncrement;
|
||||||
|
validation.setFieldU32(sfReserveIncrement, mTargetReserveIncrement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FeeVote::doFeeVoting(Ledger::ref lastClosedLedger, SHAMap::ref initialPosition)
|
void FeeVote::doFeeVoting(Ledger::ref lastClosedLedger, SHAMap::ref initialPosition)
|
||||||
{
|
{
|
||||||
// LCL must be flag ledger
|
// LCL must be flag ledger
|
||||||
assert((lastClosedLedger->getLedgerSeq() % 256) == 0);
|
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
|
// 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
|
// choose our positions
|
||||||
|
uint64 baseFee = baseFeeVote.getVotes();
|
||||||
|
uint32 baseReserve = baseReserveVote.getVotes();
|
||||||
|
uint32 incReserve = incReserveVote.getVotes();
|
||||||
|
|
||||||
// add transactions to our position
|
// add transactions to our position
|
||||||
|
if ((baseFee != lastClosedLedger->getBaseFee()) ||
|
||||||
|
(baseReserve != lastClosedLedger->getReserve(0)) ||
|
||||||
|
(incReserve != lastClosedLedger->getReserveInc()))
|
||||||
|
{
|
||||||
|
cLog(lsWARNING) << "We are voting for a fee change: " << baseFee << "/" << baseReserve << "/" << incReserve;
|
||||||
|
SerializedTransaction trans(ttFEE);
|
||||||
|
trans.setFieldU64(sfBaseFee, baseFee);
|
||||||
|
trans.setFieldU32(sfReferenceFeeUnits, 10);
|
||||||
|
trans.setFieldU32(sfReserveBase, baseReserve);
|
||||||
|
trans.setFieldU32(sfReserveIncrement, incReserve);
|
||||||
|
|
||||||
|
|
||||||
|
Serializer s;
|
||||||
|
s.add32(sHP_TransactionID);
|
||||||
|
trans.add(s, true);
|
||||||
|
uint256 txID = s.getSHA512Half();
|
||||||
|
cLog(lsWARNING) << "Vote: " << txID;
|
||||||
|
|
||||||
|
SHAMapItem::pointer tItem = boost::make_shared<SHAMapItem>(txID, s.peekData());
|
||||||
|
if (!initialPosition->addGiveItem(tItem, true, false))
|
||||||
|
{
|
||||||
|
cLog(lsWARNING) << "Ledger already had fee change";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
@@ -93,8 +93,10 @@ public:
|
|||||||
mTargetReserveIncrement(targetReserveIncrement)
|
mTargetReserveIncrement(targetReserveIncrement)
|
||||||
{ ; }
|
{ ; }
|
||||||
|
|
||||||
void doValidation(STObject& baseValidation);
|
// add our wishes to our validation
|
||||||
|
void doValidation(Ledger::ref lastClosedLedger, STObject& baseValidation);
|
||||||
|
|
||||||
|
// vote on the fee we want
|
||||||
void doFeeVoting(Ledger::ref lastClosedLedger, SHAMap::ref initialPosition);
|
void doFeeVoting(Ledger::ref lastClosedLedger, SHAMap::ref initialPosition);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -317,7 +317,16 @@ void LedgerConsensus::handleLCL(const uint256& lclHash)
|
|||||||
|
|
||||||
void LedgerConsensus::takeInitialPosition(Ledger& initialLedger)
|
void LedgerConsensus::takeInitialPosition(Ledger& initialLedger)
|
||||||
{
|
{
|
||||||
SHAMap::pointer initialSet = initialLedger.peekTransactionMap()->snapShot(false);
|
SHAMap::pointer initialSet;
|
||||||
|
|
||||||
|
if (mProposing && mHaveCorrectLCL && ((mPreviousLedger->getLedgerSeq() % 256) == 0))
|
||||||
|
{ // previous ledger was flag ledger
|
||||||
|
SHAMap::pointer preSet = initialLedger.peekTransactionMap()->snapShot(true);
|
||||||
|
theApp->getFeeVote().doFeeVoting(mPreviousLedger, preSet);
|
||||||
|
initialSet = preSet->snapShot(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
initialSet = initialLedger.peekTransactionMap()->snapShot(false);
|
||||||
uint256 txSet = initialSet->getHash();
|
uint256 txSet = initialSet->getHash();
|
||||||
cLog(lsINFO) << "initial position " << txSet;
|
cLog(lsINFO) << "initial position " << txSet;
|
||||||
mapComplete(txSet, initialSet, false);
|
mapComplete(txSet, initialSet, false);
|
||||||
@@ -1208,6 +1217,8 @@ void LedgerConsensus::accept(SHAMap::ref set, LoadEvent::pointer)
|
|||||||
SerializedValidation::pointer v = boost::make_shared<SerializedValidation>
|
SerializedValidation::pointer v = boost::make_shared<SerializedValidation>
|
||||||
(newLCLHash, theApp->getOPs().getValidationTimeNC(), mValPublic, mProposing);
|
(newLCLHash, theApp->getOPs().getValidationTimeNC(), mValPublic, mProposing);
|
||||||
v->setFieldU32(sfLedgerSequence, newLCL->getLedgerSeq());
|
v->setFieldU32(sfLedgerSequence, newLCL->getLedgerSeq());
|
||||||
|
if (((newLCL->getLedgerSeq() + 1) % 256) == 0) // next ledger is flag ledger
|
||||||
|
theApp->getFeeVote().doValidation(newLCL, *v);
|
||||||
v->sign(signingHash, mValPrivate);
|
v->sign(signingHash, mValPrivate);
|
||||||
v->setTrusted();
|
v->setTrusted();
|
||||||
theApp->isNew(signingHash); // suppress it if we receive it
|
theApp->isNew(signingHash); // suppress it if we receive it
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ enum TransactionEngineParams
|
|||||||
tapRETRY = 0x20, // This is not the transaction's last pass
|
tapRETRY = 0x20, // This is not the transaction's last pass
|
||||||
// Transaction can be retried, soft failures allowed
|
// Transaction can be retried, soft failures allowed
|
||||||
|
|
||||||
tapAFTER_END = 0x40, // We are processing the transaction last
|
|
||||||
|
|
||||||
tapADMIN = 0x400, // Transaction came from a privileged source
|
tapADMIN = 0x400, // Transaction came from a privileged source
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user