Skip to content

Commit

Permalink
Consensus: MOVEONLY: consensus
Browse files Browse the repository at this point in the history
  • Loading branch information
Folm committed Mar 29, 2018
1 parent 7e37fbd commit ee78fd8
Show file tree
Hide file tree
Showing 23 changed files with 318 additions and 203 deletions.
4 changes: 2 additions & 2 deletions qa/pull-tester/run-bitcoind-for-test.sh
Expand Up @@ -3,14 +3,14 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
DATADIR="/home/folm/folm/.folm"
DATADIR="/home/splendour/projects/folm/.folm"
rm -rf "$DATADIR"
mkdir -p "$DATADIR"/regtest
touch "$DATADIR/regtest/debug.log"
tail -q -n 1 -F "$DATADIR/regtest/debug.log" | grep -m 1 -q "Done loading" &
WAITER=$!
PORT=`expr 10000 + $$ % 55536`
"/home/folm/folm/src/folmd" -connect=0.0.0.0 -datadir="$DATADIR" -rpcuser=user -rpcpassword=pass -listen -keypool=3 -debug -debug=net -logtimestamps -checkmempool=0 -relaypriority=0 -port=$PORT -whitelist=127.0.0.1 -regtest -rpcport=`expr $PORT + 1` &
"/home/splendour/projects/folm/src/folmd" -connect=0.0.0.0 -datadir="$DATADIR" -rpcuser=user -rpcpassword=pass -listen -keypool=3 -debug -debug=net -logtimestamps -checkmempool=0 -relaypriority=0 -port=$PORT -whitelist=127.0.0.1 -regtest -rpcport=`expr $PORT + 1` &
BITCOIND=$!

#Install a watchdog.
Expand Down
2 changes: 1 addition & 1 deletion qa/pull-tester/tests-config.sh
Expand Up @@ -3,7 +3,7 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

BUILDDIR="/home/folm/folm"
BUILDDIR="/home/splendour/projects/folm"
EXEEXT=""

# These will turn into comments if they were disabled when configuring.
Expand Down
78 changes: 41 additions & 37 deletions src/Makefile
Expand Up @@ -96,15 +96,15 @@ am__append_2 = $(builddir)/leveldb/libleveldb.a
am__append_3 = $(builddir)/leveldb/libmemenv.a
am__append_4 = $(BDB_CPPFLAGS)
am__append_5 = libbitcoin_wallet.a
#am__append_6 = libbitcoin_zmq.a
am__append_6 = libbitcoin_zmq.a
bin_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
$(am__EXEEXT_4) $(am__EXEEXT_5)
TESTS = $(am__EXEEXT_6) $(am__EXEEXT_5)
am__append_7 = folmd
am__append_8 = folm-cli folm-tx
#am__append_9 = compat/glibc_compat.cpp \
# compat/glibcxx_compat.cpp
#am__append_10 = $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
am__append_10 = $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
am__append_11 = libbitcoin_wallet.a
#
#am__append_12 = folmd-res.rc
Expand Down Expand Up @@ -133,7 +133,7 @@ am__append_11 = libbitcoin_wallet.a
# test/rpc_wallet_tests.cpp

#am__append_20 = $(LIBBITCOIN_WALLET)
##am__append_21 = $(ZMQ_LIBS)
#am__append_21 = $(ZMQ_LIBS)
#am__append_22 = $(CLEAN_BITCOIN_TEST)
am__append_23 = qt/folm-qt
am__append_24 = qt/libbitcoinqt.a
Expand Down Expand Up @@ -174,7 +174,7 @@ am__append_25 = \
#am__append_26 = $(BITCOIN_MM)
#am__append_27 = $(BITCOIN_RC)
am__append_28 = $(LIBBITCOIN_WALLET)
#am__append_29 = $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
am__append_29 = $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
am__append_30 = $(CLEAN_QT)
#am__append_31 = qt/test/test_folm-qt
#am__append_32 = qt/test/test_folm-qt
Expand All @@ -183,7 +183,7 @@ am__append_30 = $(CLEAN_QT)
# qt/test/paymentservertests.cpp

