Skip to content

Commit

Permalink
Merge pull request #1156 from stellar/next-db-and-proto-3
Browse files Browse the repository at this point in the history
Next db and proto 3

Reviewed-by: vogel
  • Loading branch information
latobarita authored Feb 6, 2017
2 parents b908d29 + 3ed448e commit 3c4e356
Show file tree
Hide file tree
Showing 109 changed files with 4,510 additions and 1,674 deletions.
64 changes: 31 additions & 33 deletions docs/stellar-core_example.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#
# This file gives details of the various configuration parameters you can set
# This file gives details of the various configuration parameters you can set
# when running stellar-core. You will need to edit to fit your own set up.
#
# This is a TOML file. See https://github.com/toml-lang/toml for syntax.


###########################
## General admin settings

Expand Down Expand Up @@ -48,8 +48,8 @@ DATABASE="sqlite3://stellar.db"
HTTP_PORT=11626

# PUBLIC_HTTP_PORT (true or false) default false
# If false you only accept stellar commands from localhost.
# Do not set to true and expose the port to the open internet. This will allow
# If false you only accept stellar commands from localhost.
# Do not set to true and expose the port to the open internet. This will allow
# random people to run stellar commands on your server. (such as `stop`)
PUBLIC_HTTP_PORT=false

Expand All @@ -63,8 +63,12 @@ COMMANDS=[
"ll?level=info&partition=Herder"
]

# convenience mapping of common names to node IDs. The common names can be used
# in the .cfg. `$common_name`. If set, they will also appear in your logs
# Date and Time in UTC when this node should start voting for upgrade for
# new ledger protocol version (currently: 3).
PREFERRED_UPGRADE_DATETIME=2017-03-01T00:00:00Z

# convenience mapping of common names to node IDs. The common names can be used
# in the .cfg. `$common_name`. If set, they will also appear in your logs
# instead of the less friendly nodeID.
#NODE_NAMES=[
# "GA22N4YGO7IJDRF2SISA5KHULGYYKDXBQGYIWUVNMSNHF5G2DNBKP3M5 eliza",
Expand All @@ -79,18 +83,18 @@ NETWORK_PASSPHRASE="Public Global Stellar Network ; September 2015"
###########################
## Overlay configuration

# PEER_PORT (Integer) defaults to 11625
# PEER_PORT (Integer) defaults to 11625
# The port other instances of stellar-core can connect to you on.
PEER_PORT=11625

# TARGET_PEER_CONNECTIONS (Integer) default 8
# This server will send outbound connection attempts until it is at this
# This server will send outbound connection attempts until it is at this
# number of peer connections.
TARGET_PEER_CONNECTIONS=8

# MAX_PEER_CONNECTIONS (Integer) default 12
# This server will start dropping peers if it is above this number of
# connected peers. The more peers you are connected to the higher
# This server will start dropping peers if it is above this number of
# connected peers. The more peers you are connected to the higher
# the bandwidth requirements
MAX_PEER_CONNECTIONS=12

Expand Down Expand Up @@ -126,7 +130,7 @@ MINIMUM_IDLE_PERCENT=0
# It will try to connect to these when it is below TARGET_PEER_CONNECTIONS.
KNOWN_PEERS=[
"core-testnet1.stellar.org",
"core-testnet2.stellar.org",
"core-testnet2.stellar.org",
"core-testnet3.stellar.org"]


Expand Down Expand Up @@ -177,7 +181,7 @@ DESIRED_MAX_TX_PER_LEDGER=400
# FAILURE_SAFETY (integer) default -1
# This is the number of failures you want to be able to tolerate.
# You will need at least 3f+1 nodes in your quorum set.
# If you don't have enough in your quorum set to tolerate the level you
# If you don't have enough in your quorum set to tolerate the level you
# set here stellar-core won't run.
# A value of -1 indicates to use (n-1)/3 (n being the number of nodes)
# A vale of 0 is only allowed if UNSAFE_QUORUM is set
Expand All @@ -190,7 +194,7 @@ FAILURE_SAFETY=-1
# a threshold % is set too low (threshold below 66% for the top level,
# 51% for other levels)
# FAILURE_SAFETY at 0 or above the number of failures that can occur
# You might want to set this if you are running your own network and
# You might want to set this if you are running your own network and
# aren't concerned with byzantine failures or if you fully understand how the
# quorum sets of other nodes relate to yours when it comes to
# quorum intersection.
Expand All @@ -211,22 +215,16 @@ CATCHUP_COMPLETE=false
# This limits the number that will be active at a time.
MAX_CONCURRENT_SUBPROCESSES=10

