Freeze flags: (RIPD-394)

* Define all flags
 * Set/clear bits in transactors
 * Frozen line counts towards reserve, is non-default
 * Report trust line state
This commit is contained in:
JoelKatz
2014-05-22 14:22:15 -07:00
committed by David Schwartz
parent 07db5d497c
commit 4cf29455e4
9 changed files with 79 additions and 1 deletions

View File

@@ -74,6 +74,8 @@ JSS ( fee_base );
JSS ( fee_ref ); JSS ( fee_ref );
JSS ( fetch_pack ); JSS ( fetch_pack );
JSS ( flags ); JSS ( flags );
JSS ( freeze );
JSS ( freeze_peer );
JSS ( hash ); JSS ( hash );
JSS ( hostid ); JSS ( hostid );
JSS ( id ); JSS ( id );

View File

@@ -1367,6 +1367,7 @@ TER LedgerEntrySet::trustCreate (
SLE::ref sleAccount, // --> the account being set. SLE::ref sleAccount, // --> the account being set.
const bool bAuth, // --> authorize account. const bool bAuth, // --> authorize account.
const bool bNoRipple, // --> others cannot ripple through const bool bNoRipple, // --> others cannot ripple through
const bool bFreeze, // --> funds cannot leave
const STAmount& saBalance, // --> balance of account being set. const STAmount& saBalance, // --> balance of account being set.
// Issuer should be noAccount() // Issuer should be noAccount()
const STAmount& saLimit, // --> limit for account being set. const STAmount& saLimit, // --> limit for account being set.
@@ -1435,6 +1436,10 @@ TER LedgerEntrySet::trustCreate (
{ {
uFlags |= (bSetHigh ? lsfHighNoRipple : lsfLowNoRipple); uFlags |= (bSetHigh ? lsfHighNoRipple : lsfLowNoRipple);
} }
if (bFreeze)
{
uFlags |= (!bSetHigh ? lsfLowFreeze : lsfHighFreeze);
}
sleRippleState->setFieldU32 (sfFlags, uFlags); sleRippleState->setFieldU32 (sfFlags, uFlags);
ownerCountAdjust ( ownerCountAdjust (
@@ -1536,6 +1541,7 @@ TER LedgerEntrySet::rippleCredit (
entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID)), entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID)),
false, false,
false, false,
false,
saBalance, saBalance,
saReceiverLimit); saReceiverLimit);
} }
@@ -1568,6 +1574,7 @@ TER LedgerEntrySet::rippleCredit (
&& (uFlags & (!bSenderHigh ? lsfLowReserve : lsfHighReserve)) && (uFlags & (!bSenderHigh ? lsfLowReserve : lsfHighReserve))
// Sender reserve is set. // Sender reserve is set.
&& !(uFlags & (!bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple)) && !(uFlags & (!bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple))
&& !(uFlags & (!bSenderHigh ? lsfLowFreeze : lsfHighFreeze))
&& !sleRippleState->getFieldAmount ( && !sleRippleState->getFieldAmount (
!bSenderHigh ? sfLowLimit : sfHighLimit) !bSenderHigh ? sfLowLimit : sfHighLimit)
// Sender trust limit is 0. // Sender trust limit is 0.

View File

@@ -246,6 +246,7 @@ public:
SLE::ref sleAccount, SLE::ref sleAccount,
const bool bAuth, const bool bAuth,
const bool bNoRipple, const bool bNoRipple,
const bool bFreeze,
const STAmount& saSrcBalance, const STAmount& saSrcBalance,
const STAmount& saSrcLimit, const STAmount& saSrcLimit,
const std::uint32_t uSrcQualityIn = 0, const std::uint32_t uSrcQualityIn = 0,

View File

@@ -78,6 +78,18 @@ public:
return mFlags & (!mViewLowest ? lsfLowNoRipple : lsfHighNoRipple); return mFlags & (!mViewLowest ? lsfLowNoRipple : lsfHighNoRipple);
} }
/** Have we set the freeze flag on our peer */
bool getFreeze () const
{
return mFlags & (mViewLowest ? lsfLowFreeze : lsfHighFreeze);
}
/** Has the peer set the freeze flag on us */
bool getFreezePeer () const
{
return mFlags & (!mViewLowest ? lsfLowFreeze : lsfHighFreeze);
}
const STAmount& getBalance () const const STAmount& getBalance () const
{ {
return mBalance; return mBalance;

View File

@@ -29,6 +29,12 @@ TER SetAccount::doApply ()
std::uint32_t const uSetFlag = mTxn.getFieldU32 (sfSetFlag); std::uint32_t const uSetFlag = mTxn.getFieldU32 (sfSetFlag);
std::uint32_t const uClearFlag = mTxn.getFieldU32 (sfClearFlag); std::uint32_t const uClearFlag = mTxn.getFieldU32 (sfClearFlag);
if ((uSetFlag != 0) && (uSetFlag == uClearFlag))
{
m_journal.trace << "Malformed transaction: Set and clear same flag";
return temINVALID_FLAG;
}
// legacy AccountSet flags // legacy AccountSet flags
bool bSetRequireDest = (uTxFlags & TxFlag::requireDestTag) || (uSetFlag == asfRequireDest); bool bSetRequireDest = (uTxFlags & TxFlag::requireDestTag) || (uSetFlag == asfRequireDest);
bool bClearRequireDest = (uTxFlags & tfOptionalDestTag) || (uClearFlag == asfRequireDest); bool bClearRequireDest = (uTxFlags & tfOptionalDestTag) || (uClearFlag == asfRequireDest);
@@ -141,6 +147,29 @@ TER SetAccount::doApply ()
uFlagsOut &= ~lsfDisableMaster; uFlagsOut &= ~lsfDisableMaster;
} }
if ((uSetFlag == asfNoFreeze) && (uClearFlag != asfNoFreeze))
{
m_journal.trace << "Set NoFreeze flag";
uFlagsOut |= lsfNoFreeze;
}
// Anyone may set global freeze
if ((uSetFlag == asfGlobalFreeze) && (uClearFlag != asfGlobalFreeze))
{
m_journal.trace << "Set GlobalFreeze flag";
uFlagsOut |= lsfGlobalFreeze;
}
// If you have set NoFreeze, you may not clear GlobalFreeze
// This prevents those who have set NoFreeze from using
// GlobalFreeze strategically.
if ((uSetFlag != asfGlobalFreeze) && (uClearFlag == asfGlobalFreeze) &&
((uFlagsOut & lsfNoFreeze) == 0))
{
m_journal.trace << "Clear GlobalFreeze flag";
uFlagsOut &= ~lsfGlobalFreeze;
}
// //
// Track transaction IDs signed by this account in its root // Track transaction IDs signed by this account in its root
// //