#am__append_35 = $(LIBBITCOIN_WALLET)
##am__append_36 = $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
#am__append_36 = $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
#am__append_37 = $(CLEAN_BITCOIN_QT_TEST)
subdir = src
SUBDIRS =
Expand Down Expand Up @@ -325,7 +325,8 @@ am__libbitcoin_util_a_SOURCES_DIST = allocators.cpp compat/strnlen.cpp \
base58.h bip38.h bloom.h chain.h chainparams.h \
chainparamsbase.h chainparamsseeds.h checkpoints.h \
checkqueue.h clientversion.h coincontrol.h coins.h compat.h \
compat/sanity.h compressor.h primitives/block.h \
compat/sanity.h compressor.h consensus/consensus.h \
consensus/params.h consensus/validation.h primitives/block.h \
primitives/transaction.h core_io.h crypter.h obfuscation.h \
obfuscation-relay.h db.h eccryptoverify.h ecwrapper.h hash.h \
init.h kernel.h swifttx.h key.h keystore.h leveldbwrapper.h \
Expand Down Expand Up @@ -390,9 +391,9 @@ libbitcoin_zmq_a_AR = $(AR) $(ARFLAGS)
libbitcoin_zmq_a_LIBADD =
am__libbitcoin_zmq_a_SOURCES_DIST = zmq/zmqabstractnotifier.cpp \
zmq/zmqnotificationinterface.cpp zmq/zmqpublishnotifier.cpp
#am_libbitcoin_zmq_a_OBJECTS = zmq/libbitcoin_zmq_a-zmqabstractnotifier.$(OBJEXT) \
# zmq/libbitcoin_zmq_a-zmqnotificationinterface.$(OBJEXT) \
# zmq/libbitcoin_zmq_a-zmqpublishnotifier.$(OBJEXT)
am_libbitcoin_zmq_a_OBJECTS = zmq/libbitcoin_zmq_a-zmqabstractnotifier.$(OBJEXT) \
zmq/libbitcoin_zmq_a-zmqnotificationinterface.$(OBJEXT) \
zmq/libbitcoin_zmq_a-zmqpublishnotifier.$(OBJEXT)
libbitcoin_zmq_a_OBJECTS = $(am_libbitcoin_zmq_a_OBJECTS)
qt_libbitcoinqt_a_AR = $(AR) $(ARFLAGS)
qt_libbitcoinqt_a_LIBADD =
Expand Down Expand Up @@ -742,8 +743,8 @@ am_folmd_OBJECTS = folmd-folmd.$(OBJEXT) $(am__objects_11)
folmd_OBJECTS = $(am_folmd_OBJECTS)
am__DEPENDENCIES_2 = $(am__append_2)
am__DEPENDENCIES_3 = $(am__append_3)
#am__DEPENDENCIES_4 = $(LIBBITCOIN_ZMQ) \
# $(am__DEPENDENCIES_1)
am__DEPENDENCIES_4 = $(LIBBITCOIN_ZMQ) \
$(am__DEPENDENCIES_1)
folmd_DEPENDENCIES = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_UNIVALUE) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) \
$(am__DEPENDENCIES_2) $(am__DEPENDENCIES_3) $(LIBSECP256K1) \
Expand All @@ -767,9 +768,9 @@ am__objects_14 = qt/res/folm-qt-res.$(OBJEXT)
am_qt_folm_qt_OBJECTS = qt/qt_folm_qt-folm.$(OBJEXT) \
$(am__objects_13) $(am__objects_15)
qt_folm_qt_OBJECTS = $(am_qt_folm_qt_OBJECTS)
#am__DEPENDENCIES_5 = \
# $(LIBBITCOIN_ZMQ) \
# $(am__DEPENDENCIES_1)
am__DEPENDENCIES_5 = \
$(LIBBITCOIN_ZMQ) \
$(am__DEPENDENCIES_1)
qt_folm_qt_DEPENDENCIES = qt/libbitcoinqt.a \
$(LIBBITCOIN_SERVER) $(am__append_28) \
$(am__DEPENDENCIES_5) $(LIBBITCOIN_CLI) \
Expand Down Expand Up @@ -800,9 +801,9 @@ am__qt_test_test_folm_qt_SOURCES_DIST = qt/test/test_main.cpp \
# $(am__objects_18)
qt_test_test_folm_qt_OBJECTS = $(am_qt_test_test_folm_qt_OBJECTS) \
$(nodist_qt_test_test_folm_qt_OBJECTS)
##am__DEPENDENCIES_6 = \
## $(LIBBITCOIN_ZMQ) \
## $(am__DEPENDENCIES_1)
#am__DEPENDENCIES_6 = \
# $(LIBBITCOIN_ZMQ) \
# $(am__DEPENDENCIES_1)
#qt_test_test_folm_qt_DEPENDENCIES = \
# $(LIBBITCOINQT) $(LIBBITCOIN_SERVER) \
# $(am__append_35) $(am__DEPENDENCIES_6) \
Expand Down Expand Up @@ -897,8 +898,8 @@ am__test_test_folm_SOURCES_DIST = test/bignum.h \
test_test_folm_OBJECTS = $(am_test_test_folm_OBJECTS) \
$(nodist_test_test_folm_OBJECTS)
#am__DEPENDENCIES_7 = libbitcoinconsensus.la
##am__DEPENDENCIES_8 = \
## $(am__DEPENDENCIES_1)
#am__DEPENDENCIES_8 = \
# $(am__DEPENDENCIES_1)
#test_test_folm_DEPENDENCIES = $(LIBBITCOIN_SERVER) \
# $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) \
# $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) \
Expand Down Expand Up @@ -1261,13 +1262,13 @@ am__relativize = \
dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
done; \
reldir="$$dir2"
ACLOCAL = ${SHELL} /home/folm/folm/build-aux/missing aclocal-1.15
ACLOCAL = ${SHELL} /home/splendour/projects/folm/build-aux/missing aclocal-1.15
AMTAR = $${TAR-tar}
AM_DEFAULT_VERBOSITY = 0
AR = /usr/bin/ar
AUTOCONF = ${SHELL} /home/folm/folm/build-aux/missing autoconf
AUTOHEADER = ${SHELL} /home/folm/folm/build-aux/missing autoheader
AUTOMAKE = ${SHELL} /home/folm/folm/build-aux/missing automake-1.15
AUTOCONF = ${SHELL} /home/splendour/projects/folm/build-aux/missing autoconf
AUTOHEADER = ${SHELL} /home/splendour/projects/folm/build-aux/missing autoheader
AUTOMAKE = ${SHELL} /home/splendour/projects/folm/build-aux/missing automake-1.15
AWK = mawk
BDB_CPPFLAGS =
BDB_LIBS = -ldb_cxx-4.8
Expand Down Expand Up @@ -1358,7 +1359,7 @@ LTLIBOBJS =
LT_SYS_LIBRARY_PATH =
LUPDATE = /usr/lib/x86_64-linux-gnu/qt5/bin/lupdate
MAINT =
MAKEINFO = ${SHELL} /home/folm/folm/build-aux/missing makeinfo
MAKEINFO = ${SHELL} /home/splendour/projects/folm/build-aux/missing makeinfo
MAKENSIS =
MANIFEST_TOOL = :
MINIUPNPC_CPPFLAGS =
Expand Down Expand Up @@ -1440,11 +1441,11 @@ X11XCB_CFLAGS =
X11XCB_LIBS =
XGETTEXT = /usr/bin/xgettext
ZMQ_CFLAGS =
ZMQ_LIBS =
abs_builddir = /home/folm/folm/src
abs_srcdir = /home/folm/folm/src
abs_top_builddir = /home/folm/folm
abs_top_srcdir = /home/folm/folm
ZMQ_LIBS = -lzmq
abs_builddir = /home/splendour/projects/folm/src
abs_srcdir = /home/splendour/projects/folm/src
abs_top_builddir = /home/splendour/projects/folm
abs_top_srcdir = /home/splendour/projects/folm
ac_ct_AR = ar
ac_ct_CC = gcc
ac_ct_CXX = g++
Expand Down Expand Up @@ -1476,7 +1477,7 @@ host_vendor = pc
htmldir = ${docdir}
includedir = ${prefix}/include
infodir = ${datarootdir}/info
install_sh = ${SHELL} /home/folm/folm/build-aux/install-sh
install_sh = ${SHELL} /home/splendour/projects/folm/build-aux/install-sh
libdir = ${exec_prefix}/lib
libexecdir = ${exec_prefix}/libexec
localedir = ${datarootdir}/locale
Expand Down Expand Up @@ -1545,6 +1546,9 @@ BITCOIN_CORE_H = \
compat.h \
compat/sanity.h \
compressor.h \
consensus/consensus.h \
consensus/params.h \
consensus/validation.h \
primitives/block.h \
primitives/transaction.h \
core_io.h \
Expand Down Expand Up @@ -1659,13 +1663,13 @@ libbitcoin_server_a_SOURCES = \
$(JSON_H) \
$(BITCOIN_CORE_H)