# MAINTENANCE_ON_STARTUP
# controls the type of maintenance to perform on startup
# true (default): perform as much automatic maintenance as possible
# false: no maintenance is attempted (must be performed as a command)
MAINTENANCE_ON_STARTUP=true

# See HISTORY table at below



###############################
## The following options should probably never be set. They are used primarily
## The following options should probably never be set. They are used primarily
## for testing.

# RUN_STANDALONE (true or false) defaults to false
# This is a mode for testing. It prevents you from trying to connect
# This is a mode for testing. It prevents you from trying to connect
# to other peers
RUN_STANDALONE=false

Expand All @@ -238,8 +236,8 @@ PARANOID_MODE=false


# MANUAL_CLOSE (true or false) defaults to false
# Mode for testing. Ledger will only close when stellar-core gets
# the `manualclose` command
# Mode for testing. Ledger will only close when stellar-core gets
# the `manualclose` command
MANUAL_CLOSE=false


Expand All @@ -253,7 +251,7 @@ ARTIFICIALLY_GENERATE_LOAD_FOR_TESTING=false

# ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING (true or false) defaults to false
# Reduces ledger close time to 1s and checkpoint frequency to every 8 ledgers.
# Do not ever set this in production, as it will make your history archives
# Do not ever set this in production, as it will make your history archives
# incompatible with those of anyone else.
ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING=false

Expand All @@ -271,18 +269,18 @@ ALLOW_LOCALHOST_FOR_TESTING=false
#####################
## Tables must come at the end. (TOML you are almost perfect!)

