From 88f885f2e710d6fa157306e79f73df7289140c55 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 7 Sep 2015 08:57:02 -0700 Subject: [PATCH] Limit changed node count --- src/ripple/app/tx/impl/Transactor.cpp | 6 +++++- src/ripple/ledger/ApplyView.h | 6 ++++++ src/ripple/ledger/ApplyViewImpl.h | 5 +++++ src/ripple/ledger/detail/ApplyStateTable.h | 3 +++ src/ripple/ledger/detail/ApplyViewBase.h | 3 +++ src/ripple/ledger/impl/ApplyStateTable.cpp | 19 +++++++++++++++++++ src/ripple/ledger/impl/ApplyViewBase.cpp | 7 +++++++ src/ripple/ledger/impl/ApplyViewImpl.cpp | 6 ++++++ src/ripple/protocol/TER.h | 1 + src/ripple/protocol/impl/TER.cpp | 1 + 10 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/ripple/app/tx/impl/Transactor.cpp b/src/ripple/app/tx/impl/Transactor.cpp index cf90758e8..8479a9736 100644 --- a/src/ripple/app/tx/impl/Transactor.cpp +++ b/src/ripple/app/tx/impl/Transactor.cpp @@ -532,7 +532,11 @@ Transactor::operator()() bool didApply = isTesSuccess (terResult); auto fee = tx().getTransactionFee (); - if (isTecClaim (terResult) && !(view().flags() & tapRETRY)) + if (view().size() > 5200) + terResult = tecOVERSIZE; + + if ((terResult == tecOVERSIZE) || + (isTecClaim (terResult) && !(view().flags() & tapRETRY))) { // only claim the transaction fee JLOG(j_.debug) << diff --git a/src/ripple/ledger/ApplyView.h b/src/ripple/ledger/ApplyView.h index 0d96b1e9d..9b85de26a 100644 --- a/src/ripple/ledger/ApplyView.h +++ b/src/ripple/ledger/ApplyView.h @@ -196,6 +196,12 @@ public: void update (std::shared_ptr const& sle) = 0; + /** Get the number of modified entries + */ + virtual + std::size_t + size () = 0; + //-------------------------------------------------------------------------- // Called when a credit is made to an account diff --git a/src/ripple/ledger/ApplyViewImpl.h b/src/ripple/ledger/ApplyViewImpl.h index 5786f9cba..c9883e521 100644 --- a/src/ripple/ledger/ApplyViewImpl.h +++ b/src/ripple/ledger/ApplyViewImpl.h @@ -80,6 +80,11 @@ public: deliver_ = amount; } + /** Get the number of modified entries + */ + std::size_t + size (); + private: boost::optional deliver_; }; diff --git a/src/ripple/ledger/detail/ApplyStateTable.h b/src/ripple/ledger/detail/ApplyStateTable.h index d0aea9cf3..e621d812c 100644 --- a/src/ripple/ledger/detail/ApplyStateTable.h +++ b/src/ripple/ledger/detail/ApplyStateTable.h @@ -94,6 +94,9 @@ public: peek (ReadView const& base, Keylet const& k); + std::size_t + size (); + void erase (ReadView const& base, std::shared_ptr const& sle); diff --git a/src/ripple/ledger/detail/ApplyViewBase.h b/src/ripple/ledger/detail/ApplyViewBase.h index afd565d1e..2fa6d54dc 100644 --- a/src/ripple/ledger/detail/ApplyViewBase.h +++ b/src/ripple/ledger/detail/ApplyViewBase.h @@ -132,6 +132,9 @@ public: rawDestroyXRP ( std::uint64_t feeDrops) override; + std::size_t + size () override; + protected: ApplyFlags flags_; ReadView const* base_; diff --git a/src/ripple/ledger/impl/ApplyStateTable.cpp b/src/ripple/ledger/impl/ApplyStateTable.cpp index 4d5ab9b29..3f3e934fd 100644 --- a/src/ripple/ledger/impl/ApplyStateTable.cpp +++ b/src/ripple/ledger/impl/ApplyStateTable.cpp @@ -53,6 +53,25 @@ ApplyStateTable::apply (RawView& to) const } } +std::size_t +ApplyStateTable::size () +{ + std::size_t ret = 0; + for (auto& item : items_) + { + switch (item.second.first) + { + case Action::erase: + case Action::insert: + case Action::modify: + ++ret; + default: + break; + } + } + return ret; +} + void ApplyStateTable::apply (OpenView& to, STTx const& tx, TER ter, diff --git a/src/ripple/ledger/impl/ApplyViewBase.cpp b/src/ripple/ledger/impl/ApplyViewBase.cpp index 22491d4ca..da5818086 100644 --- a/src/ripple/ledger/impl/ApplyViewBase.cpp +++ b/src/ripple/ledger/impl/ApplyViewBase.cpp @@ -148,6 +148,13 @@ ApplyViewBase::update( items_.update(*base_, sle); } +std::size_t +ApplyViewBase::size () +{ + return items_.size (); +} + + //--- void diff --git a/src/ripple/ledger/impl/ApplyViewImpl.cpp b/src/ripple/ledger/impl/ApplyViewImpl.cpp index 6d2634f98..3a1603cdb 100644 --- a/src/ripple/ledger/impl/ApplyViewImpl.cpp +++ b/src/ripple/ledger/impl/ApplyViewImpl.cpp @@ -38,4 +38,10 @@ ApplyViewImpl::apply (OpenView& to, items_.apply(to, tx, ter, deliver_, j); } +std::size_t +ApplyViewImpl::size () +{ + return items_.size (); +} + } // ripple diff --git a/src/ripple/protocol/TER.h b/src/ripple/protocol/TER.h index 3a0da87fa..a1e0e402a 100644 --- a/src/ripple/protocol/TER.h +++ b/src/ripple/protocol/TER.h @@ -200,6 +200,7 @@ enum TER tecNEED_MASTER_KEY = 142, tecDST_TAG_NEEDED = 143, tecINTERNAL = 144, + tecOVERSIZE = 145, }; inline bool isTelLocal(TER x) diff --git a/src/ripple/protocol/impl/TER.cpp b/src/ripple/protocol/impl/TER.cpp index 54df2f5b5..a2f2d0508 100644 --- a/src/ripple/protocol/impl/TER.cpp +++ b/src/ripple/protocol/impl/TER.cpp @@ -50,6 +50,7 @@ bool transResultInfo (TER code, std::string& token, std::string& text) { tecPATH_PARTIAL, "tecPATH_PARTIAL", "Path could not send full amount." }, { tecNO_ALTERNATIVE_KEY, "tecNO_ALTERNATIVE_KEY", "The operation would remove the last way to sign a transaction."}, { tecNO_REGULAR_KEY, "tecNO_REGULAR_KEY", "Regular key is not set." }, + { tecOVERSIZE, "tecOVERSIZE", "Object exceeded serialization limits." }, { tecUNFUNDED, "tecUNFUNDED", "One of _ADD, _OFFER, or _SEND. Deprecated." }, { tecUNFUNDED_ADD, "tecUNFUNDED_ADD", "Insufficient XRP balance for WalletAdd." },