#LIBBITCOIN_ZMQ = libbitcoin_zmq.a
#libbitcoin_zmq_a_CPPFLAGS = $(BITCOIN_INCLUDES) $(ZMQ_CFLAGS)
#libbitcoin_zmq_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
#libbitcoin_zmq_a_SOURCES = \
# zmq/zmqabstractnotifier.cpp \
# zmq/zmqnotificationinterface.cpp \
# zmq/zmqpublishnotifier.cpp
LIBBITCOIN_ZMQ = libbitcoin_zmq.a
libbitcoin_zmq_a_CPPFLAGS = $(BITCOIN_INCLUDES) $(ZMQ_CFLAGS)
libbitcoin_zmq_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_zmq_a_SOURCES = \
zmq/zmqabstractnotifier.cpp \
zmq/zmqnotificationinterface.cpp \
zmq/zmqpublishnotifier.cpp


# wallet: shared between folmd and folm-qt, but only linked
Expand Down
3 changes: 3 additions & 0 deletions src/Makefile.am
Expand Up @@ -94,6 +94,9 @@ BITCOIN_CORE_H = \
compat.h \
compat/sanity.h \
compressor.h \
consensus/consensus.h \
consensus/params.h \
consensus/validation.h \
primitives/block.h \
primitives/transaction.h \
core_io.h \
Expand Down
63 changes: 63 additions & 0 deletions src/consensus/consensus.h
@@ -0,0 +1,63 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_CONSENSUS_CONSENSUS_H
#define BITCOIN_CONSENSUS_CONSENSUS_H

