mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
dump more building
This commit is contained in:
@@ -56,8 +56,8 @@ ApplyContext::discard()
|
||||
void
|
||||
ApplyContext::apply(TER ter)
|
||||
{
|
||||
std::cout << "ApplyContext::apply" << "\n";
|
||||
std::cout << "tx: " << tx.getTransactionID() << "\n";
|
||||
// std::cout << "ApplyContext::apply" << "\n";
|
||||
// std::cout << "tx: " << tx.getTransactionID() << "\n";
|
||||
// if (flags_ == tapPREFLIGHT_BATCH)
|
||||
// return;
|
||||
view_->apply(base_, tx, ter, journal);
|
||||
|
||||
@@ -378,18 +378,23 @@ Batch::preclaim(PreclaimContext const& ctx)
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
std::vector<TER> doApplyResponses;
|
||||
|
||||
TER
|
||||
Batch::doApply()
|
||||
{
|
||||
std::cout << "Batch::doApply()" << "\n";
|
||||
// std::cout << "Batch::doApply()" << "\n";
|
||||
Sandbox sb(&ctx_.view());
|
||||
// Sandbox sb(ctx_.base_.base_, view().flags());
|
||||
|
||||
uint32_t flags = ctx_.tx.getFlags();
|
||||
if (flags & tfBatchMask)
|
||||
return temINVALID_FLAG;
|
||||
|
||||
auto const& txns = ctx_.tx.getFieldArray(sfRawTransactions);
|
||||
for (std::size_t i = 0; i < txns.size(); ++i)
|
||||
{
|
||||
std::cout << "START" << "\n";
|
||||
// std::cout << "START" << "\n";
|
||||
ApplyViewImpl& avi = dynamic_cast<ApplyViewImpl&>(ctx_.view());
|
||||
STObject meta{sfBatchExecution};
|
||||
|
||||
@@ -404,8 +409,9 @@ Batch::doApply()
|
||||
auto const tt = txn.getFieldU16(sfTransactionType);
|
||||
auto const txtype = safe_cast<TxType>(tt);
|
||||
auto const stx = STTx(txtype, [&txn](STObject& obj) { obj = std::move(txn); });
|
||||
|
||||
|
||||
// OpenView(&ctx_.view())
|
||||
JLOG(ctx_.journal.error()) << "Batch: SUBMITTING: " << preclaimResponses[i];
|
||||
ApplyContext actx(
|
||||
ctx_.app,
|
||||
ctx_.base_,
|
||||
@@ -414,7 +420,6 @@ Batch::doApply()
|
||||
ctx_.view().fees().base,
|
||||
view().flags(),
|
||||
ctx_.journal);
|
||||
|
||||
auto const result = invoke_apply(actx);
|
||||
meta.setFieldU8(sfTransactionResult, TERtoInt(result.first));
|
||||
meta.setFieldU16(sfTransactionType, tt);
|
||||
@@ -422,10 +427,17 @@ Batch::doApply()
|
||||
meta.setFieldH256(sfTransactionHash, stx.getTransactionID());
|
||||
|
||||
avi.addBatchExecutionMetaData(std::move(meta));
|
||||
|
||||
if (result.first != tesSUCCESS)
|
||||
{
|
||||
actx.discard();
|
||||
|
||||
if (flags & tfBatchFirst)
|
||||
{
|
||||
return tecFAILED_PROCESSING;
|
||||
}
|
||||
}
|
||||
doApplyResponses.push_back(result.first);
|
||||
}
|
||||
|
||||
auto const sle = ctx_.base_.read(keylet::account(account_));
|
||||
@@ -436,13 +448,25 @@ Batch::doApply()
|
||||
if (!sleSrcAcc)
|
||||
return tefINTERNAL;
|
||||
|
||||
std::cout << "ACCOUNT SEQ: " << sleSrcAcc->getFieldU32(sfSequence) << "\n";
|
||||
std::cout << "ACCOUNT BALANCE: " << mSourceBalance << "\n";
|
||||
std::cout << "ACCOUNT BALANCE=: " << sle->getFieldAmount(sfBalance) << "\n";
|
||||
// std::cout << "ACCOUNT SEQ: " << sleSrcAcc->getFieldU32(sfSequence) << "\n";
|
||||
// std::cout << "ACCOUNT BALANCE: " << mSourceBalance << "\n";
|
||||
// std::cout << "ACCOUNT BALANCE=: " << sle->getFieldAmount(sfBalance) << "\n";
|
||||
sleSrcAcc->setFieldAmount(sfBalance, sle->getFieldAmount(sfBalance));
|
||||
sb.update(sleSrcAcc);
|
||||
sb.apply(ctx_.rawView());
|
||||
|
||||
for (auto applyResp : doApplyResponses)
|
||||
{
|
||||
if (applyResp != tesSUCCESS)
|
||||
{
|
||||
if (flags & tfBatchAtomic)
|
||||
{
|
||||
ctx_.discard();
|
||||
return tecFAILED_PROCESSING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sb.apply(ctx_.rawView());
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -259,7 +259,7 @@ XRPNotCreated::finalize(
|
||||
// std::cout << "fee.drops: " << feeAdded << "\n";
|
||||
// std::cout << "dropsAdded: " << dropsAdded.drops() << "\n";
|
||||
// std::cout << "drops: " << drops << "\n";
|
||||
std::cout << "drops=: " << drops_ << "\n";
|
||||
// std::cout << "drops=: " << drops_ << "\n";
|
||||
|
||||
// catch any overflow or funny business
|
||||
// if (drops > dropsAdded.drops())
|
||||
|
||||
@@ -300,7 +300,7 @@ Payment::preclaim(PreclaimContext const& ctx)
|
||||
TER
|
||||
Payment::doApply()
|
||||
{
|
||||
std::cout << "Payment::doApply()" << "\n";
|
||||
// std::cout << "Payment::doApply()" << "\n";
|
||||
auto const deliverMin = ctx_.tx[~sfDeliverMin];
|
||||
|
||||
// Ripple if source or destination is non-native or if there are paths.
|
||||
|
||||
@@ -808,8 +808,8 @@ Transactor::apply()
|
||||
preCompute();
|
||||
|
||||
auto const tt = ctx_.tx.getTxnType();
|
||||
std::cout << "tt: " << tt << "\n";
|
||||
std::cout << "id: " << ctx_.tx.getTransactionID() << "\n";
|
||||
// std::cout << "tt: " << tt << "\n";
|
||||
// std::cout << "id: " << ctx_.tx.getTransactionID() << "\n";
|
||||
// if (tt == ttBATCH)
|
||||
// return doApply();
|
||||
|
||||
@@ -831,7 +831,7 @@ Transactor::apply()
|
||||
// std::cout << "mPriorBalance: " << mPriorBalance << "\n";
|
||||
// std::cout << "mSourceBalance=: " << (mSourceBalance - mPriorBalance) << "\n";
|
||||
mPriorBalance = STAmount{(*sle)[sfBalance]}.xrp();
|
||||
std::cout << "mPriorBalance: " << mPriorBalance << "\n";
|
||||
// std::cout << "mPriorBalance: " << mPriorBalance << "\n";
|
||||
mSourceBalance = mPriorBalance;
|
||||
|
||||
TER result = consumeSeqProxy(sle);
|
||||
@@ -848,7 +848,7 @@ Transactor::apply()
|
||||
view().update(sle);
|
||||
}
|
||||
|
||||
std::cout << "Transactor::apply" << "\n";
|
||||
// std::cout << "Transactor::apply" << "\n";
|
||||
|
||||
return doApply();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ ApplyViewImpl::ApplyViewImpl(ReadView const* base, ApplyFlags flags)
|
||||
void
|
||||
ApplyViewImpl::apply(OpenView& to, STTx const& tx, TER ter, beast::Journal j)
|
||||
{
|
||||
std::cout << "ApplyViewImpl::apply" << "\n";
|
||||
// std::cout << "ApplyViewImpl::apply" << "\n";
|
||||
items_.apply(to, tx, ter, deliver_, batchExecution_, hookExecution_, hookEmission_, j);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,11 +129,11 @@ OpenView::txCount() const
|
||||
void
|
||||
OpenView::apply(TxsRawView& to) const
|
||||
{
|
||||
std::cout << "OpenView::apply" << "\n";
|
||||
// std::cout << "OpenView::apply" << "\n";
|
||||
items_.apply(to);
|
||||
for (auto const& item : txs_)
|
||||
{
|
||||
std::cout << "OpenView::apply: " << to_string(item.first) << "\n";
|
||||
// std::cout << "OpenView::apply: " << to_string(item.first) << "\n";
|
||||
to.rawTxInsert(item.first, item.second.txn, item.second.meta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,6 +168,14 @@ constexpr std::uint32_t const tfURITokenNonMintMask = ~tfUniversal;
|
||||
// ClaimReward flags:
|
||||
constexpr std::uint32_t const tfOptOut = 0x00000001;
|
||||
|
||||
enum BatchFlags : std::uint32_t {
|
||||
tfBatchAtomic = 0x00000001,
|
||||
tfBatchFirst = 0x00000002,
|
||||
};
|
||||
|
||||
constexpr std::uint32_t const tfBatchMask =
|
||||
~(tfUniversal | tfBatchAtomic | tfBatchFirst);
|
||||
|
||||
// clang-format on
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
@@ -61,10 +61,9 @@ class Batch_test : public beast::unit_test::suite
|
||||
jv[sfRawTransactions.jsonName][index] = Json::Value{};
|
||||
jv[sfRawTransactions.jsonName][index][jss::RawTransaction] = tx;
|
||||
jv[sfRawTransactions.jsonName][index][jss::RawTransaction][jss::SigningPubKey] = strHex(account.pk());
|
||||
jv[sfRawTransactions.jsonName][index][jss::RawTransaction][sfFee.jsonName] = 0;
|
||||
jv[sfRawTransactions.jsonName][index][jss::RawTransaction][jss::Sequence] = 0;
|
||||
jv[sfRawTransactions.jsonName][index][jss::RawTransaction][sfOperationLimit.jsonName] = index;
|
||||
jv[sfRawTransactions.jsonName][index][jss::RawTransaction][sfCloseResolution.jsonName] = next;
|
||||
jv[sfRawTransactions.jsonName][index][jss::RawTransaction][sfFee.jsonName] = to_string(feeDrops);
|
||||
jv[sfRawTransactions.jsonName][index][jss::RawTransaction][jss::Sequence] = next;
|
||||
// jv[sfRawTransactions.jsonName][index][jss::RawTransaction][sfCloseResolution.jsonName] = next;
|
||||
return jv;
|
||||
}
|
||||
|
||||
@@ -200,14 +199,14 @@ class Batch_test : public beast::unit_test::suite
|
||||
using namespace test::jtx;
|
||||
using namespace std::literals;
|
||||
|
||||
test::jtx::Env env{*this, envconfig()};
|
||||
// Env env{
|
||||
// *this,
|
||||
// envconfig(),
|
||||
// features,
|
||||
// nullptr,
|
||||
// // beast::severities::kWarning
|
||||
// beast::severities::kTrace};
|
||||
// test::jtx::Env env{*this, envconfig()};
|
||||
Env env{
|
||||
*this,
|
||||
envconfig(),
|
||||
features,
|
||||
nullptr,
|
||||
// beast::severities::kWarning
|
||||
beast::severities::kTrace};
|
||||
|
||||
auto const feeDrops = env.current()->fees().base;
|
||||
|
||||
@@ -222,17 +221,18 @@ class Batch_test : public beast::unit_test::suite
|
||||
Json::Value jv;
|
||||
jv[jss::TransactionType] = jss::Batch;
|
||||
jv[jss::Account] = alice.human();
|
||||
jv[jss::Sequence] = seq + 2;
|
||||
|
||||
// Batch Transactions
|
||||
jv[sfRawTransactions.jsonName] = Json::Value{Json::arrayValue};
|
||||
|
||||
// Tx 1
|
||||
Json::Value const tx1 = pay(alice, bob, XRP(1));
|
||||
jv = addBatchTx(jv, tx1, alice, feeDrops, 0, 0);
|
||||
jv = addBatchTx(jv, tx1, alice, feeDrops, 0, seq);
|
||||
|
||||
// Tx 2
|
||||
Json::Value const tx2 = pay(alice, bob, XRP(1));
|
||||
jv = addBatchTx(jv, tx2, alice, feeDrops, 1, 0);
|
||||
jv = addBatchTx(jv, tx2, alice, feeDrops, 1, seq + 1);
|
||||
|
||||
env(jv, fee(feeDrops * 2), ter(tesSUCCESS));
|
||||
env.close();
|
||||
@@ -255,22 +255,14 @@ class Batch_test : public beast::unit_test::suite
|
||||
}
|
||||
|
||||
void
|
||||
testSingle(FeatureBitset features)
|
||||
testAtomicFailure(FeatureBitset features)
|
||||
{
|
||||
testcase("batch single");
|
||||
testcase("atomic failure");
|
||||
|
||||
using namespace test::jtx;
|
||||
using namespace std::literals;
|
||||
|
||||
test::jtx::Env env{*this, envconfig()};
|
||||
// Env env{
|
||||
// *this,
|
||||
// envconfig(),
|
||||
// features,
|
||||
// nullptr,
|
||||
// // beast::severities::kWarning
|
||||
// beast::severities::kTrace};
|
||||
|
||||
auto const feeDrops = env.current()->fees().base;
|
||||
|
||||
auto const alice = Account("alice");
|
||||
@@ -280,80 +272,39 @@ class Batch_test : public beast::unit_test::suite
|
||||
env.close();
|
||||
|
||||
auto const seq = env.seq("alice");
|
||||
// ttBATCH
|
||||
Json::Value jv;
|
||||
jv[jss::TransactionType] = jss::Batch;
|
||||
jv[jss::Account] = alice.human();
|
||||
jv[jss::Sequence] = seq;
|
||||
|
||||
// Batch Transactions
|
||||
jv[sfRawTransactions.jsonName] = Json::Value{Json::arrayValue};
|
||||
|
||||
// Tx 1
|
||||
jv[sfRawTransactions.jsonName][0U] = Json::Value{};
|
||||
jv[sfRawTransactions.jsonName][0U][jss::RawTransaction] = Json::Value{};
|
||||
jv[sfRawTransactions.jsonName][0U][jss::RawTransaction]
|
||||
[jss::TransactionType] = jss::Payment;
|
||||
jv[sfRawTransactions.jsonName][0U][jss::RawTransaction]
|
||||
[sfAccount.jsonName] = alice.human();
|
||||
jv[sfRawTransactions.jsonName][0U][jss::RawTransaction]
|
||||
[sfDestination.jsonName] = bob.human();
|
||||
jv[sfRawTransactions.jsonName][0U][jss::RawTransaction]
|
||||
[sfAmount.jsonName] = "1000000";
|
||||
jv[sfRawTransactions.jsonName][0U][jss::RawTransaction][sfFee.jsonName] =
|
||||
to_string(feeDrops);
|
||||
jv[sfRawTransactions.jsonName][0U][jss::RawTransaction][jss::Sequence] =
|
||||
seq + 0;
|
||||
jv[sfRawTransactions.jsonName][0U][jss::RawTransaction]
|
||||
[jss::SigningPubKey] = strHex(alice.pk());
|
||||
Json::Value const tx1 = pay(alice, bob, XRP(1));
|
||||
jv = addBatchTx(jv, tx1, alice, feeDrops, 0, 0);
|
||||
|
||||
// Tx 2
|
||||
jv[sfRawTransactions.jsonName][1U] = Json::Value{};
|
||||
jv[sfRawTransactions.jsonName][1U][jss::RawTransaction] = Json::Value{};
|
||||
jv[sfRawTransactions.jsonName][1U][jss::RawTransaction]
|
||||
[jss::TransactionType] = jss::Payment;
|
||||
jv[sfRawTransactions.jsonName][1U][jss::RawTransaction]
|
||||
[sfAccount.jsonName] = alice.human();
|
||||
jv[sfRawTransactions.jsonName][1U][jss::RawTransaction]
|
||||
[sfDestination.jsonName] = bob.human();
|
||||
jv[sfRawTransactions.jsonName][1U][jss::RawTransaction]
|
||||
[sfAmount.jsonName] = "999900000";
|
||||
jv[sfRawTransactions.jsonName][1U][jss::RawTransaction][sfFee.jsonName] =
|
||||
to_string(feeDrops);
|
||||
jv[sfRawTransactions.jsonName][1U][jss::RawTransaction][jss::Sequence] =
|
||||
seq + 1;
|
||||
jv[sfRawTransactions.jsonName][1U][jss::RawTransaction]
|
||||
[jss::SigningPubKey] = strHex(alice.pk());
|
||||
Json::Value const tx2 = pay(alice, bob, XRP(999));
|
||||
jv = addBatchTx(jv, tx2, alice, feeDrops, 1, 0);
|
||||
|
||||
env(jv, fee((feeDrops * 2)), ter(tesSUCCESS));
|
||||
env(jv, fee(feeDrops * 2), txflags(tfBatchAtomic), ter(tecFAILED_PROCESSING));
|
||||
env.close();
|
||||
|
||||
std::array<TestBatchData, 2> testCases = {{
|
||||
{"tesSUCCESS", "Payment"},
|
||||
{"tecUNFUNDED_PAYMENT", "Payment"},
|
||||
}};
|
||||
|
||||
Json::Value params;
|
||||
params[jss::transaction] = env.tx()->getJson(JsonOptions::none)[jss::hash];
|
||||
auto const jrr = env.rpc("json", "tx", to_string(params));
|
||||
std::cout << "jrr: " << jrr << "\n";
|
||||
auto const meta = jrr[jss::result][jss::meta];
|
||||
validateBatchTxns(meta, testCases);
|
||||
|
||||
BEAST_EXPECT(env.seq(alice) == 4);
|
||||
BEAST_EXPECT(env.balance(alice) == XRP(1000) - XRP(1) - (feeDrops * 2));
|
||||
BEAST_EXPECT(env.balance(bob) == XRP(1000) + XRP(1));
|
||||
BEAST_EXPECT(env.seq(alice) == 2);
|
||||
BEAST_EXPECT(env.balance(alice) == XRP(1000) - (feeDrops * 2));
|
||||
BEAST_EXPECT(env.balance(bob) == XRP(1000));
|
||||
}
|
||||
|
||||
void
|
||||
testInvalidBatch(FeatureBitset features)
|
||||
testFirstFailure(FeatureBitset features)
|
||||
{
|
||||
testcase("invalid batch");
|
||||
testcase("first failure");
|
||||
|
||||
using namespace test::jtx;
|
||||
using namespace std::literals;
|
||||
|
||||
test::jtx::Env env{*this};
|
||||
test::jtx::Env env{*this, envconfig()};
|
||||
auto const feeDrops = env.current()->fees().base;
|
||||
|
||||
auto const alice = Account("alice");
|
||||
auto const bob = Account("bob");
|
||||
@@ -362,23 +313,40 @@ class Batch_test : public beast::unit_test::suite
|
||||
env.close();
|
||||
|
||||
Json::Value jv;
|
||||
jv[jss::TransactionType] = jss::AccountSet;
|
||||
jv[jss::TransactionType] = jss::Batch;
|
||||
jv[jss::Account] = alice.human();
|
||||
jv[jss::Destination] = bob.human();
|
||||
jv[sfFee.jsonName] = "10";
|
||||
jv[sfCloseResolution.jsonName] = to_string(1);
|
||||
env(jv, fee(drops(10)), ter(tesSUCCESS));
|
||||
|
||||
// Batch Transactions
|
||||
jv[sfRawTransactions.jsonName] = Json::Value{Json::arrayValue};
|
||||
|
||||
// Tx 1
|
||||
Json::Value const tx1 = pay(alice, bob, XRP(1));
|
||||
jv = addBatchTx(jv, tx1, alice, feeDrops, 0, 0);
|
||||
|
||||
// Tx 2
|
||||
Json::Value const tx2 = pay(alice, bob, XRP(999));
|
||||
jv = addBatchTx(jv, tx2, alice, feeDrops, 1, 0);
|
||||
|
||||
// Tx 3
|
||||
Json::Value const tx3 = pay(alice, bob, XRP(1));
|
||||
jv = addBatchTx(jv, tx3, alice, feeDrops, 2, 0);
|
||||
|
||||
env(jv, fee(feeDrops * 3), txflags(tfBatchFirst), ter(tecFAILED_PROCESSING));
|
||||
env.close();
|
||||
|
||||
BEAST_EXPECT(env.seq(alice) == 2);
|
||||
BEAST_EXPECT(env.balance(alice) == XRP(1000) - (feeDrops * 3));
|
||||
BEAST_EXPECT(env.balance(bob) == XRP(1000));
|
||||
}
|
||||
|
||||
void
|
||||
testWithFeats(FeatureBitset features)
|
||||
{
|
||||
// testBadPubKey(features);
|
||||
testUnfunded(features);
|
||||
// testSuccess(features);
|
||||
// testSingle(features);
|
||||
// testInvalidBatch(features);
|
||||
// testUnfunded(features);
|
||||
testSuccess(features);
|
||||
// testAtomicFailure(features);
|
||||
// testFirstFailure(features);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user