mirror of
https://github.com/Xahau/xahaud.git
synced 2026-06-27 12:36:37 +00:00
Compare commits
1 Commits
server-def
...
amm-suppor
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
630fd33e6f |
@@ -95,16 +95,8 @@ if [[ "$4" == "" ]]; then
|
||||
echo "Non GH, local building, no Action runner magic"
|
||||
else
|
||||
# GH Action, runner
|
||||
if [[ "$(git rev-parse --abbrev-ref HEAD)" == "release" ]]; then
|
||||
echo "building on the release branch... placing it in builds/candidate"
|
||||
mkdir /data/builds/candidate
|
||||
cp /io/release-build/xahaud /data/builds/candidate/$(date +%Y).$(date +%-m).$(date +%-d)-$(git rev-parse --abbrev-ref HEAD)+$4
|
||||
cp /io/release-build/release.info /data/builds/candidate/$(date +%Y).$(date +%-m).$(date +%-d)-$(git rev-parse --abbrev-ref HEAD)+$4.releaseinfo
|
||||
else
|
||||
echo "building non-release branch, placing it in builds root"
|
||||
cp /io/release-build/xahaud /data/builds/$(date +%Y).$(date +%-m).$(date +%-d)-$(git rev-parse --abbrev-ref HEAD)+$4
|
||||
cp /io/release-build/release.info /data/builds/$(date +%Y).$(date +%-m).$(date +%-d)-$(git rev-parse --abbrev-ref HEAD)+$4.releaseinfo
|
||||
fi
|
||||
cp /io/release-build/xahaud /data/builds/$(date +%Y).$(date +%-m).$(date +%-d)-$(git rev-parse --abbrev-ref HEAD)+$4
|
||||
cp /io/release-build/release.info /data/builds/$(date +%Y).$(date +%-m).$(date +%-d)-$(git rev-parse --abbrev-ref HEAD)+$4.releaseinfo
|
||||
echo "Published build to: http://build.xahau.tech/"
|
||||
echo $(date +%Y).$(date +%-m).$(date +%-d)-$(git rev-parse --abbrev-ref HEAD)+$4
|
||||
fi
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
// If you add an amendment here, then do not forget to increment `numFeatures`
|
||||
// in include/xrpl/protocol/Feature.h.
|
||||
|
||||
XRPL_FIX (HookMap, Supported::yes, VoteBehavior::DefaultYes)
|
||||
XRPL_FIX (GuardDepth32, Supported::yes, VoteBehavior::DefaultNo)
|
||||
XRPL_FEATURE(NamedHooks, Supported::yes, VoteBehavior::DefaultNo)
|
||||
XRPL_FEATURE(IOURewardClaim, Supported::yes, VoteBehavior::DefaultNo)
|
||||
|
||||
@@ -93,7 +93,7 @@ LEDGER_ENTRY(ltCHECK, 0x0043, Check, check, ({
|
||||
*/
|
||||
LEDGER_ENTRY(ltHOOK_DEFINITION, 'D', HookDefinition, hook_definition, ({
|
||||
{sfHookHash, soeREQUIRED},
|
||||
{sfHookOn, soeOPTIONAL},
|
||||
{sfHookOn, soeREQUIRED},
|
||||
{sfHookOnIncoming, soeOPTIONAL},
|
||||
{sfHookOnOutgoing, soeOPTIONAL},
|
||||
{sfHookCanEmit, soeOPTIONAL},
|
||||
|
||||
@@ -293,8 +293,6 @@ JSS(effective); // out: ValidatorList
|
||||
// in: UNL
|
||||
JSS(elapsed_seconds);
|
||||
JSS(enabled); // out: AmendmentTable
|
||||
JSS(ledger_enabled); // out: ServerDefinitions (amendment on-ledger)
|
||||
JSS(cfg_forced); // out: ServerDefinitions ([features] config stanza)
|
||||
JSS(engine_result); // out: NetworkOPs, TransactionSign, Submit
|
||||
JSS(engine_result_code); // out: NetworkOPs, TransactionSign, Submit
|
||||
JSS(engine_result_message); // out: NetworkOPs, TransactionSign, Submit
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx.h>
|
||||
#include <test/jtx/AMM.h>
|
||||
#include <xrpld/app/tx/applySteps.h>
|
||||
#include <xrpld/ledger/Dir.h>
|
||||
#include <xrpl/protocol/Feature.h>
|
||||
@@ -4317,93 +4316,6 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
env.close();
|
||||
}
|
||||
|
||||
void
|
||||
testIOUAMM(FeatureBitset features)
|
||||
{
|
||||
testcase("IOU AMM");
|
||||
using namespace test::jtx;
|
||||
using namespace std::chrono;
|
||||
|
||||
Account alice{"alice"};
|
||||
Account bob{"bob"};
|
||||
Account gw{"gw"};
|
||||
|
||||
auto const USD = gw["USD"];
|
||||
|
||||
// AMMCreate fails - insufficient balance
|
||||
Env env(*this, features | featureAMM | featureAMMClawback);
|
||||
env.fund(XRP(10000), alice, bob, gw);
|
||||
env.close();
|
||||
|
||||
env.trust(USD(100000), alice);
|
||||
env.close();
|
||||
env(pay(gw, alice, USD(1000)));
|
||||
env.close();
|
||||
|
||||
env(escrow(alice, bob, USD(1000)), finish_time(env.now() + 1s));
|
||||
env.close();
|
||||
|
||||
// AMMCreate fails - insufficient balance
|
||||
AMM ammFail(env, alice, XRP(1000), USD(1000), ter(tecUNFUNDED_AMM));
|
||||
|
||||
env(pay(gw, alice, USD(1000)));
|
||||
env.close();
|
||||
|
||||
AMM ammAlice(env, alice, XRP(1000), USD(1000));
|
||||
BEAST_EXPECT(ammAlice.ammExists());
|
||||
|
||||
// Single Asset Deposit fails - insufficient balance
|
||||
ammAlice.deposit(
|
||||
alice,
|
||||
USD(1000),
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
ter(tecUNFUNDED_AMM));
|
||||
|
||||
// Double Asset Deposit fails - insufficient balance
|
||||
ammAlice.deposit(
|
||||
alice,
|
||||
USD(1000),
|
||||
XRP(1000),
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
ter(tecUNFUNDED_AMM));
|
||||
|
||||
auto const lptoken = ammAlice.getLPTokensBalance(alice);
|
||||
// lock all LP tokens
|
||||
env(escrow(alice, bob, STAmount{lptoken, ammAlice.lptIssue()}),
|
||||
finish_time(env.now() + 1s));
|
||||
env.close();
|
||||
|
||||
// Withdraw
|
||||
ammAlice.withdraw(
|
||||
alice, USD(1000), std::nullopt, std::nullopt, ter(tecAMM_BALANCE));
|
||||
ammAlice.withdrawAll(alice, USD(1000), ter(tecAMM_BALANCE));
|
||||
|
||||
env(ammAlice.bid(BidArg{
|
||||
.account = alice,
|
||||
.bidMax = 100,
|
||||
.assets = {{USD, XRP}},
|
||||
}),
|
||||
ter(tecAMM_INVALID_TOKENS));
|
||||
|
||||
ammAlice.vote(
|
||||
alice,
|
||||
1'000,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
{{USD, XRP}},
|
||||
ter(tecAMM_INVALID_TOKENS));
|
||||
|
||||
// Cannot escrow clawbackable tokens, so we cannot ammClawback escrowed
|
||||
// tokens
|
||||
// env(amm::ammClawback(gw, alice, USD, XRP, USD(100)),
|
||||
// ter(tecAMM_BALANCE));
|
||||
// env(amm::ammClawback(gw, alice, USD, XRP, std::nullopt),
|
||||
// ter(tecAMM_BALANCE));
|
||||
}
|
||||
|
||||
static uint256
|
||||
getEscrowIndex(AccountID const& account, std::uint32_t uSequence)
|
||||
{
|
||||
@@ -4817,7 +4729,6 @@ struct Escrow_test : public beast::unit_test::suite
|
||||
testIOUTLINSF(features);
|
||||
testIOUPrecisionLoss(features);
|
||||
testIOUClawback(features);
|
||||
testIOUAMM(features);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -3632,9 +3632,8 @@ public:
|
||||
|
||||
auto const alice = Account{"alice"};
|
||||
auto const bob = Account{"bob"};
|
||||
auto const claire = Account{"claire"};
|
||||
Env env{*this, features};
|
||||
env.fund(XRP(100000), alice, bob, claire);
|
||||
env.fund(XRP(100000), alice, bob);
|
||||
env.close();
|
||||
|
||||
// Compute hook hash for the accept hook
|
||||
@@ -3774,84 +3773,6 @@ public:
|
||||
BEAST_EXPECT(result2.has_value());
|
||||
BEAST_EXPECT(result2.value() == newData.size());
|
||||
}
|
||||
|
||||
{
|
||||
// fixHookMap: foreign state set without grant after state previous
|
||||
// modified
|
||||
|
||||
HookStateMap stateMap;
|
||||
auto hookCtx = makeStubHookContext(
|
||||
applyCtx, alice.id(), bob.id(), {}, stateMap);
|
||||
|
||||
AccountID const aliceid = alice.id();
|
||||
|
||||
// Pre-populate stateMap
|
||||
stateMap[alice.id()] = {
|
||||
100, // availableForReserves
|
||||
1, // namespaceCount
|
||||
1, // hookStateScale
|
||||
{}};
|
||||
|
||||
auto& api = hookCtx.api();
|
||||
|
||||
// setup a hook on alice, and on claire, no grants
|
||||
env(hook(alice, {{hso(genesis::AcceptHook)}}, 0), fee(XRP(1)));
|
||||
env(hook(claire, {{hso(genesis::AcceptHook)}}, 0), fee(XRP(1)));
|
||||
env.close();
|
||||
|
||||
// First modification
|
||||
auto result1 =
|
||||
api.state_foreign_set(testKey, testNs, aliceid, testData);
|
||||
BEAST_EXPECT(result1.has_value());
|
||||
|
||||
// Second modification this time using bob as hookacc (should hit
|
||||
// cache)
|
||||
auto hookCtx2 = makeStubHookContext(
|
||||
applyCtx, claire.id(), bob.id(), {}, stateMap);
|
||||
|
||||
// check the state entry is carried into the second context
|
||||
|
||||
// does the map contain the account?
|
||||
BEAST_EXPECT(
|
||||
hookCtx2.result.stateMap.find(aliceid) !=
|
||||
hookCtx2.result.stateMap.end());
|
||||
|
||||
// the name space?
|
||||
BEAST_EXPECT(
|
||||
std::get<3>(hookCtx2.result.stateMap[aliceid]).find(testNs) !=
|
||||
std::get<3>(hookCtx2.result.stateMap[aliceid]).end());
|
||||
|
||||
// the key entry?
|
||||
BEAST_EXPECT(
|
||||
std::get<3>(hookCtx2.result.stateMap[aliceid])[testNs].find(
|
||||
testKey) !=
|
||||
std::get<3>(hookCtx2.result.stateMap[aliceid])[testNs].end());
|
||||
|
||||
// is the entry marked as modified?
|
||||
BEAST_EXPECT(
|
||||
std::get<3>(hookCtx2.result.stateMap[aliceid])[testNs][testKey]
|
||||
.first);
|
||||
|
||||
auto& api2 = hookCtx2.api();
|
||||
Bytes newData{0x04, 0x05};
|
||||
auto result2 =
|
||||
api2.state_foreign_set(testKey, testNs, aliceid, newData);
|
||||
|
||||
if (features[fixHookMap])
|
||||
{
|
||||
// new behaviour: grant is missing, cannot write
|
||||
BEAST_EXPECT(!result2.has_value());
|
||||
BEAST_EXPECT(result2.error() == NOT_AUTHORIZED);
|
||||
BEAST_EXPECT(hookCtx2.result.foreignStateSetDisabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
// old behaviour: allow this illegal write due to the entry
|
||||
// being modified previously in the map
|
||||
BEAST_EXPECT(result2.has_value());
|
||||
BEAST_EXPECT(result2.value() == newData.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -4911,7 +4832,6 @@ public:
|
||||
|
||||
test_state(features);
|
||||
test_state_foreign(features);
|
||||
test_state_foreign_set(features - fixHookMap);
|
||||
test_state_foreign_set(features);
|
||||
test_state_foreign_set_max(features);
|
||||
test_state_set(features);
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace ripple {
|
||||
namespace test {
|
||||
namespace jtx {
|
||||
|
||||
[[maybe_unused]] static Number
|
||||
static Number
|
||||
number(STAmount const& a)
|
||||
{
|
||||
if (isXRP(a))
|
||||
|
||||
@@ -186,13 +186,10 @@ public:
|
||||
bool expectObsolete =
|
||||
(votes.at(feature[jss::name].asString()) ==
|
||||
VoteBehavior::Obsolete);
|
||||
// "enabled" is now the effective value (ledger_voted || forced);
|
||||
// this default env votes nothing onto the ledger, so assert on the
|
||||
// canonical on-ledger flag.
|
||||
BEAST_EXPECTS(
|
||||
feature.isMember(jss::ledger_enabled) &&
|
||||
!feature[jss::ledger_enabled].asBool(),
|
||||
feature[jss::name].asString() + " ledger_enabled");
|
||||
feature.isMember(jss::enabled) &&
|
||||
!feature[jss::enabled].asBool(),
|
||||
feature[jss::name].asString() + " enabled");
|
||||
BEAST_EXPECTS(
|
||||
feature.isMember(jss::vetoed) &&
|
||||
feature[jss::vetoed].isBool() == !expectObsolete &&
|
||||
@@ -240,12 +237,10 @@ public:
|
||||
bool expectObsolete =
|
||||
(votes.at((*it)[jss::name].asString()) ==
|
||||
VoteBehavior::Obsolete);
|
||||
// expectEnabled reflects the on-ledger amendment table, so compare
|
||||
// against ledger_enabled (enabled is now ledger_voted || forced).
|
||||
BEAST_EXPECTS(
|
||||
(*it).isMember(jss::ledger_enabled) &&
|
||||
(*it)[jss::ledger_enabled].asBool() == expectEnabled,
|
||||
(*it)[jss::name].asString() + " ledger_enabled");
|
||||
(*it).isMember(jss::enabled) &&
|
||||
(*it)[jss::enabled].asBool() == expectEnabled,
|
||||
(*it)[jss::name].asString() + " enabled");
|
||||
if (expectEnabled)
|
||||
BEAST_EXPECTS(
|
||||
!(*it).isMember(jss::vetoed),
|
||||
@@ -365,78 +360,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testConfigForced(FeatureBitset features)
|
||||
{
|
||||
testcase("Config-forced features ([features] stanza)");
|
||||
|
||||
using namespace test::jtx;
|
||||
|
||||
// jtx enables amendments by inserting them into config.features (the
|
||||
// same presets mechanism as the [features] config stanza), so passing
|
||||
// a single-feature bitset gives us exactly one config-forced amendment
|
||||
// and votes nothing onto the ledger. server_definitions must then
|
||||
// report that one as effectively enabled, distinguishing the source:
|
||||
// enabled = ledger_enabled || cfg_forced
|
||||
// ledger_enabled = false (never voted onto the ledger)
|
||||
// cfg_forced = true (forced via config) for the one feature only
|
||||
auto const forced = featurePriceOracle;
|
||||
auto const forcedHex = to_string(forced);
|
||||
|
||||
Env env{*this, FeatureBitset(forced)};
|
||||
|
||||
auto jrr = env.rpc("server_definitions")[jss::result];
|
||||
if (!BEAST_EXPECT(jrr.isMember(jss::features)))
|
||||
return;
|
||||
|
||||
bool sawForced = false;
|
||||
for (auto it = jrr[jss::features].begin();
|
||||
it != jrr[jss::features].end();
|
||||
++it)
|
||||
{
|
||||
auto const& f = *it;
|
||||
auto const name = f[jss::name].asString();
|
||||
|
||||
// every entry now carries the split flags
|
||||
if (!BEAST_EXPECTS(
|
||||
f.isMember(jss::enabled) &&
|
||||
f.isMember(jss::ledger_enabled) &&
|
||||
f.isMember(jss::cfg_forced),
|
||||
name + " split flags"))
|
||||
return;
|
||||
|
||||
// nothing is enabled on-ledger in a fresh env
|
||||
BEAST_EXPECTS(
|
||||
!f[jss::ledger_enabled].asBool(), name + " ledger_enabled");
|
||||
|
||||
if (it.key().asString() == forcedHex)
|
||||
{
|
||||
sawForced = true;
|
||||
BEAST_EXPECTS(
|
||||
f[jss::cfg_forced].asBool(), name + " cfg_forced");
|
||||
// ledger_enabled(false) || cfg_forced(true) == true
|
||||
BEAST_EXPECTS(f[jss::enabled].asBool(), name + " enabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
BEAST_EXPECTS(
|
||||
!f[jss::cfg_forced].asBool(), name + " cfg_forced");
|
||||
// not forced and not on-ledger => not effectively enabled
|
||||
BEAST_EXPECTS(
|
||||
f[jss::enabled].asBool() == f[jss::ledger_enabled].asBool(),
|
||||
name + " enabled==ledger_enabled");
|
||||
}
|
||||
}
|
||||
BEAST_EXPECT(sawForced);
|
||||
}
|
||||
|
||||
void
|
||||
testServerFeatures(FeatureBitset features)
|
||||
{
|
||||
testNoParams(features);
|
||||
testSomeEnabled(features);
|
||||
testWithMajorities(features);
|
||||
testConfigForced(features);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <queue>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <wasmedge/wasmedge.h>
|
||||
|
||||
@@ -175,8 +174,6 @@ struct HookResult
|
||||
false; // hook_again allows strong pre-apply to nominate
|
||||
// additional weak post-apply execution
|
||||
std::shared_ptr<STObject const> provisionalMeta;
|
||||
std::set<std::pair<AccountID, uint256 /* namespace */>>
|
||||
foreignStateGrantCache; // add found grants here to avoid rechecking
|
||||
};
|
||||
|
||||
class HookExecutor;
|
||||
|
||||
@@ -1920,114 +1920,88 @@ HookAPI::state_foreign_set(
|
||||
if (hookCtx.result.foreignStateSetDisabled)
|
||||
return Unexpected(PREVIOUS_FAILURE_PREVENTS_RETRY);
|
||||
|
||||
bool const hasFix = hookCtx.applyCtx.view().rules().enabled(fixHookMap);
|
||||
|
||||
if (!hasFix)
|
||||
// first check if we've already modified this state
|
||||
auto cacheEntry = lookup_state_cache(account, ns, key);
|
||||
if (cacheEntry && cacheEntry->get().first)
|
||||
{
|
||||
// first check if we've already modified this state
|
||||
auto cacheEntry = lookup_state_cache(account, ns, key);
|
||||
if (cacheEntry && cacheEntry->get().first)
|
||||
{
|
||||
// if a cache entry already exists and it has already been modified
|
||||
// don't check grants again
|
||||
if (auto ret = set_state_cache(account, ns, key, data, true);
|
||||
!ret.has_value())
|
||||
return Unexpected(ret.error());
|
||||
// if a cache entry already exists and it has already been modified
|
||||
// don't check grants again
|
||||
if (auto ret = set_state_cache(account, ns, key, data, true);
|
||||
!ret.has_value())
|
||||
return Unexpected(ret.error());
|
||||
|
||||
return data.size();
|
||||
}
|
||||
return data.size();
|
||||
}
|
||||
// check if we've used a grant to modify this state entry before, if not
|
||||
// look up possible grants
|
||||
if (!hasFix ||
|
||||
hookCtx.result.foreignStateGrantCache.find({account, ns}) ==
|
||||
hookCtx.result.foreignStateGrantCache.end())
|
||||
|
||||
// cache miss or cache was present but entry was not marked as previously
|
||||
// modified therefore before continuing we need to check grants
|
||||
auto const sle =
|
||||
hookCtx.applyCtx.view().read(ripple::keylet::hook(account));
|
||||
if (!sle)
|
||||
return Unexpected(INTERNAL_ERROR);
|
||||
|
||||
bool found_auth = false;
|
||||
|
||||
// we do this by iterating the hooks installed on the foreign account and in
|
||||
// turn their grants and namespaces
|
||||
auto const& hooks = sle->getFieldArray(sfHooks);
|
||||
for (auto const& hookObj : hooks)
|
||||
{
|
||||
auto const sle =
|
||||
hookCtx.applyCtx.view().read(ripple::keylet::hook(account));
|
||||
// skip blank entries
|
||||
if (!hookObj.isFieldPresent(sfHookHash))
|
||||
continue;
|
||||
|
||||
if (!sle)
|
||||
if (!hookObj.isFieldPresent(sfHookGrants))
|
||||
continue;
|
||||
|
||||
auto const& hookGrants = hookObj.getFieldArray(sfHookGrants);
|
||||
|
||||
if (hookGrants.size() < 1)
|
||||
continue;
|
||||
|
||||
// the grant allows the hook to modify the granter's namespace only
|
||||
if (hookObj.isFieldPresent(sfHookNamespace))
|
||||
{
|
||||
if (hasFix)
|
||||
{
|
||||
hookCtx.result.foreignStateSetDisabled = true;
|
||||
return Unexpected(NOT_AUTHORIZED);
|
||||
}
|
||||
|
||||
return Unexpected(INTERNAL_ERROR);
|
||||
if (hookObj.getFieldH256(sfHookNamespace) != ns)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// fetch the hook definition
|
||||
auto const def =
|
||||
hookCtx.applyCtx.view().read(ripple::keylet::hookDefinition(
|
||||
hookObj.getFieldH256(sfHookHash)));
|
||||
if (!def) // should never happen except in a rare race condition
|
||||
continue;
|
||||
if (def->getFieldH256(sfHookNamespace) != ns)
|
||||
continue;
|
||||
}
|
||||
|
||||
// RH TODO: test this code path more completely
|
||||
|
||||
bool found_auth = false;
|
||||
|
||||
// we do this by iterating the hooks installed on the foreign account
|
||||
// and in turn their grants and namespaces
|
||||
auto const& hooks = sle->getFieldArray(sfHooks);
|
||||
for (auto const& hookObj : hooks)
|
||||
// this is expensive search so we'll disallow after one failed attempt
|
||||
for (auto const& hookGrantObj : hookGrants)
|
||||
{
|
||||
// skip blank entries
|
||||
if (!hookObj.isFieldPresent(sfHookHash))
|
||||
continue;
|
||||
bool hasAuthorizedField = hookGrantObj.isFieldPresent(sfAuthorize);
|
||||
|
||||
if (!hookObj.isFieldPresent(sfHookGrants))
|
||||
continue;
|
||||
|
||||
auto const& hookGrants = hookObj.getFieldArray(sfHookGrants);
|
||||
|
||||
if (hookGrants.size() < 1)
|
||||
continue;
|
||||
|
||||
// the grant allows the hook to modify the granter's namespace only
|
||||
if (hookObj.isFieldPresent(sfHookNamespace))
|
||||
if (hookGrantObj.getFieldH256(sfHookHash) ==
|
||||
hookCtx.result.hookHash &&
|
||||
(!hasAuthorizedField ||
|
||||
hookGrantObj.getAccountID(sfAuthorize) ==
|
||||
hookCtx.result.account))
|
||||
{
|
||||
if (hookObj.getFieldH256(sfHookNamespace) != ns)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// fetch the hook definition
|
||||
auto const def =
|
||||
hookCtx.applyCtx.view().read(ripple::keylet::hookDefinition(
|
||||
hookObj.getFieldH256(sfHookHash)));
|
||||
if (!def) // should never happen except in a rare race
|
||||
// condition
|
||||
continue;
|
||||
if (def->getFieldH256(sfHookNamespace) != ns)
|
||||
continue;
|
||||
}
|
||||
|
||||
// this is expensive search so we'll disallow after one failed
|
||||
// attempt
|
||||
for (auto const& hookGrantObj : hookGrants)
|
||||
{
|
||||
bool hasAuthorizedField =
|
||||
hookGrantObj.isFieldPresent(sfAuthorize);
|
||||
|
||||
if (hookGrantObj.getFieldH256(sfHookHash) ==
|
||||
hookCtx.result.hookHash &&
|
||||
(!hasAuthorizedField ||
|
||||
hookGrantObj.getAccountID(sfAuthorize) ==
|
||||
hookCtx.result.account))
|
||||
{
|
||||
found_auth = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found_auth)
|
||||
found_auth = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found_auth)
|
||||
{
|
||||
// hook only gets one attempt
|
||||
hookCtx.result.foreignStateSetDisabled = true;
|
||||
return Unexpected(NOT_AUTHORIZED);
|
||||
}
|
||||
if (found_auth)
|
||||
break;
|
||||
}
|
||||
|
||||
// add the grant to the cache
|
||||
hookCtx.result.foreignStateGrantCache.emplace(account, ns);
|
||||
if (!found_auth)
|
||||
{
|
||||
// hook only gets one attempt
|
||||
hookCtx.result.foreignStateSetDisabled = true;
|
||||
return Unexpected(NOT_AUTHORIZED);
|
||||
}
|
||||
|
||||
if (auto ret = set_state_cache(account, ns, key, data, true);
|
||||
|
||||
@@ -148,31 +148,6 @@ ammLPHolds(
|
||||
// Put balance in account terms.
|
||||
amount.negate();
|
||||
}
|
||||
|
||||
// If tokens can be escrowed then they can be locked in the trustline
|
||||
// which means we must never spend them until the escrow is released.
|
||||
if (view.rules().enabled(featurePaychanAndEscrowForTokens) &&
|
||||
sle->isFieldPresent(sfLockedBalance))
|
||||
{
|
||||
STAmount const lockedBalance = sle->getFieldAmount(sfLockedBalance);
|
||||
STAmount const spendableBalance = amount -
|
||||
(lpAccount > ammAccount ? -lockedBalance : lockedBalance);
|
||||
|
||||
// RH NOTE: this is defensively programmed, it should never fire
|
||||
// if something bad does happen the trustline acts as a frozen line.
|
||||
if (spendableBalance < beast::zero || spendableBalance > amount)
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
JLOG(j.error())
|
||||
<< "SpendableBalance has illegal value in accountHolds "
|
||||
<< spendableBalance;
|
||||
amount.clear(Issue{currency, ammAccount});
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
else
|
||||
amount = spendableBalance;
|
||||
}
|
||||
|
||||
amount.setIssuer(ammAccount);
|
||||
|
||||
JLOG(j.trace()) << "ammLPHolds:"
|
||||
|
||||
@@ -259,6 +259,7 @@ AMMClawback::equalWithdrawMatchingOneAmount(
|
||||
STAmount const& amount)
|
||||
{
|
||||
auto frac = Number{amount} / amountBalance;
|
||||
auto amount2Withdraw = amount2Balance * frac;
|
||||
|
||||
auto const lpTokensWithdraw =
|
||||
toSTAmount(lptAMMBalance.issue(), lptAMMBalance * frac);
|
||||
|
||||
@@ -375,12 +375,10 @@ accountHolds(
|
||||
// if something bad does happen the trustline acts as a frozen line.
|
||||
if (spendableBalance < beast::zero || spendableBalance > amount)
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
JLOG(j.error())
|
||||
<< "SpendableBalance has illegal value in accountHolds "
|
||||
<< spendableBalance;
|
||||
amount.clear(Issue{currency, issuer});
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
else
|
||||
amount = spendableBalance;
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/app/misc/AmendmentTable.h>
|
||||
#include <xrpld/app/misc/NetworkOPs.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/rpc/detail/TransactionSign.h>
|
||||
#include <xrpl/json/json_value.h>
|
||||
#include <xrpl/json/json_writer.h>
|
||||
@@ -546,39 +545,6 @@ doServerDefinitions(RPC::JsonContext& context)
|
||||
features[to_string(h)][jss::majority] =
|
||||
t.time_since_epoch().count();
|
||||
|
||||
// Amendment activation has two independent sources; surface both so a
|
||||
// consumer isn't misled by a node that force-enables amendments:
|
||||
// ledger_enabled : recorded in the on-ledger Amendments object
|
||||
// (network-canonical; what the table reports as
|
||||
// "enabled")
|
||||
// cfg_forced : force-activated via the [features] config stanza
|
||||
// (node-local; active in the Rules regardless of the
|
||||
// ledger, casts no votes, never written on-ledger)
|
||||
// enabled : effective for transaction processing on this
|
||||
// server, i.e. ledger_enabled || cfg_forced
|
||||
for (auto const& name : features.getMemberNames())
|
||||
{
|
||||
Json::Value& entry = features[name];
|
||||
bool const ledgerEnabled = entry[jss::enabled].asBool();
|
||||
entry[jss::ledger_enabled] = ledgerEnabled;
|
||||
entry[jss::cfg_forced] = false;
|
||||
// entry[jss::enabled] is left == ledgerEnabled here; only
|
||||
// cfg_forced amendments below flip it.
|
||||
}
|
||||
for (auto const& h : context.app.config().features)
|
||||
{
|
||||
Json::Value& entry = features[to_string(h)];
|
||||
if (!entry.isMember(jss::name))
|
||||
{
|
||||
if (auto const fname = featureToName(h); !fname.empty())
|
||||
entry[jss::name] = fname;
|
||||
}
|
||||
if (!entry.isMember(jss::ledger_enabled))
|
||||
entry[jss::ledger_enabled] = false;
|
||||
entry[jss::cfg_forced] = true;
|
||||
entry[jss::enabled] = true; // ledger_enabled || cfg_forced
|
||||
}
|
||||
|
||||
lastFeatures = features;
|
||||
{
|
||||
const std::string out = Json::FastWriter().write(features);
|
||||
|
||||
Reference in New Issue
Block a user