View File

@@ -57,6 +57,8 @@ TER SetTrust::doApply ()
bool const bSetAuth = (uTxFlags & tfSetfAuth); bool const bSetAuth = (uTxFlags & tfSetfAuth);
bool const bSetNoRipple = (uTxFlags & tfSetNoRipple); bool const bSetNoRipple = (uTxFlags & tfSetNoRipple);
bool const bClearNoRipple = (uTxFlags & tfClearNoRipple); bool const bClearNoRipple = (uTxFlags & tfClearNoRipple);
bool const bSetFreeze = (uTxFlags & tfSetFreeze);
bool const bClearFreeze = (uTxFlags & tfClearFreeze);
if (bSetAuth && !(mTxnAccount->getFieldU32 (sfFlags) & lsfRequireAuth)) if (bSetAuth && !(mTxnAccount->getFieldU32 (sfFlags) & lsfRequireAuth))
{ {
@@ -242,6 +244,15 @@ TER SetTrust::doApply ()
uFlagsOut &= ~(bHigh ? lsfHighNoRipple : lsfLowNoRipple); uFlagsOut &= ~(bHigh ? lsfHighNoRipple : lsfLowNoRipple);
} }
if (bSetFreeze && !bClearFreeze && !mTxnAccount->isFlag (lsfNoFreeze))
{
uFlagsOut |= (bHigh ? lsfHighFreeze : lsfLowFreeze);
}
else if (bClearFreeze && !bSetFreeze)
{
uFlagsOut &= ~(bHigh ? lsfHighFreeze : lsfLowFreeze);
}
if (QUALITY_ONE == uLowQualityOut) uLowQualityOut = 0; if (QUALITY_ONE == uLowQualityOut) uLowQualityOut = 0;
if (QUALITY_ONE == uHighQualityOut) uHighQualityOut = 0; if (QUALITY_ONE == uHighQualityOut) uHighQualityOut = 0;
@@ -249,11 +260,13 @@ TER SetTrust::doApply ()
bool const bLowReserveSet = uLowQualityIn || uLowQualityOut || bool const bLowReserveSet = uLowQualityIn || uLowQualityOut ||
(uFlagsOut & lsfLowNoRipple) || (uFlagsOut & lsfLowNoRipple) ||
(uFlagsOut & lsfLowFreeze) ||
!!saLowLimit || saLowBalance > zero; !!saLowLimit || saLowBalance > zero;
bool const bLowReserveClear = !bLowReserveSet; bool const bLowReserveClear = !bLowReserveSet;
bool const bHighReserveSet = uHighQualityIn || uHighQualityOut || bool const bHighReserveSet = uHighQualityIn || uHighQualityOut ||
(uFlagsOut & lsfHighNoRipple) || (uFlagsOut & lsfHighNoRipple) ||
(uFlagsOut & lsfHighFreeze) ||
!!saHighLimit || saHighBalance > zero; !!saHighLimit || saHighBalance > zero;
bool const bHighReserveClear = !bHighReserveSet; bool const bHighReserveClear = !bHighReserveSet;
@@ -375,6 +388,7 @@ TER SetTrust::doApply ()
mTxnAccount, mTxnAccount,
bSetAuth, bSetAuth,
bSetNoRipple && !bClearNoRipple, bSetNoRipple && !bClearNoRipple,
bSetFreeze && !bClearFreeze,
saBalance, saBalance,
saLimitAllow, // Limit for who is being charged. saLimitAllow, // Limit for who is being charged.
uQualityIn, uQualityIn,

