void closeLedger(vector<Simulation::TxInfo> txs)
    {
        auto baseFee = mApp->getConfig().DESIRED_BASE_FEE;
        TxSetFramePtr txSet = make_shared<TxSetFrame>(mApp->getLedgerManager().getLastClosedLedgerHeader().hash);
        for (auto& tx : txs)
        {
            txSet->add(tx.createPaymentTx());
            tx.recordExecution(baseFee);
        }

        LedgerCloseData ledgerData(mApp->getLedgerManager().getLedgerNum(),
            txSet,
            VirtualClock::to_time_t(mApp->getClock().now()),
            baseFee);

        mApp->getLedgerManager().closeLedger(ledgerData);
    }
    void
    closeLedger(vector<Simulation::TxInfo> txs)
    {
        auto baseFee = mApp->getConfig().DESIRED_BASE_FEE;
        LoadGenerator::TxMetrics txm(mApp->getMetrics());
        TxSetFramePtr txSet = make_shared<TxSetFrame>(
            mApp->getLedgerManager().getLastClosedLedgerHeader().hash);
        for (auto& tx : txs)
        {
            std::vector<TransactionFramePtr> txfs;
            tx.toTransactionFrames(*mApp, txfs, txm);
            for (auto f : txfs)
                txSet->add(f);
            tx.recordExecution(baseFee);
        }

        StellarValue sv(txSet->getContentsHash(),
                        VirtualClock::to_time_t(mApp->getClock().now()),
                        emptyUpgradeSteps, 0);
        LedgerCloseData ledgerData(mApp->getLedgerManager().getLedgerNum(),
                                   txSet, sv);

        mApp->getLedgerManager().closeLedger(ledgerData);
    }
 optional<TxInfo> ensureAccountIsLoadedCreated(size_t i)
 {
     if (!mAccounts[i])
     {
         auto newAccount = createAccount(i);
         mAccounts[i] = newAccount;
         if (!loadAccount(*newAccount))
         {
             newAccount->mSeq = LedgerHeaderFrame(mApp->getLedgerManager()
                 .getCurrentLedgerHeader())
                 .getStartingSequenceNumber();
             return make_optional<TxInfo>(newAccount->creationTransaction());
         }
     }
     return nullopt<TxInfo>();
 }
Beispiel #4
0
static int
catchup(Config const& cfg, uint32_t to, uint32_t count,
        Json::Value& catchupInfo)
{
    VirtualClock clock(VirtualClock::REAL_TIME);
    Application::pointer app = Application::create(clock, cfg, false);

    if (!checkInitialized(app))
    {
        return 1;
    }

    auto done = false;
    app->getLedgerManager().loadLastKnownLedger(
        [&done](asio::error_code const& ec) {
            if (ec)
            {
                throw std::runtime_error(
                    "Unable to restore last-known ledger state");
            }

            done = true;
        });
    while (!done && clock.crank(true))
        ;

    try
    {
        app->getLedgerManager().startCatchUp({to, count}, true);
    }
    catch (std::invalid_argument const&)
    {
        LOG(INFO) << "*";
        LOG(INFO) << "* Target ledger " << to
                  << " is not newer than last closed ledger"
                  << " - nothing to do";
        LOG(INFO) << "* If you really want to catchup to " << to
                  << " run stellar-core with --newdb parameter.";
        LOG(INFO) << "*";
        return 2;
    }

    auto& io = clock.getIOService();
    auto synced = false;
    asio::io_service::work mainWork(io);
    done = false;
    while (!done && clock.crank(true))
    {
        switch (app->getLedgerManager().getState())
        {
        case LedgerManager::LM_BOOTING_STATE:
        {
            LOG(INFO) << "*";
            LOG(INFO) << "* Catchup failed.";
            LOG(INFO) << "*";
            done = true;
            break;
        }
        case LedgerManager::LM_SYNCED_STATE:
        {
            LOG(INFO) << "*";
            LOG(INFO) << "* Catchup finished.";
            LOG(INFO) << "*";
            done = true;
            synced = true;
            break;
        }
        case LedgerManager::LM_CATCHING_UP_STATE:
            break;
        }
    }

    catchupInfo = app->getJsonInfo();
    app->gracefulStop();
    while (clock.crank(true))
        ;

    return synced ? 0 : 3;
}
    return updates;
}

TEST_CASE("Total coins change without inflation",
          "[invariant][conservationoflumens]")
{
    std::default_random_engine gen;
    Config cfg = getTestConfig(0);
    cfg.INVARIANT_CHECKS = {"ConservationOfLumens"};

    std::uniform_int_distribution<int64_t> dist(0, INT64_MAX);

    VirtualClock clock;
    Application::pointer app = createTestApplication(clock, cfg);

    LedgerHeader lh(app->getLedgerManager().getCurrentLedgerHeader());
    LedgerDelta ld(lh, app->getDatabase(), false);
    ld.getHeader().totalCoins = dist(gen);
    OperationResult res;
    REQUIRE_THROWS_AS(
        app->getInvariantManager().checkOnOperationApply({}, res, ld),
        InvariantDoesNotHold);
}

TEST_CASE("Fee pool change without inflation",
          "[invariant][conservationoflumens]")
{
    std::default_random_engine gen;
    Config cfg = getTestConfig(0);
    cfg.INVARIANT_CHECKS = {"ConservationOfLumens"};
Beispiel #6
0
    autocheck::generator<LedgerEntry>());

LedgerEntry
generateValidLedgerEntry()
{
    return validLedgerEntryGenerator(10);
}

TEST_CASE("Ledger entry db lifecycle", "[ledger]")
{
    Config cfg(getTestConfig());
    VirtualClock clock;
    Application::pointer app = Application::create(clock, cfg);

    app->start();
    LedgerDelta delta(app->getLedgerManager().getCurrentLedgerHeader(),
                      app->getDatabase());
    auto& db = app->getDatabase();
    for (size_t i = 0; i < 100; ++i)
    {
        auto le = EntryFrame::FromXDR(validLedgerEntryGenerator(3));
        CHECK(!EntryFrame::exists(db, le->getKey()));
        le->storeAddOrChange(delta, db);
        CHECK(EntryFrame::exists(db, le->getKey()));
        le->storeDelete(delta, db);
        CHECK(!EntryFrame::exists(db, le->getKey()));
    }
}

TEST_CASE("single ledger entry insert SQL", "[singlesql][entrysql]")
{
#include "test/TestAccount.h"
#include "test/TxTests.h"
#include "test/test.h"
#include "xdrpp/marshal.h"

using namespace stellar;
using namespace stellar::txtest;

TEST_CASE("PendingEnvelopes::recvSCPEnvelope", "[herder]")
{
    Config cfg(getTestConfig());
    VirtualClock clock;
    Application::pointer app = Application::create(clock, cfg);

    auto const& networkID = app->getNetworkID();
    auto const& lcl = app->getLedgerManager().getLastClosedLedgerHeader();

    auto root = TestAccount::createRoot(*app);
    auto a1 = getAccount("A");
    using TxPair = std::pair<Value, TxSetFramePtr>;
    auto makeTxPair = [](TxSetFramePtr txSet, uint64_t closeTime) {
        txSet->sortForHash();
        auto sv = StellarValue{txSet->getContentsHash(), closeTime,
                               emptyUpgradeSteps, 0};
        auto v = xdr::xdr_to_opaque(sv);

        return TxPair{v, txSet};
    };
    auto makeEnvelope = [&root](TxPair const& p, Hash qSetHash,
                                uint64_t slotIndex) {
        // herder must want the TxSet before receiving it, so we are sending it