/** The maximum allowed size for a serialized block, in bytes (network rule) */
static const unsigned int MAX_BLOCK_SIZE = 4000000;
/** The maximum allowed number of signature check operations in a block (network rule) */
static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
static const int COINBASE_MATURITY = 100;
/** Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp. */
static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC

/** Default for -blockmaxsize and -blockminsize, which control the range of sizes the mining code will create **/
static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 750000;
static const unsigned int DEFAULT_BLOCK_MIN_SIZE = 0;
/** Default for -blockprioritysize, maximum space for zero/low-fee transactions **/
static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 50000;
/** Default for accepting alerts from the P2P network. */
static const bool DEFAULT_ALERTS = true;
/** The maximum size for transactions we're willing to relay/mine */
static const unsigned int MAX_STANDARD_TX_SIZE = 100000;
/** Maximum number of signature check operations in an IsStandard() P2SH script */
static const unsigned int MAX_P2SH_SIGOPS = 15;
/** The maximum number of sigops we're willing to relay/mine in a single tx */
static const unsigned int MAX_TX_SIGOPS = MAX_BLOCK_SIGOPS / 5;
/** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
/** The maximum size of a blk?????.dat file (since 0.8) */
static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
/** The pre-allocation chunk size for blk?????.dat files (since 0.8) */
static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
/** The pre-allocation chunk size for rev?????.dat files (since 0.8) */
static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
/** Maximum number of script-checking threads allowed */
static const int MAX_SCRIPTCHECK_THREADS = 16;
/** -par default (number of script-checking threads, 0 = auto) */
static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
/** Number of blocks that can be requested at any given time from a single peer. */
static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16;
/** Timeout in seconds during which a peer must stall block download progress before being disconnected. */
static const unsigned int BLOCK_STALLING_TIMEOUT = 2;
/** Number of headers sent in one getheaders result. We rely on the assumption that if a peer sends
* less than this number, we reached their tip. Changing this value is a protocol upgrade. */
static const unsigned int MAX_HEADERS_RESULTS = 2000;
/** Size of the "block download window": how far ahead of our current height do we fetch?
* Larger windows tolerate larger download speed differences between peer, but increase the potential
* degree of disordering of blocks on disk (which make reindexing and in the future perhaps pruning
* harder). We'll probably want to make this a per-peer adaptive value at some point. */
static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
/** Time to wait (in seconds) between writing blockchain state to disk. */
static const unsigned int DATABASE_WRITE_INTERVAL = 3600;
/** Maximum length of reject messages. */
static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;