View File

@@ -102,6 +102,8 @@ enum LedgerSpecificFlags
lsfRequireAuth = 0x00040000, // True, to require a authorization to hold IOUs. lsfRequireAuth = 0x00040000, // True, to require a authorization to hold IOUs.
lsfDisallowXRP = 0x00080000, // True, to disallow sending XRP. lsfDisallowXRP = 0x00080000, // True, to disallow sending XRP.
lsfDisableMaster = 0x00100000, // True, force regular key lsfDisableMaster = 0x00100000, // True, force regular key
lsfNoFreeze = 0x00200000, // True, cannot freeze ripple states
lsfGlobalFreeze = 0x00400000, // True, all assets frozen
// ltOFFER // ltOFFER
lsfPassive = 0x00010000, lsfPassive = 0x00010000,
@@ -114,6 +116,8 @@ enum LedgerSpecificFlags
lsfHighAuth = 0x00080000, lsfHighAuth = 0x00080000,
lsfLowNoRipple = 0x00100000, lsfLowNoRipple = 0x00100000,
lsfHighNoRipple = 0x00200000, lsfHighNoRipple = 0x00200000,
lsfLowFreeze = 0x00400000, // True, low side has set freeze flag
lsfHighFreeze = 0x00800000, // True, high side has set freeze flag
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@@ -63,6 +63,8 @@ const std::uint32_t asfRequireAuth = 2;
const std::uint32_t asfDisallowXRP = 3; const std::uint32_t asfDisallowXRP = 3;
const std::uint32_t asfDisableMaster = 4; const std::uint32_t asfDisableMaster = 4;
const std::uint32_t asfAccountTxnID = 5; const std::uint32_t asfAccountTxnID = 5;
const std::uint32_t asfNoFreeze = 6;
const std::uint32_t asfGlobalFreeze = 7;
// OfferCreate flags: // OfferCreate flags:
const std::uint32_t tfPassive = 0x00010000; const std::uint32_t tfPassive = 0x00010000;
@@ -81,7 +83,10 @@ const std::uint32_t tfPaymentMask = ~ (tfUniversal | tfPartialPayment |
const std::uint32_t tfSetfAuth = 0x00010000; const std::uint32_t tfSetfAuth = 0x00010000;
const std::uint32_t tfSetNoRipple = 0x00020000; const std::uint32_t tfSetNoRipple = 0x00020000;
const std::uint32_t tfClearNoRipple = 0x00040000; const std::uint32_t tfClearNoRipple = 0x00040000;
const std::uint32_t tfTrustSetMask = ~ (tfUniversal | tfSetfAuth | tfSetNoRipple | tfClearNoRipple); const std::uint32_t tfSetFreeze = 0x00100000;
const std::uint32_t tfClearFreeze = 0x00200000;
const std::uint32_t tfTrustSetMask = ~ (tfUniversal | tfSetfAuth | tfSetNoRipple | tfClearNoRipple
| tfSetFreeze | tfClearFreeze);
} // ripple } // ripple

View File

@@ -106,6 +106,10 @@ Json::Value doAccountLines (RPC::Context& context)
jPeer[jss::no_ripple] = true; jPeer[jss::no_ripple] = true;
if (line->getNoRipplePeer()) if (line->getNoRipplePeer())
jPeer[jss::no_ripple_peer] = true; jPeer[jss::no_ripple_peer] = true;
if (line->getFreeze())
jPeer[jss::freeze] = true;
if (line->getFreezePeer())
jPeer[jss::freeze_peer] = true;
} }
} }