From a95d4ad6cadbe481a1a2b0752a5f1e38f0c7902c Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Thu, 23 Jan 2025 13:35:13 -0500 Subject: [PATCH 1/2] Fix cahce bug introduced in 2.0.1 Partially chery-picked from https://github.com/XRPLF/rippled/commit/f419c18056889c857dbfa1f9a97c8ca4779ffa7d --- src/ripple/ledger/impl/CachedView.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/ripple/ledger/impl/CachedView.cpp b/src/ripple/ledger/impl/CachedView.cpp index 210031346..587d50abf 100644 --- a/src/ripple/ledger/impl/CachedView.cpp +++ b/src/ripple/ledger/impl/CachedView.cpp @@ -63,20 +63,17 @@ CachedViewImpl::read(Keylet const& k) const hits.increment(); else misses.increment(); - std::lock_guard lock(mutex_); - auto const er = map_.emplace(k.key, *digest); - bool const inserted = er.second; - if (sle && !k.check(*sle)) + + if (!cacheHit) { - if (!inserted) - { - // On entry, this function did not find this key in map_. Now - // something (another thread?) has inserted the sle into the map and - // it has the wrong type. - LogicError("CachedView::read: wrong type"); - } - return nullptr; + // Avoid acquiring this lock unless necessary. It is only necessary if + // the key was not found in the map_. The lock is needed to add the key + // and digest. + std::lock_guard lock(mutex_); + map_.emplace(k.key, *digest); } + if (!sle || !k.check(*sle)) + return nullptr; return sle; } From 5ba9e871c56dc26aca52f9db629d703b2f2c0ade Mon Sep 17 00:00:00 2001 From: tequ Date: Wed, 23 Apr 2025 11:32:35 +0900 Subject: [PATCH 2/2] bad merge: RPCCall_test, Transaction_test --- src/test/rpc/RPCCall_test.cpp | 6 ++++-- src/test/rpc/Transaction_test.cpp | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/test/rpc/RPCCall_test.cpp b/src/test/rpc/RPCCall_test.cpp index a5d6ca747..28e7b5bc7 100644 --- a/src/test/rpc/RPCCall_test.cpp +++ b/src/test/rpc/RPCCall_test.cpp @@ -1965,7 +1965,7 @@ static RPCCallTestData const rpcCallTestArray[] = { "method" : "channel_authorize", "params" : [ { - "api_version" : %MAX_API_VER%, + "api_version" : %API_VER%, "amount" : { "currency" : "USD", "issuer" : "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA", @@ -2151,7 +2151,7 @@ static RPCCallTestData const rpcCallTestArray[] = { "method" : "channel_verify", "params" : [ { - "api_version" : %MAX_API_VER%, + "api_version" : %API_VER%, "amount" : { "currency" : "USD", "issuer" : "rnUy2SHTrB9DubsPmkJZUXTf5FcNDGrYEA", @@ -6257,6 +6257,8 @@ public: } else { + printf("got: %s\n", got.toStyledString().c_str()); + printf("exp: %s\n", exp.toStyledString().c_str()); fail(rpcCallTest.description, __FILE__, rpcCallTest.line); } } diff --git a/src/test/rpc/Transaction_test.cpp b/src/test/rpc/Transaction_test.cpp index fe077bfd0..608aace6a 100644 --- a/src/test/rpc/Transaction_test.cpp +++ b/src/test/rpc/Transaction_test.cpp @@ -821,7 +821,7 @@ class Transaction_test : public beast::unit_test::suite std::shared_ptr const txn = env.tx(); BEAST_EXPECT( to_string(txn->getTransactionID()) == - "3F8BDE5A5F82C4F4708E5E9255B713E303E6E1A371FD5C7A704AFD1387C23981"); + "93334A06F509A0E04E908F2E9BA3BD1A00C7B11A91D5EAF20BEF25CE36FCC358"); env.close(); std::shared_ptr meta = env.closed()->txRead(txn->getTransactionID()).second; @@ -855,8 +855,8 @@ class Transaction_test : public beast::unit_test::suite result[jss::result][jss::meta_blob] == expected_meta_blob); BEAST_EXPECT( result[jss::result][jss::ledger_hash] == - "2D5150E5A5AA436736A732291E437ABF01BC9E206C2DF3C77C4F856915" - "7905AA"); + "BC720494ECE70EF8EF078043E71845D9BAC4D1C079181127AF309CC72B" + "ABB1EA"); BEAST_EXPECT( result[jss::result][jss::close_time_iso] == "2000-01-01T00:00:10Z");