static const bool DEFAULT_PEERBLOOMFILTERS = true;


#endif // BITCOIN_CONSENSUS_CONSENSUS_H
87 changes: 87 additions & 0 deletions src/consensus/validation.h
@@ -0,0 +1,87 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_CONSENSUS_VALIDATION_H
#define BITCOIN_CONSENSUS_VALIDATION_H

#include <string>

/** "reject" message codes */
static const unsigned char REJECT_MALFORMED = 0x01;
static const unsigned char REJECT_INVALID = 0x10;
static const unsigned char REJECT_OBSOLETE = 0x11;
static const unsigned char REJECT_DUPLICATE = 0x12;
static const unsigned char REJECT_NONSTANDARD = 0x40;
static const unsigned char REJECT_DUST = 0x41;
static const unsigned char REJECT_INSUFFICIENTFEE = 0x42;
static const unsigned char REJECT_CHECKPOINT = 0x43;
/** Capture information about block/transaction validation */
class CValidationState
{
private:
enum mode_state {
MODE_VALID, //! everything ok
MODE_INVALID, //! network rule violation (DoS value may be set)
MODE_ERROR, //! run-time error
} mode;
int nDoS;
std::string strRejectReason;
unsigned char chRejectCode;
bool corruptionPossible;

public:
CValidationState() : mode(MODE_VALID), nDoS(0), chRejectCode(0), corruptionPossible(false) {}
bool DoS(int level, bool ret = false, unsigned char chRejectCodeIn = 0, std::string strRejectReasonIn = "", bool corruptionIn = false)
{
chRejectCode = chRejectCodeIn;
strRejectReason = strRejectReasonIn;
corruptionPossible = corruptionIn;
if (mode == MODE_ERROR)
return ret;
nDoS += level;
mode = MODE_INVALID;
return ret;
}
bool Invalid(bool ret = false,
unsigned char _chRejectCode = 0,
std::string _strRejectReason = "")
{
return DoS(0, ret, _chRejectCode, _strRejectReason);
}
bool Error(std::string strRejectReasonIn = "")
{
if (mode == MODE_VALID)
strRejectReason = strRejectReasonIn;
mode = MODE_ERROR;
return false;
}
bool IsValid() const
{
return mode == MODE_VALID;
}
bool IsInvalid() const
{
return mode == MODE_INVALID;
}
bool IsError() const
{
return mode == MODE_ERROR;
}
bool IsInvalid(int& nDoSOut) const
{
if (IsInvalid()) {
nDoSOut = nDoS;
return true;
}
return false;
}
bool CorruptionPossible() const
{
return corruptionPossible;
}
unsigned char GetRejectCode() const { return chRejectCode; }
std::string GetRejectReason() const { return strRejectReason; }
};
#endif // BITCOIN_CONSENSUS_VALIDATION_H
1 change: 1 addition & 0 deletions src/init.cpp
Expand Up @@ -17,6 +17,7 @@
#include "amount.h"
#include "checkpoints.h"
#include "compat/sanity.h"
#include "consensus/validation.h"
#include "key.h"
#include "main.h"
#include "masternode-budget.h"
Expand Down

0 comments on commit ee78fd8

Please sign in to comment.