# HISTORY
# HISTORY
# Used to specify where to fetch and store the history archives.
# Fetching and storing history is kept as general as possible.
# Any place you can save and load static files from should be usable by the
# Fetching and storing history is kept as general as possible.
# Any place you can save and load static files from should be usable by the
# stellar-core history system. s3, the file system, http, etc
# stellar-core will call any external process you specify and will pass it the
# stellar-core will call any external process you specify and will pass it the
# name of the file to save or load.
# Simply use template parameters `{0}` and `{1}` in place of the files being transmitted or retrieved.
# You can specify multiple places to store and fetch from. stellar-core will
# You can specify multiple places to store and fetch from. stellar-core will
# use multiple fetching locations as backup in case there is a failure fetching from one.
#
# Note: any archive you *put* to you must run `$ stellar-core --newhist <historyarchive>`
# Note: any archive you *put* to you must run `$ stellar-core --newhist <historyarchive>`
# once before you start.
# for example this config you would run: $ stellar-core --newhist local
[HISTORY.local]
Expand Down Expand Up @@ -316,7 +314,7 @@ mkdir="mkdir -p /tmp/stellar-core/history/vs/{0}"
#
# It can be nested 2 levels: {A,B,C,{D,E,F},{G,H,{I,J,K,L}}}
# The THRESHOLD_PERCENT is how many have to agree (1-100%). The sets are treated
# as one vote. So for example in the above there are 5 things that can vote:
# as one vote. So for example in the above there are 5 things that can vote:
# individual validators: A,B,C, and the sets {D,E,F} and {G,H with subset {I,J,K,L}}
# the sets each have their own threshold.
# For example with {100% G,H with subset (50% I,J,K,L}}
Expand All @@ -334,8 +332,8 @@ mkdir="mkdir -p /tmp/stellar-core/history/vs/{0}"
#
# The following setup is equivalent to the example given above.
#
# Note on naming: you can add common names to the NAMED_NODES list here as
# shown in the first 3 validators or use common names that have been
# Note on naming: you can add common names to the NAMED_NODES list here as
# shown in the first 3 validators or use common names that have been
# previously defined.
[QUORUM_SET]
VALIDATORS=[
Expand Down
2 changes: 1 addition & 1 deletion src/bucket/BucketTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include "herder/LedgerCloseData.h"
#include "lib/catch.hpp"
#include "main/Application.h"
#include "main/test.h"
#include "ledger/LedgerTestUtils.h"
#include "test/test.h"
#include "util/Fs.h"
#include "util/Logging.h"
#include "util/Timer.h"
Expand Down
5 changes: 3 additions & 2 deletions src/crypto/CryptoTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

#include "main/test.h"
#include "util/Logging.h"
#include "lib/catch.hpp"
#include "crypto/Hex.h"
#include "crypto/KeyUtils.h"
#include "crypto/SHA.h"
#include "crypto/SecretKey.h"
#include "crypto/Random.h"
#include "crypto/StrKey.h"
#include "test/test.h"
#include "util/basen.h"
#include <autocheck/autocheck.hpp>
#include <sodium.h>
Expand Down Expand Up @@ -132,7 +133,7 @@ TEST_CASE("sign tests", "[crypto]")
auto sk = SecretKey::random();
auto pk = sk.getPublicKey();
LOG(DEBUG) << "generated random secret key seed: " << sk.getStrKeySeed();
LOG(DEBUG) << "corresponding public key: " << PubKeyUtils::toStrKey(pk);
LOG(DEBUG) << "corresponding public key: " << KeyUtils::toStrKey(pk);

CHECK(SecretKey::fromStrKeySeed(sk.getStrKeySeed()) == sk);

Expand Down
28 changes: 28 additions & 0 deletions src/crypto/KeyUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2016 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

#include "KeyUtils.h"

#include "crypto/StrKey.h"

namespace stellar
{

size_t
KeyUtils::getKeyVersionSize(strKey::StrKeyVersionByte keyVersion)
{
switch (keyVersion)
{
case strKey::STRKEY_PUBKEY_ED25519:
case strKey::STRKEY_SEED_ED25519:
return crypto_sign_PUBLICKEYBYTES;
case strKey::STRKEY_PRE_AUTH_TX:
case strKey::STRKEY_HASH_X:
return 32U;
default:
throw std::invalid_argument("invalid key version: " + std::to_string(keyVersion));
}
}

}
97 changes: 97 additions & 0 deletions src/crypto/KeyUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#pragma once

// Copyright 2016 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

#include "crypto/StrKey.h"
#include "xdr/Stellar-types.h"

#include <sodium.h>

#include <string>

namespace stellar
{

template<typename T>
struct KeyFunctions
{
struct getKeyTypeEnum
{
};

static std::string getKeyTypeName();
static bool getKeyVersionIsSupported(strKey::StrKeyVersionByte keyVersion);
static typename getKeyTypeEnum::type toKeyType(strKey::StrKeyVersionByte keyVersion);
static strKey::StrKeyVersionByte toKeyVersion(typename getKeyTypeEnum::type keyType);
static uint256 & getKeyValue(T &key);
static uint256 const& getKeyValue(T const &key);
};

// signer key utility functions
namespace KeyUtils
{

template<typename T>
std::string
toStrKey(T const& key)
{
return strKey::toStrKey(KeyFunctions<T>::toKeyVersion(key.type()), KeyFunctions<T>::getKeyValue(key));
}

template<typename T>
std::string
toShortString(T const& key)
{
return toStrKey(key).substr(0, 5);
}

std::size_t
getKeyVersionSize(strKey::StrKeyVersionByte keyVersion);

template<typename T>
T
fromStrKey(std::string const& s)
{
T key;
uint8_t verByte;
std::vector<uint8_t> k;
if (!strKey::fromStrKey(s, verByte, k))
{
throw std::invalid_argument("bad " + KeyFunctions<T>::getKeyTypeName());
}

strKey::StrKeyVersionByte ver = static_cast<strKey::StrKeyVersionByte>(verByte);
if (!KeyFunctions<T>::getKeyVersionIsSupported(ver) ||
(k.size() != getKeyVersionSize(ver)) ||
(s.size() != strKey::getStrKeySize(getKeyVersionSize(ver))))
{
throw std::invalid_argument("bad " + KeyFunctions<T>::getKeyTypeName());
}

key.type(KeyFunctions<T>::toKeyType(ver));
std::copy(k.begin(), k.end(), KeyFunctions<T>::getKeyValue(key).begin());
return key;
}

template<typename T, typename F>
bool
canConvert(F const &fromKey)
{
return KeyFunctions<T>::getKeyVersionIsSupported(KeyFunctions<F>::toKeyVersion(fromKey.type()));
}

template<typename T, typename F>
T
convertKey(F const &fromKey)
{
T toKey;
toKey.type(KeyFunctions<T>::toKeyType(KeyFunctions<F>::toKeyVersion(fromKey.type())));
KeyFunctions<T>::getKeyValue(toKey) = KeyFunctions<F>::getKeyValue(fromKey);
return toKey;
}

}

}
Loading

0 comments on commit 3c4e356

Please sign in to comment.