Esempio n. 1
0
Simulation::pointer
Topologies::separate(int nNodes, float quorumThresoldFraction,
                     Simulation::Mode mode, Hash const& networkID,
                     std::function<Config()> confGen)
{
    Simulation::pointer simulation =
        make_shared<Simulation>(mode, networkID, confGen);

    vector<SecretKey> keys;
    for (int i = 0; i < nNodes; i++)
    {
        keys.push_back(
            SecretKey::fromSeed(sha256("NODE_SEED_" + to_string(i))));
    }

    SCPQuorumSet qSet;
    assert(quorumThresoldFraction >= 0.5);
    qSet.threshold =
        min(nNodes, static_cast<int>(ceil(nNodes * quorumThresoldFraction)));
    for (auto const& k : keys)
    {
        qSet.validators.push_back(k.getPublicKey());
    }

    for (auto const& k : keys)
    {
        simulation->addNode(k, qSet, simulation->getClock());
    }
    return simulation;
}
Esempio n. 2
0
void
printStats(int& nLedgers, std::chrono::system_clock::time_point tBegin,
           Simulation::pointer sim)
{
    auto t = std::chrono::duration_cast<std::chrono::seconds>(
        std::chrono::system_clock::now() - tBegin);

    LOG(INFO) << "Time spent closing " << nLedgers << " ledgers with "
              << sim->getNodes().size() << " nodes : " << t.count()
              << " seconds";

    LOG(INFO) << sim->metricsSummary("scp");
}
Esempio n. 3
0
Simulation::pointer
Topologies::pair(Simulation::Mode mode, Hash const& networkID)
{
    Simulation::pointer simulation = make_shared<Simulation>(mode, networkID);

    SIMULATION_CREATE_NODE(10);
    SIMULATION_CREATE_NODE(11);

    SCPQuorumSet qSet0;
    qSet0.threshold = 2;
    qSet0.validators.push_back(v10NodeID);
    qSet0.validators.push_back(v11NodeID);

    auto n0 = simulation->addNode(v10SecretKey, qSet0, simulation->getClock());
    auto n1 = simulation->addNode(v11SecretKey, qSet0, simulation->getClock());

    simulation->addPendingConnection(n0, n1);
    return simulation;
}
Esempio n. 4
0
Simulation::pointer
Topologies::core(int nNodes, float quorumThresoldFraction,
                 Simulation::Mode mode, Hash const& networkID)
{
    Simulation::pointer simulation = make_shared<Simulation>(mode, networkID);

    vector<SecretKey> keys;
    for (int i = 0; i < nNodes; i++)
    {
        keys.push_back(SecretKey::fromSeed(
            sha256("NODE_SEED_" + to_string(i))));
    }

    SCPQuorumSet qSet;
    assert(quorumThresoldFraction >= 0.5);
    qSet.threshold =
        min(nNodes, static_cast<int>(ceil(nNodes * quorumThresoldFraction)));
    for (auto const& k : keys)
    {
        qSet.validators.push_back(k.getPublicKey());
    }

    for (auto const& k : keys)
    {
        simulation->addNode(k, qSet, simulation->getClock());
    }
    for (int from = 0; from < nNodes - 1; from++)
    {
        for (int to = from + 1; to < nNodes; to++)
        {
            simulation->addPendingConnection(keys[from].getPublicKey(),
                                             keys[to].getPublicKey());
        }
    }

    return simulation;
}
Esempio n. 5
0
Simulation::pointer
Topologies::cycle4(Hash const& networkID, std::function<Config()> confGen)
{
    Simulation::pointer simulation =
        make_shared<Simulation>(Simulation::OVER_LOOPBACK, networkID, confGen);

    SIMULATION_CREATE_NODE(0);
    SIMULATION_CREATE_NODE(1);
    SIMULATION_CREATE_NODE(2);
    SIMULATION_CREATE_NODE(3);

    SCPQuorumSet qSet0;
    qSet0.threshold = 2;
    qSet0.validators.push_back(v1NodeID);
    qSet0.validators.push_back(v0NodeID);
    SCPQuorumSet qSet1;
    qSet1.threshold = 2;
    qSet1.validators.push_back(v1NodeID);
    qSet1.validators.push_back(v2NodeID);
    SCPQuorumSet qSet2;
    qSet2.threshold = 2;
    qSet2.validators.push_back(v2NodeID);
    qSet2.validators.push_back(v3NodeID);
    SCPQuorumSet qSet3;
    qSet3.threshold = 2;
    qSet3.validators.push_back(v3NodeID);
    qSet3.validators.push_back(v0NodeID);

    auto n0 = simulation->addNode(v0SecretKey, qSet0, simulation->getClock());
    auto n1 = simulation->addNode(v1SecretKey, qSet1, simulation->getClock());
    auto n2 = simulation->addNode(v2SecretKey, qSet2, simulation->getClock());
    auto n3 = simulation->addNode(v3SecretKey, qSet3, simulation->getClock());

    simulation->addPendingConnection(n0, n1);
    simulation->addPendingConnection(n1, n2);
    simulation->addPendingConnection(n2, n3);
    simulation->addPendingConnection(n3, n0);

    simulation->addPendingConnection(n0, n2);
    simulation->addPendingConnection(n1, n3);

    return simulation;
}
Esempio n. 6
0
#include "TCPPeer.h"
#include "lib/catch.hpp"
#include "main/Application.h"
#include "main/test.h"
#include "overlay/PeerDoor.h"
#include "main/Config.h"
#include "util/Logging.h"
#include "simulation/Simulation.h"
#include "overlay/OverlayManager.h"

