mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Remove unfunded offers on tecOVERSIZE
This commit is contained in:
@@ -52,4 +52,19 @@ ApplyContext::apply(TER ter)
|
|||||||
view_->apply(base_, tx, ter, journal);
|
view_->apply(base_, tx, ter, journal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::size_t
|
||||||
|
ApplyContext::size()
|
||||||
|
{
|
||||||
|
return view_->size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ApplyContext::visit (std::function <void (
|
||||||
|
uint256 const&, bool,
|
||||||
|
std::shared_ptr<SLE const> const&,
|
||||||
|
std::shared_ptr<SLE const> const&)> const& func)
|
||||||
|
{
|
||||||
|
view_->visit(base_, func);
|
||||||
|
}
|
||||||
|
|
||||||
} // ripple
|
} // ripple
|
||||||
|
|||||||
@@ -79,6 +79,18 @@ public:
|
|||||||
void
|
void
|
||||||
apply (TER);
|
apply (TER);
|
||||||
|
|
||||||
|
/** Get the number of unapplied changes. */
|
||||||
|
std::size_t
|
||||||
|
size ();
|
||||||
|
|
||||||
|
/** Visit unapplied changes. */
|
||||||
|
void
|
||||||
|
visit (std::function <void (
|
||||||
|
uint256 const& key,
|
||||||
|
bool isDelete,
|
||||||
|
std::shared_ptr <SLE const> const& before,
|
||||||
|
std::shared_ptr <SLE const> const& after)> const& func);
|
||||||
|
|
||||||
void
|
void
|
||||||
destroyXRP (std::uint64_t feeDrops)
|
destroyXRP (std::uint64_t feeDrops)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <ripple/core/Config.h>
|
#include <ripple/core/Config.h>
|
||||||
#include <ripple/core/LoadFeeTrack.h>
|
#include <ripple/core/LoadFeeTrack.h>
|
||||||
#include <ripple/json/to_string.h>
|
#include <ripple/json/to_string.h>
|
||||||
|
#include <ripple/ledger/View.h>
|
||||||
#include <ripple/protocol/Feature.h>
|
#include <ripple/protocol/Feature.h>
|
||||||
#include <ripple/protocol/Indexes.h>
|
#include <ripple/protocol/Indexes.h>
|
||||||
#include <ripple/protocol/types.h>
|
#include <ripple/protocol/types.h>
|
||||||
@@ -454,6 +455,25 @@ TER Transactor::checkMultiSign ()
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void removeUnfundedOffers (ApplyView& view, std::vector<uint256> const& offers)
|
||||||
|
{
|
||||||
|
int removed = 0;
|
||||||
|
|
||||||
|
for (auto const& index : offers)
|
||||||
|
{
|
||||||
|
auto const sleOffer = view.peek (keylet::offer (index));
|
||||||
|
if (sleOffer)
|
||||||
|
{
|
||||||
|
// offer is unfunded
|
||||||
|
offerDelete (view, sleOffer);
|
||||||
|
if (++removed == 1000)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
static
|
static
|
||||||
inline
|
inline
|
||||||
void
|
void
|
||||||
@@ -532,7 +552,7 @@ Transactor::operator()()
|
|||||||
bool didApply = isTesSuccess (terResult);
|
bool didApply = isTesSuccess (terResult);
|
||||||
auto fee = tx().getTransactionFee ();
|
auto fee = tx().getTransactionFee ();
|
||||||
|
|
||||||
if (view().size() > 5200)
|
if (ctx_.size() > 5200)
|
||||||
terResult = tecOVERSIZE;
|
terResult = tecOVERSIZE;
|
||||||
|
|
||||||
if ((terResult == tecOVERSIZE) ||
|
if ((terResult == tecOVERSIZE) ||
|
||||||
@@ -542,6 +562,30 @@ Transactor::operator()()
|
|||||||
JLOG(j_.debug) <<
|
JLOG(j_.debug) <<
|
||||||
"Reprocessing tx " << txID << " to only claim fee";
|
"Reprocessing tx " << txID << " to only claim fee";
|
||||||
|
|
||||||
|
std::vector<uint256> removedOffers;
|
||||||
|
if (terResult == tecOVERSIZE)
|
||||||
|
{
|
||||||
|
ctx_.visit (
|
||||||
|
[&removedOffers](
|
||||||
|
uint256 const& index,
|
||||||
|
bool isDelete,
|
||||||
|
std::shared_ptr <SLE const> const& before,
|
||||||
|
std::shared_ptr <SLE const> const& after)
|
||||||
|
{
|
||||||
|
if (isDelete)
|
||||||
|
{
|
||||||
|
assert (before && after);
|
||||||
|
if (before && after &&
|
||||||
|
(before->getType() == ltOFFER) &&
|
||||||
|
(before->getFieldAmount(sfTakerPays) == after->getFieldAmount(sfTakerPays)))
|
||||||
|
{
|
||||||
|
// Removal of offer found or made unfunded
|
||||||
|
removedOffers.push_back (index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ctx_.discard();
|
ctx_.discard();
|
||||||
|
|
||||||
auto const txnAcct = view().peek(
|
auto const txnAcct = view().peek(
|
||||||
@@ -575,6 +619,10 @@ Transactor::operator()()
|
|||||||
fee = balance;
|
fee = balance;
|
||||||
txnAcct->setFieldAmount (sfBalance, balance - fee);
|
txnAcct->setFieldAmount (sfBalance, balance - fee);
|
||||||
txnAcct->setFieldU32 (sfSequence, t_seq + 1);
|
txnAcct->setFieldU32 (sfSequence, t_seq + 1);
|
||||||
|
|
||||||
|
if (terResult == tecOVERSIZE)
|
||||||
|
removeUnfundedOffers (view(), removedOffers);
|
||||||
|
|
||||||
view().update (txnAcct);
|
view().update (txnAcct);
|
||||||
didApply = true;
|
didApply = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,12 +196,6 @@ public:
|
|||||||
void
|
void
|
||||||
update (std::shared_ptr<SLE> const& sle) = 0;
|
update (std::shared_ptr<SLE> const& sle) = 0;
|
||||||
|
|
||||||
/** Get the number of modified entries
|
|
||||||
*/
|
|
||||||
virtual
|
|
||||||
std::size_t
|
|
||||||
size () = 0;
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
// Called when a credit is made to an account
|
// Called when a credit is made to an account
|
||||||
|
|||||||
@@ -85,6 +85,16 @@ public:
|
|||||||
std::size_t
|
std::size_t
|
||||||
size ();
|
size ();
|
||||||
|
|
||||||
|
/** Visit modified entries
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
visit (
|
||||||
|
OpenView& target,
|
||||||
|
std::function <void (
|
||||||
|
uint256 const& key,
|
||||||
|
bool isDelete,
|
||||||
|
std::shared_ptr <SLE const> const& before,
|
||||||
|
std::shared_ptr <SLE const> const& after)> const& func);
|
||||||
private:
|
private:
|
||||||
boost::optional<STAmount> deliver_;
|
boost::optional<STAmount> deliver_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -97,6 +97,14 @@ public:
|
|||||||
std::size_t
|
std::size_t
|
||||||
size ();
|
size ();
|
||||||
|
|
||||||
|
void
|
||||||
|
visit (ReadView const& base,
|
||||||
|
std::function <void (
|
||||||
|
uint256 const& key,
|
||||||
|
bool isDelete,
|
||||||
|
std::shared_ptr <SLE const> const& before,
|
||||||
|
std::shared_ptr <SLE const> const& after)> const& func);
|
||||||
|
|
||||||
void
|
void
|
||||||
erase (ReadView const& base,
|
erase (ReadView const& base,
|
||||||
std::shared_ptr<SLE> const& sle);
|
std::shared_ptr<SLE> const& sle);
|
||||||
|
|||||||
@@ -132,9 +132,6 @@ public:
|
|||||||
rawDestroyXRP (
|
rawDestroyXRP (
|
||||||
std::uint64_t feeDrops) override;
|
std::uint64_t feeDrops) override;
|
||||||
|
|
||||||
std::size_t
|
|
||||||
size () override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ApplyFlags flags_;
|
ApplyFlags flags_;
|
||||||
ReadView const* base_;
|
ReadView const* base_;
|
||||||
|
|||||||
@@ -72,6 +72,39 @@ ApplyStateTable::size ()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ApplyStateTable::visit (ReadView const& to,
|
||||||
|
std::function <void (
|
||||||
|
uint256 const& key,
|
||||||
|
bool isDelete,
|
||||||
|
std::shared_ptr <SLE const> const& before,
|
||||||
|
std::shared_ptr <SLE const> const& after)> const& func)
|
||||||
|
{
|
||||||
|
for (auto& item : items_)
|
||||||
|
{
|
||||||
|
switch (item.second.first)
|
||||||
|
{
|
||||||
|
case Action::erase:
|
||||||
|
func (item.first, true,
|
||||||
|
to.read (keylet::unchecked (item.first)), item.second.second);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Action::insert:
|
||||||
|
func (item.first, false,
|
||||||
|
nullptr, item.second.second);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Action::modify:
|
||||||
|
func (item.first, false,
|
||||||
|
to.read (keylet::unchecked (item.first)), item.second.second);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ApplyStateTable::apply (OpenView& to,
|
ApplyStateTable::apply (OpenView& to,
|
||||||
STTx const& tx, TER ter,
|
STTx const& tx, TER ter,
|
||||||
|
|||||||
@@ -148,13 +148,6 @@ ApplyViewBase::update(
|
|||||||
items_.update(*base_, sle);
|
items_.update(*base_, sle);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t
|
|
||||||
ApplyViewBase::size ()
|
|
||||||
{
|
|
||||||
return items_.size ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//---
|
//---
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -44,4 +44,16 @@ ApplyViewImpl::size ()
|
|||||||
return items_.size ();
|
return items_.size ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ApplyViewImpl::visit (
|
||||||
|
OpenView& to,
|
||||||
|
std::function <void (
|
||||||
|
uint256 const& key,
|
||||||
|
bool isDelete,
|
||||||
|
std::shared_ptr <SLE const> const& before,
|
||||||
|
std::shared_ptr <SLE const> const& after)> const& func)
|
||||||
|
{
|
||||||
|
items_.visit (to, func);
|
||||||
|
}
|
||||||
|
|
||||||
} // ripple
|
} // ripple
|
||||||
|
|||||||
Reference in New Issue
Block a user