namespace stellar
{

TEST_CASE("TCPPeer can communicate", "[overlay]")
{
    Simulation::pointer s = std::make_shared<Simulation>(Simulation::OVER_TCP);

    auto v10SecretKey = SecretKey::fromSeed(sha256("v10"));
    auto v11SecretKey = SecretKey::fromSeed(sha256("v11"));

    SCPQuorumSet n0_qset;
    n0_qset.threshold = 1;
    n0_qset.validators.push_back(v10SecretKey.getPublicKey());
    auto n0 =
        s->getNode(s->addNode(v10SecretKey, n0_qset, s->getClock()));

    SCPQuorumSet n1_qset;
    n1_qset.threshold = 1;
    n1_qset.validators.push_back(v11SecretKey.getPublicKey());
    auto n1 =
        s->getNode(s->addNode(v11SecretKey, n1_qset, s->getClock()));
#include "lib/catch.hpp"
#include "main/Application.h"
#include "main/test.h"
#include "overlay/PeerDoor.h"
#include "main/Config.h"
#include "util/Logging.h"
#include "simulation/Simulation.h"
#include "overlay/OverlayManager.h"

namespace stellar
{

TEST_CASE("TCPPeer can communicate", "[overlay]")
{
    Hash networkID = sha256(getTestConfig().NETWORK_PASSPHRASE);
    Simulation::pointer s =
        std::make_shared<Simulation>(Simulation::OVER_TCP, networkID);

    auto v10SecretKey = SecretKey::fromSeed(sha256("v10"));
    auto v11SecretKey = SecretKey::fromSeed(sha256("v11"));

    SCPQuorumSet n0_qset;
    n0_qset.threshold = 1;
    n0_qset.validators.push_back(v10SecretKey.getPublicKey());
    auto n0 = s->getNode(s->addNode(v10SecretKey, n0_qset, s->getClock()));

    SCPQuorumSet n1_qset;
    n1_qset.threshold = 1;
    n1_qset.validators.push_back(v11SecretKey.getPublicKey());
    auto n1 = s->getNode(s->addNode(v11SecretKey, n1_qset, s->getClock()));

    s->addPendingConnection(v10SecretKey.getPublicKey(),