diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..cd602b2
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,17 @@
+# Copyright (c) 2023 Bank of Italy
+# Distributed under the GNU AGPLv3 software license, see the accompanying COPYING file.
+
+---
+Language: Cpp
+BasedOnStyle: LLVM
+
+# The rules of the base style above can be explicitly viewed via:
+# clang-format --style llvm --dump-config
+#
+# The following are the project-specific rules
+ColumnLimit: 110
+InsertBraces: true
+# LineEnding: LF # requires clang-format >= 16, and ubuntu 22.04 has clang-format 15 at best
+# InsertNewlineAtEOF: true # requires clang-format >= 16, and ubuntu 22.04 has clang-format 15 at best
+PointerAlignment: Left
+...
diff --git a/.dockerignore b/.dockerignore
index 241dd5b..2ae211d 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -22,10 +22,12 @@
# is explicitly mentioned in the Dockerfile) or will not grab it (if the
# file is indirectly referenced through a wildcard).
+!/.clang-format
!/cmake
!/CMakeLists.txt
!/engine
!/infra
+!/Makefile
!/README.md
!/scripts
!/specs
diff --git a/.github/workflows/check-code-formatting.yml b/.github/workflows/check-code-formatting.yml
new file mode 100644
index 0000000..1944f21
--- /dev/null
+++ b/.github/workflows/check-code-formatting.yml
@@ -0,0 +1,27 @@
+name: Check code formatting
+
+on:
+ push:
+ branches:
+ - main
+ pull_request:
+ # Allows you to run this workflow manually from the Actions tab
+ workflow_dispatch:
+
+jobs:
+ check_format:
+ runs-on: ubuntu-22.04
+ steps:
+ - name: Setup clang-format 15 (we'd like 16, but as of 2023-09-29 it's not there)
+ run: |
+ # TODO: once clang-16 becomes available, please enable the rules that
+ # are currently commented in /.clang_format
+ sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 10
+ sudo update-alternatives --set clang-format /usr/bin/clang-format-15
+ - name: Checkout itcoin-fbft
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: 1
+ - name: check code formatting
+ run: |
+ make check-code-formatting
diff --git a/Dockerfile.fedora38 b/Dockerfile.fedora38
index 3d05df1..850415c 100644
--- a/Dockerfile.fedora38
+++ b/Dockerfile.fedora38
@@ -7,6 +7,7 @@ FROM fedora:38
RUN dnf install -y \
autoconf \
automake \
+ clang-tools-extra \
cmake \
g++ \
gcc \
@@ -48,6 +49,8 @@ WORKDIR /itcoin-fbft
COPY . /itcoin-fbft
+RUN make check-code-formatting
+
RUN mkdir /itcoin-fbft/build
WORKDIR /itcoin-fbft/build
diff --git a/Dockerfile.ubuntu22.04 b/Dockerfile.ubuntu22.04
index 87de3eb..37369e4 100644
--- a/Dockerfile.ubuntu22.04
+++ b/Dockerfile.ubuntu22.04
@@ -9,6 +9,7 @@ RUN apt update && apt install --no-install-recommends -y \
automake \
bsdextrautils \
ca-certificates \
+ clang-format-15 \
cmake \
g++ \
gcc \
@@ -38,12 +39,18 @@ RUN apt install --no-install-recommends -y \
libzmq3-dev \
swi-prolog
+# link clang-format-15 as clang-format
+RUN update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 10 && \
+ update-alternatives --set clang-format /usr/bin/clang-format-15
+
RUN mkdir /itcoin-fbft
WORKDIR /itcoin-fbft
COPY . /itcoin-fbft
+RUN make check-code-formatting
+
RUN mkdir /itcoin-fbft/build
WORKDIR /itcoin-fbft/build
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..c6919e8
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,50 @@
+# Copyright (c) 2023 Bank of Italy
+# Distributed under the GNU AGPLv3 software license, see the accompanying COPYING file.
+
+.DEFAULT_GOAL := help
+
+# source: https://stackoverflow.com/questions/18136918/how-to-get-current-relative-directory-of-your-makefile#73509979
+MAKEFILE_ABS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
+
+define PRINT_HELP_PYSCRIPT
+import re, sys
+
+for line in sys.stdin:
+ match = re.match(r'^([0-9a-zA-Z_-]+):.*?## (.*)$$', line)
+ if match:
+ target, help = match.groups()
+ print("%-20s %s" % (target, help))
+endef
+export PRINT_HELP_PYSCRIPT
+
+# source: https://stackoverflow.com/questions/5618615/check-if-a-program-exists-from-a-makefile#25668869
+#
+# please note that there should not be any tabs before the "ifeq/endif"
+# statement
+.PHONY: verify-prerequisites
+verify-prerequisites:
+ifeq (, $(shell command -v clang-format 2> /dev/null))
+ $(error ERROR: please install clang-format)
+endif
+
+.PHONY: check-code-formatting
+# - globstar: enable recursive globbing via "**" in bash >= 4 (equivalent to
+# shopt -s globstar)
+# - nullglob: when a glob does not match anything, return "" instead of the
+# literal glob text (equivalent to shopt -s globstar)
+SHELL = /usr/bin/env bash -O globstar -O nullglob
+check-code-formatting: verify-prerequisites ## Check if the code base is correctly formatted. Do not touch the files
+ clang-format --Werror --style=file:.clang-format --ferror-limit=20 --dry-run "${MAKEFILE_ABS_DIR}"/src/*/*.{h,hpp,c,cpp}
+
+.PHONY: reformat-code
+# - globstar: enable recursive globbing via "**" in bash >= 4 (equivalent to
+# shopt -s globstar)
+# - nullglob: when a glob does not match anything, return "" instead of the
+# literal glob text (equivalent to shopt -s globstar)
+SHELL = /usr/bin/env bash -O globstar -O nullglob
+reformat-code: verify-prerequisites ## Reformat the code base in the src directory. Can be used as pre-commit hook
+ clang-format --Werror --style=file:.clang-format -i --verbose "${MAKEFILE_ABS_DIR}"/src/**/*.{h,hpp,c,cpp}
+
+.PHONY: help
+help:
+ @python3 -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
diff --git a/README.md b/README.md
index a44344c..b854205 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,7 @@
# Frosted Byzantine Fault Tolerance (FBFT)
[![tests](https://github.com/bancaditalia/itcoin-fbft/actions/workflows/test-itcoin-fbft.yml/badge.svg?branch=main&event=push)](https://github.com/bancaditalia/itcoin-fbft/actions/workflows/test-itcoin-fbft.yml)
+[![clang-format](https://github.com/bancaditalia/itcoin-fbft/actions/workflows/check-code-formatting.yml/badge.svg?branch=main&event=push)](https://github.com/bancaditalia/itcoin-fbft/actions/workflows/check-code-formatting.yml)
This repository contains the implementation of an itcoin "consensus node",
which implements the Frosted Byzantine Fault Tolerance (FBFT) Proof-of-Authority consensus algorithm for the **itcoin** blockchain.
@@ -14,12 +15,15 @@ Please note that this software is solely intended for testing and experimentatio
1. Install build and dev dependencies with apt (system-wide):
+TODO: add documentation about clang-format in this file
+
```
sudo apt install --no-install-recommends -y \
autoconf \
automake \
bsdextrautils \
ca-certificates \
+ clang-format-15 \
cmake \
g++ \
gcc \
diff --git a/src/blockchain/BitcoinBlockchain.cpp b/src/blockchain/BitcoinBlockchain.cpp
index e1f7a57..843f0e6 100644
--- a/src/blockchain/BitcoinBlockchain.cpp
+++ b/src/blockchain/BitcoinBlockchain.cpp
@@ -6,9 +6,9 @@
#include
#include
+#include "../transport/btcclient.h"
#include "config/FbftConfig.h"
#include "generate.h"
-#include "../transport/btcclient.h"
using namespace std;
using namespace itcoin::blockchain;
@@ -16,130 +16,83 @@ using namespace itcoin::blockchain;
namespace itcoin {
namespace blockchain {
-BitcoinBlockchain::BitcoinBlockchain(const itcoin::FbftConfig& conf, transport::BtcClient& bitcoind):
-Blockchain(conf), m_bitcoind(bitcoind)
-{
+BitcoinBlockchain::BitcoinBlockchain(const itcoin::FbftConfig& conf, transport::BtcClient& bitcoind)
+ : Blockchain(conf), m_bitcoind(bitcoind) {
m_reward_address = m_conf.replica_set_v().at(m_conf.id()).p2pkh();
- BOOST_LOG_TRIVIAL(debug) << str(
- boost::format("R%1% BitcoinBlockchain, using reward address %2%.")
- % m_conf.id()
- % m_reward_address
- );
+ BOOST_LOG_TRIVIAL(debug) << str(boost::format("R%1% BitcoinBlockchain, using reward address %2%.") %
+ m_conf.id() % m_reward_address);
}
-CBlock BitcoinBlockchain::GenerateBlock(uint32_t block_timestamp)
-{
+CBlock BitcoinBlockchain::GenerateBlock(uint32_t block_timestamp) {
return generateBlock(m_bitcoind, m_reward_address, block_timestamp);
}
-bool BitcoinBlockchain::TestBlockValidity(const uint32_t height, const CBlock& block, bool check_signet_solution)
-{
+bool BitcoinBlockchain::TestBlockValidity(const uint32_t height, const CBlock& block,
+ bool check_signet_solution) {
auto block_ser = HexSerializableCBlock(block);
const uint32_t block_size_bytes = block_ser.GetHex().length() / 2;
const std::string block_hash = block.GetBlockHeader().GetHash().ToString();
BOOST_LOG_TRIVIAL(debug) << str(
- boost::format("R%1% BitcoinBlockchain::TestBlockValidity invoking for "
- "candidate block at height %2%, blocksize %3% bytes, block hash: %4%")
- % m_conf.id()
- % height
- % block_size_bytes
- % block_hash
- );
+ boost::format("R%1% BitcoinBlockchain::TestBlockValidity invoking for "
+ "candidate block at height %2%, blocksize %3% bytes, block hash: %4%") %
+ m_conf.id() % height % block_size_bytes % block_hash);
Json::Value result;
- try
- {
+ try {
result = m_bitcoind.testblockvalidity(block_ser.GetHex(), check_signet_solution);
- }
- catch (jsonrpc::JsonRpcException& e) {
- BOOST_LOG_TRIVIAL(warning) << str(
- boost::format("R%1% BitcoinBlockchain::TestBlockValidity for candidate "
- "block at height %2% with hash %3% raised %4%.")
- % m_conf.id()
- % height
- % block_hash
- % e.what()
- );
+ } catch (jsonrpc::JsonRpcException& e) {
+ BOOST_LOG_TRIVIAL(warning) << str(boost::format("R%1% BitcoinBlockchain::TestBlockValidity for candidate "
+ "block at height %2% with hash %3% raised %4%.") %
+ m_conf.id() % height % block_hash % e.what());
return false;
}
BOOST_LOG_TRIVIAL(debug) << str(
- boost::format("R%1% BitcoinBlockchain::TestBlockValidity for candidate "
- "block at height %2% with hash %3%. Result = %4% (null means ok).")
- % m_conf.id()
- % height
- % block_hash
- % result
- );
+ boost::format("R%1% BitcoinBlockchain::TestBlockValidity for candidate "
+ "block at height %2% with hash %3%. Result = %4% (null means ok).") %
+ m_conf.id() % height % block_hash % result);
return true;
}
-void BitcoinBlockchain::SubmitBlock(const uint32_t height, const CBlock& block)
-{
+void BitcoinBlockchain::SubmitBlock(const uint32_t height, const CBlock& block) {
const auto block_ser = HexSerializableCBlock(block);
const std::string block_hash = block.GetBlockHeader().GetHash().ToString();
try {
const uint32_t block_size_bytes = block_ser.GetHex().length() / 2;
BOOST_LOG_TRIVIAL(debug) << str(
- boost::format(
- "R%1% BitcoinBlockchain::SubmitBlock submitting block at height %2% "
- "block size: %3% bytes, block hash: %4%"
- )
- % m_conf.id()
- % height
- % block_size_bytes
- % block_hash
- );
+ boost::format("R%1% BitcoinBlockchain::SubmitBlock submitting block at height %2% "
+ "block size: %3% bytes, block hash: %4%") %
+ m_conf.id() % height % block_size_bytes % block_hash);
auto result = m_bitcoind.submitblock(block_ser.GetHex());
- BOOST_LOG_TRIVIAL(debug) << str(
- boost::format("R%1% BitcoinBlockchain::SubmitBlock for block at height "
- "%2%, block hash: %3%. Result = %4% (null means ok).")
- % m_conf.id()
- % height
- % block_hash
- % result
- );
- }
- catch (const jsonrpc::JsonRpcException& e)
- {
- if (e.GetMessage() == "The response is invalid: \"duplicate\"\n")
- {
+ BOOST_LOG_TRIVIAL(debug) << str(boost::format("R%1% BitcoinBlockchain::SubmitBlock for block at height "
+ "%2%, block hash: %3%. Result = %4% (null means ok).") %
+ m_conf.id() % height % block_hash % result);
+ } catch (const jsonrpc::JsonRpcException& e) {
+ if (e.GetMessage() == "The response is invalid: \"duplicate\"\n") {
BOOST_LOG_TRIVIAL(warning) << str(
- boost::format("R%1% BitcoinBlockchain::SubmitBlock the submitblock "
- "invocation for block height %2% (hash %3%) failed because the block "
- "was already in the blockchain. Most probably another replica already "
- "submitted the same block and was propagated to the local node before "
- "the submitblock call was attempted.")
- % m_conf.id()
- % height
- % block_hash
- );
- }
- else if (e.GetMessage() == "The response is invalid: \"inconclusive\"\n") {
+ boost::format("R%1% BitcoinBlockchain::SubmitBlock the submitblock "
+ "invocation for block height %2% (hash %3%) failed because the block "
+ "was already in the blockchain. Most probably another replica already "
+ "submitted the same block and was propagated to the local node before "
+ "the submitblock call was attempted.") %
+ m_conf.id() % height % block_hash);
+ } else if (e.GetMessage() == "The response is invalid: \"inconclusive\"\n") {
BOOST_LOG_TRIVIAL(warning) << str(
- boost::format("R%1% BitcoinBlockchain::SubmitBlock the submitblock "
- "invocation for height %2% (hash %3%) returned 'inconclusive'. This "
- "problem is temporarily ignored.")
- % m_conf.id()
- % height
- % block_hash
- );
- }
- else {
+ boost::format("R%1% BitcoinBlockchain::SubmitBlock the submitblock "
+ "invocation for height %2% (hash %3%) returned 'inconclusive'. This "
+ "problem is temporarily ignored.") %
+ m_conf.id() % height % block_hash);
+ } else {
BOOST_LOG_TRIVIAL(error) << str(
- boost::format("R%1% BitcoinBlockchain::SubmitBlock got exception "
- "while trying to submit block at height %2% (hash %3%): %4%")
- % m_conf.id()
- % height
- % block_hash
- % e.what()
- );
+ boost::format("R%1% BitcoinBlockchain::SubmitBlock got exception "
+ "while trying to submit block at height %2% (hash %3%): %4%") %
+ m_conf.id() % height % block_hash % e.what());
throw e;
}
}
}
-}
-}
+} // namespace blockchain
+} // namespace itcoin
diff --git a/src/blockchain/Blockchain.cpp b/src/blockchain/Blockchain.cpp
index 1813fa3..56a3e54 100644
--- a/src/blockchain/Blockchain.cpp
+++ b/src/blockchain/Blockchain.cpp
@@ -6,10 +6,7 @@
namespace itcoin {
namespace blockchain {
-Blockchain::Blockchain(const itcoin::FbftConfig& conf):
-m_conf(conf)
-{
-}
+Blockchain::Blockchain(const itcoin::FbftConfig& conf) : m_conf(conf) {}
-}
-}
+} // namespace blockchain
+} // namespace itcoin
diff --git a/src/blockchain/HexSerializableCBlock.cpp b/src/blockchain/HexSerializableCBlock.cpp
index 5d507fb..eb997da 100644
--- a/src/blockchain/HexSerializableCBlock.cpp
+++ b/src/blockchain/HexSerializableCBlock.cpp
@@ -13,36 +13,22 @@ using namespace std;
namespace itcoin {
namespace blockchain {
-HexSerializableCBlock::HexSerializableCBlock()
-{
+HexSerializableCBlock::HexSerializableCBlock() {}
-}
-
-HexSerializableCBlock::HexSerializableCBlock(CBlock block):
-CBlock(block)
-{
-
-}
+HexSerializableCBlock::HexSerializableCBlock(CBlock block) : CBlock(block) {}
-HexSerializableCBlock::HexSerializableCBlock(std::string block_hex)
-{
+HexSerializableCBlock::HexSerializableCBlock(std::string block_hex) {
std::string block_str = utils::hexToString(block_hex);
- Span block_span {
- reinterpret_cast(&block_str[0]),
- block_str.size()
- };
- CDataStream dataStream {
- block_span, SER_NETWORK, PROTOCOL_VERSION
- };
+ Span block_span{reinterpret_cast(&block_str[0]), block_str.size()};
+ CDataStream dataStream{block_span, SER_NETWORK, PROTOCOL_VERSION};
this->Unserialize(dataStream);
}
-std::string HexSerializableCBlock::GetHex() const
-{
+std::string HexSerializableCBlock::GetHex() const {
CDataStream dataStream{SER_NETWORK, PROTOCOL_VERSION};
this->Serialize(dataStream);
return utils::stringToHex(dataStream.str());
}
-}
-}
+} // namespace blockchain
+} // namespace itcoin
diff --git a/src/blockchain/blockchain.h b/src/blockchain/blockchain.h
index c54f2f7..cc9d744 100644
--- a/src/blockchain/blockchain.h
+++ b/src/blockchain/blockchain.h
@@ -7,53 +7,52 @@
#include
namespace itcoin {
- class FbftConfig;
+class FbftConfig;
}
-namespace itcoin { namespace transport {
- class BtcClient;
-}} // namespace itcoin::transport
+namespace itcoin {
+namespace transport {
+class BtcClient;
+}
+} // namespace itcoin
namespace itcoin {
namespace blockchain {
-class HexSerializableCBlock: public CBlock
-{
- public:
- HexSerializableCBlock();
- HexSerializableCBlock(CBlock block);
- HexSerializableCBlock(std::string block_hex);
- std::string GetHex() const;
+class HexSerializableCBlock : public CBlock {
+public:
+ HexSerializableCBlock();
+ HexSerializableCBlock(CBlock block);
+ HexSerializableCBlock(std::string block_hex);
+ std::string GetHex() const;
};
-class Blockchain
-{
- public:
- Blockchain(const itcoin::FbftConfig& conf);
+class Blockchain {
+public:
+ Blockchain(const itcoin::FbftConfig& conf);
- virtual CBlock GenerateBlock(uint32_t block_timestamp) = 0;
- virtual bool TestBlockValidity(const uint32_t height, const CBlock&, bool check_signet_solution) = 0;
- virtual void SubmitBlock(const uint32_t height, const CBlock&) = 0;
+ virtual CBlock GenerateBlock(uint32_t block_timestamp) = 0;
+ virtual bool TestBlockValidity(const uint32_t height, const CBlock&, bool check_signet_solution) = 0;
+ virtual void SubmitBlock(const uint32_t height, const CBlock&) = 0;
- protected:
- const itcoin::FbftConfig& m_conf;
+protected:
+ const itcoin::FbftConfig& m_conf;
};
-class BitcoinBlockchain: public Blockchain
-{
- public:
- BitcoinBlockchain(const itcoin::FbftConfig& conf, transport::BtcClient& bitcoind);
+class BitcoinBlockchain : public Blockchain {
+public:
+ BitcoinBlockchain(const itcoin::FbftConfig& conf, transport::BtcClient& bitcoind);
- CBlock GenerateBlock(uint32_t block_timestamp);
- bool TestBlockValidity(const uint32_t height, const CBlock& block, bool check_signet_solution);
- void SubmitBlock(const uint32_t height, const CBlock& block);
+ CBlock GenerateBlock(uint32_t block_timestamp);
+ bool TestBlockValidity(const uint32_t height, const CBlock& block, bool check_signet_solution);
+ void SubmitBlock(const uint32_t height, const CBlock& block);
- protected:
- transport::BtcClient& m_bitcoind;
- std::string m_reward_address;
+protected:
+ transport::BtcClient& m_bitcoind;
+ std::string m_reward_address;
};
-}
-}
+} // namespace blockchain
+} // namespace itcoin
#endif // ITCOIN_BLOCKCHAIN_BLOCKCHAIN_H
diff --git a/src/blockchain/extract.cpp b/src/blockchain/extract.cpp
index 6b834f9..48bcaf9 100644
--- a/src/blockchain/extract.cpp
+++ b/src/blockchain/extract.cpp
@@ -10,11 +10,10 @@
#include
#include
+namespace itcoin {
+namespace blockchain {
-namespace itcoin { namespace blockchain {
-
-void appendSignetSolution(CBlock *block, std::vector signetSolution)
-{
+void appendSignetSolution(CBlock* block, std::vector signetSolution) {
/*
* Append the signet solution
*
@@ -51,9 +50,8 @@ void appendSignetSolution(CBlock *block, std::vector signetSoluti
block->vtx[0] = MakeTransactionRef(tx);
}
-
-std::pair signetTxs(const CBlock& block, const std::string& signetChallengeHex)
-{
+std::pair signetTxs(const CBlock& block,
+ const std::string& signetChallengeHex) {
// assumes signet solution has not been added yet so does not need to be removed
// ITCOIN_SPECIFIC START
// assumes SIGNET_HEADER has already been added so does not need to be added here
@@ -112,5 +110,5 @@ std::pair signetTxs(const CBlock& bloc
return std::make_pair(spend, to_spend);
} // signetTxs()
-
-}} // namespace itcoin::blockchain
+} // namespace blockchain
+} // namespace itcoin
diff --git a/src/blockchain/extract.h b/src/blockchain/extract.h
index 392240d..30f123e 100644
--- a/src/blockchain/extract.h
+++ b/src/blockchain/extract.h
@@ -6,15 +6,20 @@
#include
-namespace itcoin { namespace transport {
- class BtcClient;
-}} // namespace itcoin::transport
+namespace itcoin {
+namespace transport {
+class BtcClient;
+}
+} // namespace itcoin
-namespace itcoin { namespace blockchain {
+namespace itcoin {
+namespace blockchain {
-void appendSignetSolution(CBlock *block, std::vector signetSolution);
-std::pair signetTxs(const CBlock& block, const std::string& signetChallengeHex);
+void appendSignetSolution(CBlock* block, std::vector signetSolution);
+std::pair signetTxs(const CBlock& block,
+ const std::string& signetChallengeHex);
-}} // namespace itcoin::blockchain
+} // namespace blockchain
+} // namespace itcoin
#endif // ITCOIN_BLOCKCHAIN_EXTRACT_H
diff --git a/src/blockchain/generate.cpp b/src/blockchain/generate.cpp
index 39e590e..c2c809b 100644
--- a/src/blockchain/generate.cpp
+++ b/src/blockchain/generate.cpp
@@ -13,10 +13,11 @@
#include
#include "../transport/btcclient.h"
-#include "grind.h"
#include "../utils/utils.h"
+#include "grind.h"
-namespace itcoin { namespace blockchain {
+namespace itcoin {
+namespace blockchain {
const std::vector WITNESS_COMMITMENT_HEADER = {0xaa, 0x21, 0xa9, 0xed};
@@ -24,13 +25,13 @@ const std::vector WITNESS_COMMITMENT_HEADER = {0xaa, 0x21, 0xa9,
*
* Get block template from the Bitcoin node with Signet and SegWit rules.
*
- * This code mimics https://github.com/bancaditalia/itcoin-core/blob/2f37bb2000665da31e4f45ebcdbfd059b1f3b2df/contrib/signet/miner.py#L368
+ * This code mimics
+ * https://github.com/bancaditalia/itcoin-core/blob/2f37bb2000665da31e4f45ebcdbfd059b1f3b2df/contrib/signet/miner.py#L368
*
* @param bitcoindClient
* @return the block template
*/
-Json::Value getSignetAndSegwitBlockTemplate(transport::BtcClient& bitcoindClient)
-{
+Json::Value getSignetAndSegwitBlockTemplate(transport::BtcClient& bitcoindClient) {
Json::Value root;
Json::Value rules;
@@ -45,10 +46,11 @@ Json::Value getSignetAndSegwitBlockTemplate(transport::BtcClient& bitcoindClient
* Bitcoin script opcodes can represent numeric literals between 0 and 16
* inclusive (0 is a special case). This function performs the encoding.
*/
-uint64_t encodeOpN(uint64_t number)
-{
- if (not (0 <= number && number <= 16)) {
- throw std::runtime_error("Only numbers between 0 and 16 inclusive can be represented as OP_XX opcodes. Got " + std::to_string(number));
+uint64_t encodeOpN(uint64_t number) {
+ if (not(0 <= number && number <= 16)) {
+ throw std::runtime_error(
+ "Only numbers between 0 and 16 inclusive can be represented as OP_XX opcodes. Got " +
+ std::to_string(number));
}
if (number == 0) {
@@ -58,8 +60,7 @@ uint64_t encodeOpN(uint64_t number)
return OP_1 + number - 1;
} // encodeOpN()
-CScript getScriptBIP34CoinbaseHeight(uint64_t height)
-{
+CScript getScriptBIP34CoinbaseHeight(uint64_t height) {
CScript result = CScript();
if (height <= 16) {
@@ -78,8 +79,7 @@ CScript getScriptBIP34CoinbaseHeight(uint64_t height)
return result;
} // getScriptBIP34CoinbaseHeight()
-CTransactionRef buildCoinbaseTransaction(uint64_t height, CAmount value, CScript scriptPubKey)
-{
+CTransactionRef buildCoinbaseTransaction(uint64_t height, CAmount value, CScript scriptPubKey) {
auto tx = CMutableTransaction();
tx.nVersion = 1;
tx.vin.resize(1);
@@ -95,8 +95,7 @@ CTransactionRef buildCoinbaseTransaction(uint64_t height, CAmount value, CScript
return MakeTransactionRef(tx);
} // buildCoinbaseTransaction()
-CScript getScriptPubKey(transport::BtcClient& bitcoindClient, const std::string& address)
-{
+CScript getScriptPubKey(transport::BtcClient& bitcoindClient, const std::string& address) {
// TODO avoid 'getaddressinfo' request by adding scriptPubKey of address in the configuration file
const Json::Value addressInfo = bitcoindClient.getaddressinfo(address);
const std::string scriptPubKeyHex = addressInfo["scriptPubKey"].asString();
@@ -107,16 +106,14 @@ CScript getScriptPubKey(transport::BtcClient& bitcoindClient, const std::string&
return scriptPubKey;
} // getScriptPubKey()
-CMutableTransaction TxFromHex(const std::string& str)
-{
+CMutableTransaction TxFromHex(const std::string& str) {
CMutableTransaction tx;
SpanReader{SER_NETWORK, PROTOCOL_VERSION, ParseHex(str)} >> tx;
return tx;
} // TxFromHex()
-CScript GetWitnessScript(uint256 witnessRoot, uint256 witnessNonce)
-{
+CScript GetWitnessScript(uint256 witnessRoot, uint256 witnessNonce) {
const std::vector witnessRootData(witnessRoot.begin(), witnessRoot.end());
const std::vector witnessNonceData(witnessNonce.begin(), witnessNonce.end());
std::vector concat;
@@ -136,8 +133,8 @@ CScript GetWitnessScript(uint256 witnessRoot, uint256 witnessNonce)
return CScript() << OP_RETURN << data;
} // GetWitnessScript()
-CBlock generateBlock(transport::BtcClient& bitcoindClient, const std::string& address, uint32_t block_timestamp)
-{
+CBlock generateBlock(transport::BtcClient& bitcoindClient, const std::string& address,
+ uint32_t block_timestamp) {
// create block template - START
Json::Value blockTemplate;
std::string previousBlockHash;
@@ -181,22 +178,19 @@ CBlock generateBlock(transport::BtcClient& bitcoindClient, const std::string& ad
"Network-adjusted time" is the median of the timestamps returned by all nodes connected to you.
As a result block timestamps are not exactly accurate, and they do not need to be.
Block times are accurate only to within an hour or two.
- Whenever a node connects to another node, it gets a UTC timestamp from it, and stores its offset from node-local UTC.
- The network-adjusted time is then the node-local UTC plus the median offset from all connected nodes.
- Network time is never adjusted more than 70 minutes from local system time, however.
+ Whenever a node connects to another node, it gets a UTC timestamp from it, and stores its offset from
+ node-local UTC. The network-adjusted time is then the node-local UTC plus the median offset from all
+ connected nodes. Network time is never adjusted more than 70 minutes from local system time, however.
WAS:
const uint32_t curTime = blockTemplate["curtime"].asUInt();
block.nTime = curTime < minTime? minTime: curTime;
*/
- if (block_timestamp> newHeader;
block.nNonce = newHeader.nNonce;
- BOOST_LOG_TRIVIAL(trace) << "Block merkle root (function which includes signatures) after mining: " << BlockMerkleRoot(block).GetHex();
+ BOOST_LOG_TRIVIAL(trace) << "Block merkle root (function which includes signatures) after mining: "
+ << BlockMerkleRoot(block).GetHex();
BOOST_LOG_TRIVIAL(trace) << "Grinded block: " << block.ToString();
} // mine block - END
return block;
} // generateBlock()
-}} // namespace itcoin::blockchain
+} // namespace blockchain
+} // namespace itcoin
diff --git a/src/blockchain/generate.h b/src/blockchain/generate.h
index 2f4f862..42e14ee 100644
--- a/src/blockchain/generate.h
+++ b/src/blockchain/generate.h
@@ -6,11 +6,14 @@
#include
-namespace itcoin { namespace transport {
- class BtcClient;
-}} // namespace itcoin::transport
+namespace itcoin {
+namespace transport {
+class BtcClient;
+}
+} // namespace itcoin
-namespace itcoin { namespace blockchain {
+namespace itcoin {
+namespace blockchain {
const std::vector SIGNET_HEADER_VEC = std::vector{0xec, 0xc7, 0xda, 0xa2};
@@ -36,7 +39,8 @@ const std::vector SIGNET_HEADER_VEC = std::vector{
* @param address the reward address for the coinbase transaction
* @return the generated block
*/
-CBlock generateBlock(transport::BtcClient& bitcoindClient, const std::string& address, uint32_t block_timestamp);
+CBlock generateBlock(transport::BtcClient& bitcoindClient, const std::string& address,
+ uint32_t block_timestamp);
/**
* Get the scriptPubKey of a Bitcoin address.
@@ -56,6 +60,7 @@ CScript getScriptPubKey(transport::BtcClient& bitcoindClient, const std::string&
*/
CScript GetWitnessScript(uint256 witnessRoot, uint256 witnessNonce);
-}} // namespace itcoin::blockchain
+} // namespace blockchain
+} // namespace itcoin
#endif // ITCOIN_BLOCKCHAIN_GENERATE_H
diff --git a/src/blockchain/grind.cpp b/src/blockchain/grind.cpp
index 0cc20ef..498e347 100644
--- a/src/blockchain/grind.cpp
+++ b/src/blockchain/grind.cpp
@@ -9,50 +9,51 @@
#include
#include
-void grind_task(uint32_t nBits, CBlockHeader& header_orig, uint32_t offset, uint32_t step, std::atomic& found)
-{
- arith_uint256 target;
- bool neg, over;
- target.SetCompact(nBits, &neg, &over);
- if (target == 0 || neg || over) return;
- CBlockHeader header = header_orig; // working copy
- header.nNonce = offset;
-
- uint32_t finish = std::numeric_limits::max() - step;
- finish = finish - (finish % step) + offset;
-
- while (!found && header.nNonce < finish) {
- const uint32_t next = (finish - header.nNonce < 5000*step) ? finish : header.nNonce + 5000*step;
- do {
- if (UintToArith256(header.GetHash()) <= target) {
- if (!found.exchange(true)) {
- header_orig.nNonce = header.nNonce;
- }
- return;
- }
- header.nNonce += step;
- } while(header.nNonce != next);
- }
+void grind_task(uint32_t nBits, CBlockHeader& header_orig, uint32_t offset, uint32_t step,
+ std::atomic& found) {
+ arith_uint256 target;
+ bool neg, over;
+ target.SetCompact(nBits, &neg, &over);
+ if (target == 0 || neg || over) {
+ return;
+ }
+ CBlockHeader header = header_orig; // working copy
+ header.nNonce = offset;
+
+ uint32_t finish = std::numeric_limits::max() - step;
+ finish = finish - (finish % step) + offset;
+
+ while (!found && header.nNonce < finish) {
+ const uint32_t next = (finish - header.nNonce < 5000 * step) ? finish : header.nNonce + 5000 * step;
+ do {
+ if (UintToArith256(header.GetHash()) <= target) {
+ if (!found.exchange(true)) {
+ header_orig.nNonce = header.nNonce;
+ }
+ return;
+ }
+ header.nNonce += step;
+ } while (header.nNonce != next);
+ }
}
-std::string Grind(std::string hexHeader)
-{
- CBlockHeader header;
- if (!DecodeHexBlockHeader(header, hexHeader)) {
- throw std::invalid_argument("Could not decode block header");
- }
+std::string Grind(std::string hexHeader) {
+ CBlockHeader header;
+ if (!DecodeHexBlockHeader(header, hexHeader)) {
+ throw std::invalid_argument("Could not decode block header");
+ }
- uint32_t nBits = header.nBits;
- std::atomic found{false};
+ uint32_t nBits = header.nBits;
+ std::atomic found{false};
- grind_task(nBits, std::ref(header), 0, 1, std::ref(found));
+ grind_task(nBits, std::ref(header), 0, 1, std::ref(found));
- if (!found) {
- throw std::runtime_error("Could not satisfy difficulty target");
- }
+ if (!found) {
+ throw std::runtime_error("Could not satisfy difficulty target");
+ }
- CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
- ss << header;
+ CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
+ ss << header;
- return HexStr(ss);
+ return HexStr(ss);
}
diff --git a/src/blockchain/grind.h b/src/blockchain/grind.h
index 8041107..60147ea 100644
--- a/src/blockchain/grind.h
+++ b/src/blockchain/grind.h
@@ -13,11 +13,12 @@ class CBlockHeader;
* To check that the function stays consistent as bitcoin-core evolces, one can
* run (for example in CI) scripts/check-code-consistency.py
*/
-void grind_task(uint32_t nBits, CBlockHeader& header_orig, uint32_t offset, uint32_t step, std::atomic& found);
+void grind_task(uint32_t nBits, CBlockHeader& header_orig, uint32_t offset, uint32_t step,
+ std::atomic& found);
/**
* Loosely based on Grind() in bitcoin-util.cpp
*/
std::string Grind(std::string hexHeader);
-#endif //ITCOIN_BITCOIN_CORE_GRIND_H
+#endif // ITCOIN_BITCOIN_CORE_GRIND_H
diff --git a/src/config/FbftConfig.cpp b/src/config/FbftConfig.cpp
index 9a475b2..0192102 100644
--- a/src/config/FbftConfig.cpp
+++ b/src/config/FbftConfig.cpp
@@ -23,8 +23,7 @@ namespace itcoin {
const string DEFAULT_MINER_CONF_FILENAME = "miner.conf.json";
const string DEFAULT_FBFT_DB_FILENAME = "miner.fbft.db";
-FbftConfig::FbftConfig(std::string datadir, std::string configFileName)
-{
+FbftConfig::FbftConfig(std::string datadir, std::string configFileName) {
string bitcoin_config_file = datadir + "/" + BITCOIN_CONF_FILENAME;
string miner_config_file = datadir + "/" + DEFAULT_MINER_CONF_FILENAME;
@@ -39,13 +38,22 @@ FbftConfig::FbftConfig(std::string datadir, std::string configFileName)
gArgs.ClearArgs();
// Read bitcoind configuration
- gArgs.AddArg("-datadir=", "Specify data directory. The miner will read its configuration from " + configFileName + ", and the bitcoind specific data from " + miner_config_file, ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
+ gArgs.AddArg("-datadir=",
+ "Specify data directory. The miner will read its configuration from " + configFileName +
+ ", and the bitcoind specific data from " + miner_config_file,
+ ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
SetupChainParamsBaseOptions(gArgs);
- gArgs.AddArg("-rpcpassword=", "Password for JSON-RPC connections", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
- gArgs.AddArg("-rpcport=", strprintf("Connect to JSON-RPC on "), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::OPTIONS);
- gArgs.AddArg("-rpcuser=", "Username for JSON-RPC connections", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
- gArgs.AddArg("-signetchallenge=", "The signet challenge.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
- gArgs.AddArg("-zmqpubitcoinblock=", "Enable publish hash block, height and time in (ITCOIN_SPECIFIC)", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
+ gArgs.AddArg("-rpcpassword=", "Password for JSON-RPC connections", ArgsManager::ALLOW_ANY,
+ OptionsCategory::OPTIONS);
+ gArgs.AddArg("-rpcport=", strprintf("Connect to JSON-RPC on "),
+ ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::OPTIONS);
+ gArgs.AddArg("-rpcuser=", "Username for JSON-RPC connections", ArgsManager::ALLOW_ANY,
+ OptionsCategory::OPTIONS);
+ gArgs.AddArg("-signetchallenge=", "The signet challenge.", ArgsManager::ALLOW_ANY,
+ OptionsCategory::OPTIONS);
+ gArgs.AddArg("-zmqpubitcoinblock=",
+ "Enable publish hash block, height and time in (ITCOIN_SPECIFIC)",
+ ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
// Parse bitcoind config file
gArgs.ForceSetArg("-datadir", datadir);
@@ -57,7 +65,8 @@ FbftConfig::FbftConfig(std::string datadir, std::string configFileName)
// Select the bitcoin config file section for the signet network
string chain_name = gArgs.GetChainName();
if (chain_name != "signet") {
- std::string msg = "chain_name's value is \"" + chain_name + "\", but the only allowed value is \"signet\"";
+ std::string msg =
+ "chain_name's value is \"" + chain_name + "\", but the only allowed value is \"signet\"";
BOOST_LOG_TRIVIAL(error) << msg;
throw std::runtime_error(msg);
@@ -74,14 +83,16 @@ FbftConfig::FbftConfig(std::string datadir, std::string configFileName)
// extract the TCP port from the zmqpubitcoinblock bind string in bitcoin.conf
std::string itcoinblock_bind_string = gArgs.GetArg("-zmqpubitcoinblock", "");
if (itcoinblock_bind_string == "") {
- std::string msg = "itcoin-core is not configured to send new blocks notifications via \"-zmqpubitcoinblock\" parameter. Please configure bitcoind.conf accordingly.";
+ std::string msg = "itcoin-core is not configured to send new blocks notifications via "
+ "\"-zmqpubitcoinblock\" parameter. Please configure bitcoind.conf accordingly.";
BOOST_LOG_TRIVIAL(error) << msg;
throw std::runtime_error(msg);
}
std::size_t colon_pos = itcoinblock_bind_string.find_last_of(":");
if (colon_pos == std::string::npos) {
- std::string msg = "cannot find TCP port in \"-zmqpubitcoinblock\" parameter: \"" + itcoinblock_bind_string + "\" contains no \":\"";
+ std::string msg = "cannot find TCP port in \"-zmqpubitcoinblock\" parameter: \"" +
+ itcoinblock_bind_string + "\" contains no \":\"";
BOOST_LOG_TRIVIAL(error) << msg;
throw std::runtime_error(msg);
}
@@ -91,26 +102,30 @@ FbftConfig::FbftConfig(std::string datadir, std::string configFileName)
long unsigned int itcoinblock_port = 0;
try {
itcoinblock_port = std::stoul(itcoinblock_bind_string.substr(colon_pos + 1), &consumed_chars);
- } catch(std::invalid_argument const& e) {
+ } catch (std::invalid_argument const& e) {
BOOST_LOG_TRIVIAL(error) << e.what();
consumed_chars = 0;
- } catch(std::out_of_range const& e) {
+ } catch (std::out_of_range const& e) {
BOOST_LOG_TRIVIAL(error) << e.what();
consumed_chars = 0;
}
- if ((consumed_chars == 0) || (consumed_chars < remaining_chars) || (itcoinblock_port > std::numeric_limits::max())) {
- std::string msg = "cannot extract a meaningful TCP port from \"-zmqpubitcoinblock\" (" + itcoinblock_bind_string + ")";
+ if ((consumed_chars == 0) || (consumed_chars < remaining_chars) ||
+ (itcoinblock_port > std::numeric_limits::max())) {
+ std::string msg = "cannot extract a meaningful TCP port from \"-zmqpubitcoinblock\" (" +
+ itcoinblock_bind_string + ")";
BOOST_LOG_TRIVIAL(error) << msg;
throw std::runtime_error(msg);
}
m_itcoinblock_connection_string = "tcp://" + itcoin_rpchost_ + ":" + std::to_string(itcoinblock_port);
}
- BOOST_LOG_TRIVIAL(debug) << "The value computed for connecting to the itcoinblock topic is " << m_itcoinblock_connection_string;
+ BOOST_LOG_TRIVIAL(debug) << "The value computed for connecting to the itcoinblock topic is "
+ << m_itcoinblock_connection_string;
// Parse cookie file or rpcuser and pass
if (gArgs.GetArg("-rpcpassword", "") == "") {
- BOOST_LOG_TRIVIAL(info) << "No \"-rpcpassword\" parameter was given: falling back to cookie-based authentication";
+ BOOST_LOG_TRIVIAL(info)
+ << "No \"-rpcpassword\" parameter was given: falling back to cookie-based authentication";
// Try fall back to cookie-based authentication if no password is provided
// GetAuthCookieFile
@@ -131,7 +146,8 @@ FbftConfig::FbftConfig(std::string datadir, std::string configFileName)
BOOST_LOG_TRIVIAL(info) << "JSON-RPC auth data has been read from " + fs::PathToString(filepath);
} else {
itcoin_rpc_auth_ = gArgs.GetArg("-rpcuser", "") + ":" + gArgs.GetArg("-rpcpassword", "");
- BOOST_LOG_TRIVIAL(info) << "JSON-RPC auth data has been taken from command line parameters \"-rpcuser\" and \"-rpcpassword\"";
+ BOOST_LOG_TRIVIAL(info)
+ << "JSON-RPC auth data has been taken from command line parameters \"-rpcuser\" and \"-rpcpassword\"";
}
if ((itcoin_signet_challenge_ = gArgs.GetArg("-signetchallenge", "")) == "") {
@@ -166,13 +182,13 @@ FbftConfig::FbftConfig(std::string datadir, std::string configFileName)
BOOST_LOG_TRIVIAL(debug) << "This replica will not send its message to any sniffer.";
} else {
m_sniffer_dish_connection_string = config["sniffer_dish_connection_string"].asString();
- BOOST_LOG_TRIVIAL(warning) << "Messages from this replica will also be sent to " << m_sniffer_dish_connection_string.value();
+ BOOST_LOG_TRIVIAL(warning) << "Messages from this replica will also be sent to "
+ << m_sniffer_dish_connection_string.value();
}
// Read the replica config
Json::Value replica_config_a = config["fbft_replica_set"];
- for ( unsigned int i = 0; i < replica_config_a.size(); ++i )
- {
+ for (unsigned int i = 0; i < replica_config_a.size(); ++i) {
Json::Value replica_config_json = replica_config_a[i];
string host = replica_config_json["host"].asString();
string port = replica_config_json["port"].asString();
@@ -180,16 +196,15 @@ FbftConfig::FbftConfig(std::string datadir, std::string configFileName)
string pubkey = replica_config_json["pubkey"].asString();
TransportConfig replica_config(i, host, port, p2pkh, pubkey);
- BOOST_LOG_TRIVIAL(trace) << "Read replica #" << i << " - host: " << host << ", port: " << port << ", p2pkh: " << p2pkh;
+ BOOST_LOG_TRIVIAL(trace) << "Read replica #" << i << " - host: " << host << ", port: " << port
+ << ", p2pkh: " << p2pkh;
replica_set_v_.push_back(replica_config);
}
m_cluster_size = replica_set_v_.size();
}
-const unsigned int FbftConfig::cluster_size() const {
- return m_cluster_size;
-}
+const unsigned int FbftConfig::cluster_size() const { return m_cluster_size; }
std::string FbftConfig::getSignetChallenge() const {
return this->itcoin_signet_challenge_;
diff --git a/src/config/FbftConfig.h b/src/config/FbftConfig.h
index ef9b5e7..ae94691 100644
--- a/src/config/FbftConfig.h
+++ b/src/config/FbftConfig.h
@@ -12,121 +12,115 @@
namespace itcoin {
-class TransportConfig
-{
- public:
- TransportConfig(unsigned int id, std::string host, std::string port, std::string p2pkh, std::string pubkey):
- id_(id),
- host_(host),
- port_(port),
- p2pkh_(p2pkh),
- pubkey_(pubkey)
- {}
-
- const unsigned int id() const { return id_; }
- const std::string host() const { return host_; }
- const std::string port() const { return port_; }
- const std::string p2pkh() const { return p2pkh_; }
- const std::string pubkey() const { return pubkey_; }
-
- const std::string grpc_server_uri() const { return host_ + ":" + port_; }
-
- private:
- unsigned int id_;
- std::string host_;
- std::string port_;
- std::string p2pkh_;
- std::string pubkey_;
+class TransportConfig {
+public:
+ TransportConfig(unsigned int id, std::string host, std::string port, std::string p2pkh, std::string pubkey)
+ : id_(id), host_(host), port_(port), p2pkh_(p2pkh), pubkey_(pubkey) {}
+
+ const unsigned int id() const { return id_; }
+ const std::string host() const { return host_; }
+ const std::string port() const { return port_; }
+ const std::string p2pkh() const { return p2pkh_; }
+ const std::string pubkey() const { return pubkey_; }
+
+ const std::string grpc_server_uri() const { return host_ + ":" + port_; }
+
+private:
+ unsigned int id_;
+ std::string host_;
+ std::string port_;
+ std::string p2pkh_;
+ std::string pubkey_;
}; // class TransportConfig
-class FbftConfig
-{
- public:
- FbftConfig(std::string datadir, std::string configFileName = "miner.conf.json");
-
- const uint32_t id() const {return id_;}
- const std::string genesis_block_hash() const {return m_genesis_block_hash;}
- uint32_t genesis_block_timestamp() const {return m_genesis_block_timestamp;}
- double target_block_time() const {return m_target_block_time;}
- std::string group_public_key() const {return m_group_public_key;}
-
- // Timing constants
- double C_REQUESTS_GENERATE_UNTIL_CURRENT_TIME_PLUS() const { return target_block_time(); }
- double C_PRE_PREPARE_ACCEPT_UNTIL_CURRENT_TIME_PLUS() const { return target_block_time()/10; }
-
- // Setters
- void set_replica_id(uint32_t replica_id){ id_ = replica_id; };
- void set_cluster_size(uint32_t cluster_size){ m_cluster_size = cluster_size; };
- void set_genesis_block_hash(std::string genesis_block_hash){m_genesis_block_hash = genesis_block_hash;}
- void set_genesis_block_timestamp(uint32_t genesis_block_timestamp){m_genesis_block_timestamp = genesis_block_timestamp;}
- void set_target_block_time(uint64_t target_block_time){m_target_block_time = target_block_time;}
- void set_fbft_db_reset(bool reset){ m_fbft_db_reset=reset; }
- void set_fbft_db_filename(std::string filename){ m_fbft_db_filename=filename; }
-
- // If set, zmq messages from this replica will also be sent to this dish
- const std::optional sniffer_dish_connection_string() const { return m_sniffer_dish_connection_string; }
-
- const std::string bitcoindJsonRpcEndpoint() const {
- return itcoin_rpchost_ + ":" + itcoin_rpcport_;
- }
-
- const std::string itcoin_uri() const {
- return "http://" + itcoin_rpc_auth_ + "@" + this->bitcoindJsonRpcEndpoint();
- }
-
- std::string getSignetChallenge() const;
-
- /**
- * Connection string to the itcoinblock topic exposed by the itcoin-core
- * process local to this replica.
- *
- * This value is computed from the bind string contained in the item
- * zmqpubitcoinblock in bitcoind.conf.
- *
- * For reference, see the "-zmqpubitcoinblock" option in itcoin-core and the
- * ZMQ_PUBITCOINBLOCK_PORT in the startup scripts initialize-itcoin-*.sh.
- *
- * See:
- * http://api.zeromq.org/4-3:zmq-connect
- * https://github.com/bancaditalia/itcoin-core/blob/itcoin/doc/zmq.md
- *
- * EXAMPLE:
- * tcp://127.0.0.1:8080
- */
- std::string getItcoinblockConnectionString() const { return m_itcoinblock_connection_string; }
-
- const std::vector replica_set_v() const { return replica_set_v_; }
-
- const unsigned int cluster_size() const;
-
- std::string fbft_db_filename() const { return m_fbft_db_filename; }
- bool fbft_db_reset() const { return m_fbft_db_reset; }
-
- private:
- unsigned int id_;
- uint32_t m_cluster_size;
- std::string m_genesis_block_hash;
- uint32_t m_genesis_block_timestamp;
- double m_target_block_time;
- std::string m_group_public_key;
-
- std::string itcoin_rpchost_;
- std::string itcoin_rpcport_;
- std::string itcoin_rpc_auth_;
- std::string itcoin_signet_challenge_;
- std::string m_itcoinblock_connection_string;
-
- std::vector replica_set_v_;
-
- // Fbft engine persistence
- bool m_fbft_db_reset;
- std::string m_fbft_db_filename;
-
- // If set, zmq messages from this replica will also be sent to this dish
- std::optional m_sniffer_dish_connection_string;
-
+class FbftConfig {
+public:
+ FbftConfig(std::string datadir, std::string configFileName = "miner.conf.json");
+
+ const uint32_t id() const { return id_; }
+ const std::string genesis_block_hash() const { return m_genesis_block_hash; }
+ uint32_t genesis_block_timestamp() const { return m_genesis_block_timestamp; }
+ double target_block_time() const { return m_target_block_time; }
+ std::string group_public_key() const { return m_group_public_key; }
+
+ // Timing constants
+ double C_REQUESTS_GENERATE_UNTIL_CURRENT_TIME_PLUS() const { return target_block_time(); }
+ double C_PRE_PREPARE_ACCEPT_UNTIL_CURRENT_TIME_PLUS() const { return target_block_time() / 10; }
+
+ // Setters
+ void set_replica_id(uint32_t replica_id) { id_ = replica_id; };
+ void set_cluster_size(uint32_t cluster_size) { m_cluster_size = cluster_size; };
+ void set_genesis_block_hash(std::string genesis_block_hash) { m_genesis_block_hash = genesis_block_hash; }
+ void set_genesis_block_timestamp(uint32_t genesis_block_timestamp) {
+ m_genesis_block_timestamp = genesis_block_timestamp;
+ }
+ void set_target_block_time(uint64_t target_block_time) { m_target_block_time = target_block_time; }
+ void set_fbft_db_reset(bool reset) { m_fbft_db_reset = reset; }
+ void set_fbft_db_filename(std::string filename) { m_fbft_db_filename = filename; }
+
+ // If set, zmq messages from this replica will also be sent to this dish
+ const std::optional sniffer_dish_connection_string() const {
+ return m_sniffer_dish_connection_string;
+ }
+
+ const std::string bitcoindJsonRpcEndpoint() const { return itcoin_rpchost_ + ":" + itcoin_rpcport_; }
+
+ const std::string itcoin_uri() const {
+ return "http://" + itcoin_rpc_auth_ + "@" + this->bitcoindJsonRpcEndpoint();
+ }
+
+ std::string getSignetChallenge() const;
+
+ /**
+ * Connection string to the itcoinblock topic exposed by the itcoin-core
+ * process local to this replica.
+ *
+ * This value is computed from the bind string contained in the item
+ * zmqpubitcoinblock in bitcoind.conf.
+ *
+ * For reference, see the "-zmqpubitcoinblock" option in itcoin-core and the
+ * ZMQ_PUBITCOINBLOCK_PORT in the startup scripts initialize-itcoin-*.sh.
+ *
+ * See:
+ * http://api.zeromq.org/4-3:zmq-connect
+ * https://github.com/bancaditalia/itcoin-core/blob/itcoin/doc/zmq.md
+ *
+ * EXAMPLE:
+ * tcp://127.0.0.1:8080
+ */
+ std::string getItcoinblockConnectionString() const { return m_itcoinblock_connection_string; }
+
+ const std::vector replica_set_v() const { return replica_set_v_; }
+
+ const unsigned int cluster_size() const;
+
+ std::string fbft_db_filename() const { return m_fbft_db_filename; }
+ bool fbft_db_reset() const { return m_fbft_db_reset; }
+
+private:
+ unsigned int id_;
+ uint32_t m_cluster_size;
+ std::string m_genesis_block_hash;
+ uint32_t m_genesis_block_timestamp;
+ double m_target_block_time;
+ std::string m_group_public_key;
+
+ std::string itcoin_rpchost_;
+ std::string itcoin_rpcport_;
+ std::string itcoin_rpc_auth_;
+ std::string itcoin_signet_challenge_;
+ std::string m_itcoinblock_connection_string;
+
+ std::vector replica_set_v_;
+
+ // Fbft engine persistence
+ bool m_fbft_db_reset;
+ std::string m_fbft_db_filename;
+
+ // If set, zmq messages from this replica will also be sent to this dish
+ std::optional m_sniffer_dish_connection_string;
};
} // namespace itcoin
-#endif //FBFT_CONFIG_H_
+#endif // FBFT_CONFIG_H_
diff --git a/src/fbft/Replica2.cpp b/src/fbft/Replica2.cpp
index f2ef6e1..c19324f 100644
--- a/src/fbft/Replica2.cpp
+++ b/src/fbft/Replica2.cpp
@@ -3,9 +3,9 @@
#include "Replica2.h"
-#include
#include
#include
+#include
using namespace std;
using namespace itcoin::blockchain;
@@ -16,29 +16,17 @@ using namespace itcoin::fbft::messages;
namespace itcoin {
namespace fbft {
-Replica2::Replica2(
- const itcoin::FbftConfig& config,
- Blockchain& blockchain,
- RoastWallet& wallet,
- NetworkTransport& transport,
- uint32_t start_height,
- std::string start_hash,
- uint32_t start_time
-):
-ReplicaState(config, blockchain, wallet, start_height, start_hash, start_time),
-m_transport(transport)
-{
+Replica2::Replica2(const itcoin::FbftConfig& config, Blockchain& blockchain, RoastWallet& wallet,
+ NetworkTransport& transport, uint32_t start_height, std::string start_hash,
+ uint32_t start_time)
+ : ReplicaState(config, blockchain, wallet, start_height, start_hash, start_time), m_transport(transport) {
// use current time as seed for random generator
std::srand(std::time(nullptr));
}
-const uint32_t Replica2::id() const
-{
- return m_conf.id();
-}
+const uint32_t Replica2::id() const { return m_conf.id(); }
-void Replica2::GenerateRequests()
-{
+void Replica2::GenerateRequests() {
// Constants
uint32_t genesis_block_time = m_conf.genesis_block_timestamp();
uint32_t target_block_time = m_conf.target_block_time();
@@ -52,102 +40,79 @@ void Replica2::GenerateRequests()
// This number may need to become adaptive
uint32_t MAX_NUM_GENERATED_REQUESTS = 5;
- while(
- last_req_time < current_time + MAX_NUM_GENERATED_REQUESTS*target_block_time &&
- last_req_time < last_rep_time + MAX_NUM_GENERATED_REQUESTS*target_block_time
- )
- {
+ while (last_req_time < current_time + MAX_NUM_GENERATED_REQUESTS * target_block_time &&
+ last_req_time < last_rep_time + MAX_NUM_GENERATED_REQUESTS * target_block_time) {
uint32_t req_timestamp = last_req_time + target_block_time;
BOOST_LOG_TRIVIAL(debug) << str(
- boost::format("R%1% last_req_time=%2% < current_time + delta = %3% and < last_rep_time + delta = %4%, creating request with H=%5% and T=%6%.")
- % m_conf.id()
- % last_req_time
- % (current_time + MAX_NUM_GENERATED_REQUESTS*target_block_time)
- % (last_rep_time + MAX_NUM_GENERATED_REQUESTS*target_block_time)
- % ((req_timestamp-genesis_block_time) / target_block_time)
- % req_timestamp
- );
+ boost::format("R%1% last_req_time=%2% < current_time + delta = %3% and < last_rep_time + delta = "
+ "%4%, creating request with H=%5% and T=%6%.") %
+ m_conf.id() % last_req_time % (current_time + MAX_NUM_GENERATED_REQUESTS * target_block_time) %
+ (last_rep_time + MAX_NUM_GENERATED_REQUESTS * target_block_time) %
+ ((req_timestamp - genesis_block_time) / target_block_time) % req_timestamp);
messages::Request req = messages::Request(genesis_block_time, target_block_time, req_timestamp);
actions::ReceiveRequest receive_req(m_conf.id(), req);
this->Apply(receive_req);
last_req_time = this->latest_request_time();
}
- if (last_req_time >= current_time + MAX_NUM_GENERATED_REQUESTS*target_block_time)
- {
+ if (last_req_time >= current_time + MAX_NUM_GENERATED_REQUESTS * target_block_time) {
BOOST_LOG_TRIVIAL(trace) << str(
- boost::format("R%1% last_req_time=%2% >= current_time + delta = %3%, stop creating requests.")
- % m_conf.id()
- % last_req_time
- % (current_time + MAX_NUM_GENERATED_REQUESTS*target_block_time)
- );
- }
- else
- {
+ boost::format("R%1% last_req_time=%2% >= current_time + delta = %3%, stop creating requests.") %
+ m_conf.id() % last_req_time % (current_time + MAX_NUM_GENERATED_REQUESTS * target_block_time));
+ } else {
BOOST_LOG_TRIVIAL(trace) << str(
- boost::format("R%1% last_req_time=%2% >= last_rep_time + delta = %3%, stop creating requests.")
- % m_conf.id()
- % last_req_time
- % (last_rep_time + MAX_NUM_GENERATED_REQUESTS*target_block_time)
- );
+ boost::format("R%1% last_req_time=%2% >= last_rep_time + delta = %3%, stop creating requests.") %
+ m_conf.id() % last_req_time % (last_rep_time + MAX_NUM_GENERATED_REQUESTS * target_block_time));
}
}
-void Replica2::ApplyActiveActions()
-{
+void Replica2::ApplyActiveActions() {
// We execute an active action
- uint32_t num_applied_actions = 0; uint32_t MAX_NUM_APPLIED_ACTIONS = 11;
- while (!m_active_actions.empty() && num_applied_actions action_to_apply= move(m_active_actions.at(index_random));
- this->Apply( *action_to_apply );
+ std::unique_ptr action_to_apply = move(m_active_actions.at(index_random));
+ this->Apply(*action_to_apply);
num_applied_actions += 1;
// We broadcast all messages in the output buffer
- if (!m_out_msg_buffer.empty())
- {
+ if (!m_out_msg_buffer.empty()) {
std::vector> ready_to_be_sent{};
- for (auto& p_msg: m_out_msg_buffer)
- {
+ for (auto& p_msg : m_out_msg_buffer) {
// i-th element in out_msg_buffer is nullptr after move, but still present
ready_to_be_sent.emplace_back(move(p_msg));
}
this->ClearOutMessageBuffer();
- for (auto& p_msg: ready_to_be_sent)
- {
+ for (auto& p_msg : ready_to_be_sent) {
p_msg->Sign(m_wallet);
// A special trick needs to be applied for ROAST_PRE_SIGNATURE message
// This message is sent by the ROAST coordinator to all the candidate signers of the signature session
// In 5FBFT the Primary may be both the ROAST coordinator and signer for that specific session
// In that special case, we need to inject the message in the input buffer of the coordinator
- if (p_msg->type()==MSG_TYPE::ROAST_PRE_SIGNATURE)
- {
- unique_ptr typed_msg = make_unique( dynamic_cast(*p_msg) );
+ if (p_msg->type() == MSG_TYPE::ROAST_PRE_SIGNATURE) {
+ unique_ptr typed_msg =
+ make_unique(dynamic_cast(*p_msg));
bool replica_id_found = false;
- for (uint32_t signer_id : typed_msg->signers())
- {
- if (signer_id == m_conf.id())
- {
+ for (uint32_t signer_id : typed_msg->signers()) {
+ if (signer_id == m_conf.id()) {
replica_id_found = true;
break;
}
}
- if (replica_id_found)
- {
+ if (replica_id_found) {
this->m_in_msg_buffer.emplace_back(std::move(typed_msg));
}
- }
- else if (p_msg->type()==MSG_TYPE::ROAST_SIGNATURE_SHARE)
- {
+ } else if (p_msg->type() == MSG_TYPE::ROAST_SIGNATURE_SHARE) {
// Similarly, the ROAST_SIGNATURE_SHARE should be sent to the coordinator only
// Here we ship the signature share also to current replica, in case it's the coordinator
- unique_ptr typed_msg = make_unique( dynamic_cast(*p_msg) );
+ unique_ptr typed_msg = make_unique(
+ dynamic_cast(*p_msg));
this->m_in_msg_buffer.emplace_back(std::move(typed_msg));
}
@@ -156,27 +121,17 @@ void Replica2::ApplyActiveActions()
}
}
}
- if (num_applied_actions == MAX_NUM_APPLIED_ACTIONS)
- {
- string error_msg = str(
- boost::format("R%1% exceeded the number of applied actions!")
- % id()
- );
+ if (num_applied_actions == MAX_NUM_APPLIED_ACTIONS) {
+ string error_msg = str(boost::format("R%1% exceeded the number of applied actions!") % id());
// throw(std::runtime_error(error_msg));
BOOST_LOG_TRIVIAL(error) << error_msg;
}
- BOOST_LOG_TRIVIAL(trace) << str(
- boost::format("R%1% does not have further active actions to apply.")
- % m_conf.id()
- );
+ BOOST_LOG_TRIVIAL(trace) << str(boost::format("R%1% does not have further active actions to apply.") %
+ m_conf.id());
}
-void Replica2::CheckTimedActions()
-{
- BOOST_LOG_TRIVIAL(trace) << str(
- boost::format("R%1% cycle start.")
- % m_conf.id()
- );
+void Replica2::CheckTimedActions() {
+ BOOST_LOG_TRIVIAL(trace) << str(boost::format("R%1% cycle start.") % m_conf.id());
// Generate requests
this->GenerateRequests();
@@ -188,29 +143,20 @@ void Replica2::CheckTimedActions()
// Apply active actions resulting from timeout expired
this->ApplyActiveActions();
- BOOST_LOG_TRIVIAL(trace) << str(
- boost::format("R%1% cycle end.")
- % m_conf.id()
- );
+ BOOST_LOG_TRIVIAL(trace) << str(boost::format("R%1% cycle end.") % m_conf.id());
}
-void Replica2::ReceiveIncomingMessage(std::unique_ptr msg)
-{
- BOOST_LOG_TRIVIAL(debug) << str(
- boost::format("R%1% receiving %2% from %3%.")
- % m_conf.id()
- % msg->identify()
- % msg->sender_id()
- );
+void Replica2::ReceiveIncomingMessage(std::unique_ptr msg) {
+ BOOST_LOG_TRIVIAL(debug) << str(boost::format("R%1% receiving %2% from %3%.") % m_conf.id() %
+ msg->identify() % msg->sender_id());
// Generate requests
this->GenerateRequests();
- if( msg->type()==messages::MSG_TYPE::BLOCK )
- {
+ if (msg->type() == messages::MSG_TYPE::BLOCK) {
// Checkpoint messages are not signed, since they are received upon
// receipt of a valid (hence signed) block.
- messages::Block typed_msg{ dynamic_cast(*msg) };
+ messages::Block typed_msg{dynamic_cast(*msg)};
actions::ReceiveBlock receive_block(m_conf.id(), typed_msg);
this->Apply(receive_block);
@@ -218,27 +164,18 @@ void Replica2::ReceiveIncomingMessage(std::unique_ptr msg)
// to trigger view changes
}
// Here the message is not a block, we check signature
- else if ( msg->VerifySignatures(m_wallet) )
- {
+ else if (msg->VerifySignatures(m_wallet)) {
ReplicaState::ReceiveIncomingMessage(move(msg));
// Apply active actions resulting from the received, non-block message
this->ApplyActiveActions();
- }
- else
- {
+ } else {
BOOST_LOG_TRIVIAL(error) << str(
- boost::format("R%1% received message %2% from R%3% with invalid signature, discarding.")
- % m_conf.id()
- % msg->name()
- % msg->sender_id()
- );
+ boost::format("R%1% received message %2% from R%3% with invalid signature, discarding.") %
+ m_conf.id() % msg->name() % msg->sender_id());
}
- BOOST_LOG_TRIVIAL(debug) << str(
- boost::format("R%1% receive message end.")
- % m_conf.id()
- );
+ BOOST_LOG_TRIVIAL(debug) << str(boost::format("R%1% receive message end.") % m_conf.id());
}
-}
-}
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/Replica2.h b/src/fbft/Replica2.h
index 5255e82..d92ac75 100644
--- a/src/fbft/Replica2.h
+++ b/src/fbft/Replica2.h
@@ -18,34 +18,27 @@ namespace state = itcoin::fbft::state;
namespace itcoin {
namespace fbft {
-class Replica2: public network::NetworkListener, public state::ReplicaState
-{
- public:
- Replica2(
- const itcoin::FbftConfig& config,
- blockchain::Blockchain& blockchain,
- wallet::RoastWallet& wallet,
- network::NetworkTransport& transport,
- uint32_t start_height,
- std::string start_hash,
- uint32_t start_time
- );
-
- // Getters
- const uint32_t id() const;
-
- // Operations
- void ReceiveIncomingMessage(std::unique_ptr msg);
- void CheckTimedActions();
-
- private:
- network::NetworkTransport& m_transport;
-
- void GenerateRequests();
- void ApplyActiveActions();
+class Replica2 : public network::NetworkListener, public state::ReplicaState {
+public:
+ Replica2(const itcoin::FbftConfig& config, blockchain::Blockchain& blockchain, wallet::RoastWallet& wallet,
+ network::NetworkTransport& transport, uint32_t start_height, std::string start_hash,
+ uint32_t start_time);
+
+ // Getters
+ const uint32_t id() const;
+
+ // Operations
+ void ReceiveIncomingMessage(std::unique_ptr msg);
+ void CheckTimedActions();
+
+private:
+ network::NetworkTransport& m_transport;
+
+ void GenerateRequests();
+ void ApplyActiveActions();
};
-}
-}
+} // namespace fbft
+} // namespace itcoin
#endif // ITCOIN_FBFT_REPLICA_2_H
diff --git a/src/fbft/actions/Action.cpp b/src/fbft/actions/Action.cpp
index 6b59de3..8306bcb 100644
--- a/src/fbft/actions/Action.cpp
+++ b/src/fbft/actions/Action.cpp
@@ -9,34 +9,23 @@ namespace itcoin {
namespace fbft {
namespace actions {
-Action::Action(uint32_t replica_id): m_replica_id(replica_id)
-{
+Action::Action(uint32_t replica_id) : m_replica_id(replica_id) {}
-}
-
-Action::Action(PlTerm Replica_id): m_replica_id((long) Replica_id)
-{
-
-}
+Action::Action(PlTerm Replica_id) : m_replica_id((long)Replica_id) {}
-std::string Action::name() const
-{
- return ACTION_TYPE_TYPE_AS_STRING[static_cast(this->type())];
-}
+std::string Action::name() const { return ACTION_TYPE_TYPE_AS_STRING[static_cast(this->type())]; }
-std::optional> Action::message() const
-{
+std::optional> Action::message() const {
return std::nullopt;
}
-std::ostream& operator<<(std::ostream& Str, const Action& action)
-{
+std::ostream& operator<<(std::ostream& Str, const Action& action) {
// print something from v to str, e.g: Str << v.getX();
string action_str = action.identify();
Str << action_str;
return Str;
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/Execute.cpp b/src/fbft/actions/Execute.cpp
index d5b34a6..a93301f 100644
--- a/src/fbft/actions/Execute.cpp
+++ b/src/fbft/actions/Execute.cpp
@@ -3,9 +3,9 @@
#include "actions.h"
+#include
#include
#include
-#include
#include "../../blockchain/blockchain.h"
#include "../../wallet/wallet.h"
@@ -20,33 +20,25 @@ namespace itcoin {
namespace fbft {
namespace actions {
-Execute::Execute(
- Blockchain& blockchain, RoastWallet& wallet,
- PlTerm Replica_id, PlTerm Req_digest, PlTerm V, PlTerm N):
-Action(Replica_id),
-m_blockchain(blockchain),
-m_wallet(wallet)
-{
- m_view = (long) V;
- m_seq_number = (long) N;
+Execute::Execute(Blockchain& blockchain, RoastWallet& wallet, PlTerm Replica_id, PlTerm Req_digest, PlTerm V,
+ PlTerm N)
+ : Action(Replica_id), m_blockchain(blockchain), m_wallet(wallet) {
+ m_view = (long)V;
+ m_seq_number = (long)N;
// Retrieve payload from the msg store
- std::string req_digest = (char*) Req_digest;
+ std::string req_digest = (char*)Req_digest;
Request r = Request::FindByDigest(m_replica_id, req_digest);
m_request = r;
}
-std::vector> Execute::BuildActives(
- const itcoin::FbftConfig& config, Blockchain& blockchain,
- RoastWallet& wallet
-)
-{
+std::vector>
+Execute::BuildActives(const itcoin::FbftConfig& config, Blockchain& blockchain, RoastWallet& wallet) {
std::vector> results{};
- PlTerm Req_digest, V, N, Replica_id{(long) config.id()};
+ PlTerm Req_digest, V, N, Replica_id{(long)config.id()};
PlQuery query("pre_EXECUTE", PlTermv(Req_digest, V, N, Replica_id));
- while ( query.next_solution() )
- {
+ while (query.next_solution()) {
actions::Execute action{blockchain, wallet, Replica_id, Req_digest, V, N};
std::unique_ptr p_action = std::make_unique(action);
results.emplace_back(move(p_action));
@@ -54,8 +46,7 @@ std::vector> Execute::BuildActives(
return results;
}
-int Execute::effect() const
-{
+int Execute::effect() const {
std::vector signers;
std::vector signatures;
@@ -63,36 +54,30 @@ int Execute::effect() const
string pre_signature;
// We need to find out the block to signatures
- PlTerm Replica_id{(long) m_replica_id}, Session_id, Signers, Pre_signature, Signature_shares;
- PlQuery query{"roast_final_signature_session", PlTermv(Replica_id, Session_id, Signers, Pre_signature, Signature_shares)};
- while ( query.next_solution() )
- {
- PlTail SignersTail{Signers}; PlTerm SignerElem;
- while(SignersTail.next(SignerElem))
- {
- signers.emplace_back((long) SignerElem);
+ PlTerm Replica_id{(long)m_replica_id}, Session_id, Signers, Pre_signature, Signature_shares;
+ PlQuery query{"roast_final_signature_session",
+ PlTermv(Replica_id, Session_id, Signers, Pre_signature, Signature_shares)};
+ while (query.next_solution()) {
+ PlTail SignersTail{Signers};
+ PlTerm SignerElem;
+ while (SignersTail.next(SignerElem)) {
+ signers.emplace_back((long)SignerElem);
}
- PlTail SigShareTail{Signature_shares}; PlTerm SigShareElem;
- while(SigShareTail.next(SigShareElem))
- {
- string sig_share = (const char *) SigShareElem;
+ PlTail SigShareTail{Signature_shares};
+ PlTerm SigShareElem;
+ while (SigShareTail.next(SigShareElem)) {
+ string sig_share = (const char*)SigShareElem;
signatures.emplace_back(sig_share);
}
- pre_signature = (const char *) Pre_signature;
+ pre_signature = (const char*)Pre_signature;
}
- BOOST_LOG_TRIVIAL(trace) << str(
- boost::format( "%1% effect(), Aggregating the following signatures:" )
- % this->identify()
- );
- for (int i=0; iidentify());
+ for (int i = 0; i < signers.size(); i++) // access by reference to avoid copying
{
- BOOST_LOG_TRIVIAL(trace) << str(
- boost::format( "%1% effect(), signature from R%2% = %3%" )
- % this->identify()
- % signers.at(i)
- % signatures.at(i)
- );
+ BOOST_LOG_TRIVIAL(trace) << str(boost::format("%1% effect(), signature from R%2% = %3%") %
+ this->identify() % signers.at(i) % signatures.at(i));
}
// Retrieve thre proposed block
@@ -104,53 +89,32 @@ int Execute::effect() const
RoastWallet& wallet = dynamic_cast(m_wallet);
final_block = wallet.FinalizeBlock(proposed_block, pre_signature, signatures);
- if(final_block.GetHash() != proposed_block.GetHash())
- {
+ if (final_block.GetHash() != proposed_block.GetHash()) {
BOOST_LOG_TRIVIAL(error) << "The executed block has mismatching hash, and will be ignored.";
return 0;
}
- BOOST_LOG_TRIVIAL(trace) << str(
- boost::format( "%1% effect(), Proposed/Final block hash = %2%>" )
- % this->identify()
- % final_block.GetHash().GetHex()
- );
+ BOOST_LOG_TRIVIAL(trace) << str(boost::format("%1% effect(), Proposed/Final block hash = %2%>") %
+ this->identify() % final_block.GetHash().GetHex());
- BOOST_LOG_TRIVIAL(trace) << str(
- boost::format( "%1% effect(), Proposed block = %2%>" )
- % this->identify()
- % HexSerializableCBlock(proposed_block).GetHex()
- );
+ BOOST_LOG_TRIVIAL(trace) << str(boost::format("%1% effect(), Proposed block = %2%>") % this->identify() %
+ HexSerializableCBlock(proposed_block).GetHex());
- BOOST_LOG_TRIVIAL(trace) << str(
- boost::format( "%1% effect(), Final block = %2%>" )
- % this->identify()
- % HexSerializableCBlock(final_block).GetHex()
- );
+ BOOST_LOG_TRIVIAL(trace) << str(boost::format("%1% effect(), Final block = %2%>") % this->identify() %
+ HexSerializableCBlock(final_block).GetHex());
m_blockchain.SubmitBlock(m_seq_number, final_block);
- PlTermv args(
- PlString((const char*) m_request.digest().c_str()),
- PlTerm((long) m_seq_number),
- PlString((const char*) proposed_block.GetHash().GetHex().c_str()),
- PlTerm((long) m_replica_id)
- );
+ PlTermv args(PlString((const char*)m_request.digest().c_str()), PlTerm((long)m_seq_number),
+ PlString((const char*)proposed_block.GetHash().GetHex().c_str()), PlTerm((long)m_replica_id));
return PlCall("effect_EXECUTE", args);
}
-std::string Execute::identify() const
-{
- return str(
- boost::format( "<%1%, Request=%2%, V=%3%, N=%4%, R=%5%>" )
- % name()
- % m_request.digest()
- % m_view
- % m_seq_number
- % m_replica_id
- );
+std::string Execute::identify() const {
+ return str(boost::format("<%1%, Request=%2%, V=%3%, N=%4%, R=%5%>") % name() % m_request.digest() % m_view %
+ m_seq_number % m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/ProcessNewView.cpp b/src/fbft/actions/ProcessNewView.cpp
index e11aee3..e67e63f 100644
--- a/src/fbft/actions/ProcessNewView.cpp
+++ b/src/fbft/actions/ProcessNewView.cpp
@@ -3,8 +3,8 @@
#include "actions.h"
-#include
#include
+#include
#include "../../blockchain/blockchain.h"
#include "../../wallet/wallet.h"
@@ -19,55 +19,36 @@ namespace itcoin {
namespace fbft {
namespace actions {
-ProcessNewView::ProcessNewView(PlTerm Replica_id, PlTerm Hi, PlTerm Nu, PlTerm Chi)
-:Action(Replica_id)
-{
- m_hi = (long) Hi;
+ProcessNewView::ProcessNewView(PlTerm Replica_id, PlTerm Hi, PlTerm Nu, PlTerm Chi) : Action(Replica_id) {
+ m_hi = (long)Hi;
m_nu = NewView::nu_from_plterm(Nu);
m_chi = NewView::chi_from_plterm(Chi);
};
-std::vector> ProcessNewView::BuildActives(
- const itcoin::FbftConfig& config,
- Blockchain& blockchain,
- RoastWallet& wallet
-)
-{
+std::vector>
+ProcessNewView::BuildActives(const itcoin::FbftConfig& config, Blockchain& blockchain, RoastWallet& wallet) {
std::vector> results{};
- PlTerm Hi, Nu, Chi, Replica_id{(long) config.id()};
+ PlTerm Hi, Nu, Chi, Replica_id{(long)config.id()};
PlQuery query("pre_PROCESS_NEW_VIEW", PlTermv(Hi, Nu, Chi, Replica_id));
- while ( query.next_solution() )
- {
+ while (query.next_solution()) {
unique_ptr action =
- std::make_unique(Replica_id, Hi, Nu, Chi);
+ std::make_unique(Replica_id, Hi, Nu, Chi);
results.emplace_back(std::move(action));
}
return results;
}
-int ProcessNewView::effect() const
-{
- PlTermv args(
- PlTerm((long) m_hi),
- NewView::chi_as_plterm(m_chi),
- PlTerm((long) m_replica_id)
- );
+int ProcessNewView::effect() const {
+ PlTermv args(PlTerm((long)m_hi), NewView::chi_as_plterm(m_chi), PlTerm((long)m_replica_id));
return PlCall("effect_PROCESS_NEW_VIEW", args);
}
-std::string ProcessNewView::identify() const
-{
- return str(
- boost::format( "<%1%, Hi=%2%, Nu=%3%, Chi=%4%, R=%5%>" )
- % name()
- % m_hi
- % "m_nu"
- % "m_chi"
- % m_replica_id
- );
+std::string ProcessNewView::identify() const {
+ return str(boost::format("<%1%, Hi=%2%, Nu=%3%, Chi=%4%, R=%5%>") % name() % m_hi % "m_nu" % "m_chi" %
+ m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/ReceiveBlock.cpp b/src/fbft/actions/ReceiveBlock.cpp
index d406b82..7ebc680 100644
--- a/src/fbft/actions/ReceiveBlock.cpp
+++ b/src/fbft/actions/ReceiveBlock.cpp
@@ -3,34 +3,23 @@
#include "actions.h"
-#include
#include
+#include
namespace itcoin {
namespace fbft {
namespace actions {
-int ReceiveBlock::effect() const
-{
- PlTermv args(
- PlTerm((long) m_replica_id),
- PlTerm((long) m_msg.block_height()),
- PlTerm((long) m_msg.block_time()),
- PlString((const char*) m_msg.block_hash().c_str())
- );
+int ReceiveBlock::effect() const {
+ PlTermv args(PlTerm((long)m_replica_id), PlTerm((long)m_msg.block_height()),
+ PlTerm((long)m_msg.block_time()), PlString((const char*)m_msg.block_hash().c_str()));
return PlCall("effect_RECEIVE_BLOCK", args);
}
-std::string ReceiveBlock::identify() const
-{
- return str(
- boost::format( "<%1%, H=%2%, R=%3%>" )
- % name()
- % m_msg.block_height()
- % m_replica_id
- );
+std::string ReceiveBlock::identify() const {
+ return str(boost::format("<%1%, H=%2%, R=%3%>") % name() % m_msg.block_height() % m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/ReceiveCommit.cpp b/src/fbft/actions/ReceiveCommit.cpp
index 8ae917a..ec2cce2 100644
--- a/src/fbft/actions/ReceiveCommit.cpp
+++ b/src/fbft/actions/ReceiveCommit.cpp
@@ -3,39 +3,26 @@
#include "actions.h"
-#include
#include
+#include
namespace itcoin {
namespace fbft {
namespace actions {
-int ReceiveCommit::effect() const
-{
- PlTermv args(
- PlTerm((long) m_msg.view()),
- PlTerm((long) m_msg.seq_number()),
- PlString((const char*) m_msg.pre_signature().c_str()),
- PlTerm((long) m_msg.sender_id()),
- PlString((const char*) m_msg.signature().c_str()),
- PlTerm((long) m_replica_id)
- );
+int ReceiveCommit::effect() const {
+ PlTermv args(PlTerm((long)m_msg.view()), PlTerm((long)m_msg.seq_number()),
+ PlString((const char*)m_msg.pre_signature().c_str()), PlTerm((long)m_msg.sender_id()),
+ PlString((const char*)m_msg.signature().c_str()), PlTerm((long)m_replica_id));
return PlCall("effect_RECEIVE_COMMIT", args);
}
-std::string ReceiveCommit::identify() const
-{
- return str(
- boost::format( "<%1%, V=%2%, N=%3%, Data=%4% R=%5%>" )
- % name()
- % m_msg.view()
- % m_msg.seq_number()
- % m_msg.pre_signature().substr(0,5)
- % m_replica_id
- );
+std::string ReceiveCommit::identify() const {
+ return str(boost::format("<%1%, V=%2%, N=%3%, Data=%4% R=%5%>") % name() % m_msg.view() %
+ m_msg.seq_number() % m_msg.pre_signature().substr(0, 5) % m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/ReceiveNewView.cpp b/src/fbft/actions/ReceiveNewView.cpp
index 6da6593..ae007f4 100644
--- a/src/fbft/actions/ReceiveNewView.cpp
+++ b/src/fbft/actions/ReceiveNewView.cpp
@@ -3,9 +3,9 @@
#include "actions.h"
+#include
#include
#include
-#include
#include "../../blockchain/blockchain.h"
#include "../../wallet/wallet.h"
@@ -19,39 +19,23 @@ namespace itcoin {
namespace fbft {
namespace actions {
-ReceiveNewView::ReceiveNewView(RoastWallet& wallet, uint32_t replica_id, messages::NewView msg):
-Action(replica_id),
-m_wallet(wallet),
-m_msg(msg)
-{
-};
-
-int ReceiveNewView::effect() const
-{
-
- PlTermv args(
- PlTerm((long) m_msg.view()),
- NewView::nu_as_plterm(m_msg.nu()),
- NewView::chi_as_plterm(m_msg.chi()),
- PlTerm((long) m_msg.sender_id()),
- PlString((const char*) m_msg.signature().c_str()),
- PlTerm((long) m_replica_id)
- );
+ReceiveNewView::ReceiveNewView(RoastWallet& wallet, uint32_t replica_id, messages::NewView msg)
+ : Action(replica_id), m_wallet(wallet), m_msg(msg){};
+
+int ReceiveNewView::effect() const {
+
+ PlTermv args(PlTerm((long)m_msg.view()), NewView::nu_as_plterm(m_msg.nu()),
+ NewView::chi_as_plterm(m_msg.chi()), PlTerm((long)m_msg.sender_id()),
+ PlString((const char*)m_msg.signature().c_str()), PlTerm((long)m_replica_id));
return PlCall("effect_RECEIVE_NEW_VIEW", args);
}
-std::string ReceiveNewView::identify() const
-{
- return str(
- boost::format( "<%1%, V=%2%, Sender=%3%, R=%4%>" )
- % name()
- % m_msg.view()
- % m_msg.sender_id()
- % m_replica_id
- );
+std::string ReceiveNewView::identify() const {
+ return str(boost::format("<%1%, V=%2%, Sender=%3%, R=%4%>") % name() % m_msg.view() % m_msg.sender_id() %
+ m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/ReceivePrePrepare.cpp b/src/fbft/actions/ReceivePrePrepare.cpp
index 8ac07c4..82ddb3a 100644
--- a/src/fbft/actions/ReceivePrePrepare.cpp
+++ b/src/fbft/actions/ReceivePrePrepare.cpp
@@ -3,9 +3,9 @@
#include "actions.h"
+#include
#include
#include
-#include
#include "../../blockchain/blockchain.h"
#include "../../wallet/wallet.h"
@@ -20,82 +20,60 @@ namespace itcoin {
namespace fbft {
namespace actions {
-ReceivePrePrepare::ReceivePrePrepare(uint32_t replica_id, Blockchain& blockchain,
- double current_time, double pre_prepare_time_tolerance_delta,
- PrePrepare msg)
-:
-Action(replica_id),
-m_current_time(current_time),
-m_pre_prepare_time_tolerance_delta(pre_prepare_time_tolerance_delta),
-m_blockchain(blockchain),
-m_msg(msg)
-{
+ReceivePrePrepare::ReceivePrePrepare(uint32_t replica_id, Blockchain& blockchain, double current_time,
+ double pre_prepare_time_tolerance_delta, PrePrepare msg)
+ : Action(replica_id), m_current_time(current_time),
+ m_pre_prepare_time_tolerance_delta(pre_prepare_time_tolerance_delta), m_blockchain(blockchain),
+ m_msg(msg){
-};
+ };
-int ReceivePrePrepare::effect() const
-{
+int ReceivePrePrepare::effect() const {
/*
* Here we check that the block proposed by the primary is valid. We exclude
* the signet solution from the check (hence the third parameter set to
* "false").
*/
- if(!m_blockchain.TestBlockValidity(m_msg.seq_number(), m_msg.proposed_block(), false))
- {
+ if (!m_blockchain.TestBlockValidity(m_msg.seq_number(), m_msg.proposed_block(), false)) {
BOOST_LOG_TRIVIAL(error) << "A received PRE_PREPARE contains an invalid block, and will be ignored!";
return 0;
}
// Check that the block has the expected timestamp
messages::Request req;
- if (!messages::Request::TryFindByDigest(m_replica_id, m_msg.req_digest(), req))
- {
+ if (!messages::Request::TryFindByDigest(m_replica_id, m_msg.req_digest(), req)) {
BOOST_LOG_TRIVIAL(error) << "A received PRE_PREPARE references an unknown request, and will be ignored.";
return 0;
}
- if (!m_msg.proposed_block().nTime == req.timestamp())
- {
- BOOST_LOG_TRIVIAL(error) << "A received PRE_PREPARE has mismatching block and request timestamp, and will be ignored.";
+ if (!m_msg.proposed_block().nTime == req.timestamp()) {
+ BOOST_LOG_TRIVIAL(error)
+ << "A received PRE_PREPARE has mismatching block and request timestamp, and will be ignored.";
return 0;
}
- if (req.timestamp() > m_current_time + m_pre_prepare_time_tolerance_delta)
- {
+ if (req.timestamp() > m_current_time + m_pre_prepare_time_tolerance_delta) {
string error_msg = str(
- boost::format("R%1% PRE_PREPARE received for a future request (request time = %2%) has been received too early (current time = %3%, max timestamp accepted = %4%), and will be ignored.")
- % m_replica_id
- % req.timestamp()
- % m_current_time
- % (m_current_time + m_pre_prepare_time_tolerance_delta)
- );
+ boost::format("R%1% PRE_PREPARE received for a future request (request time = %2%) has been received "
+ "too early (current time = %3%, max timestamp accepted = %4%), and will be ignored.") %
+ m_replica_id % req.timestamp() % m_current_time %
+ (m_current_time + m_pre_prepare_time_tolerance_delta));
BOOST_LOG_TRIVIAL(error) << error_msg;
return 0;
}
- PlTermv args(
- PlTerm((long) m_msg.view()),
- PlTerm((long) m_msg.seq_number()),
- PlString((const char*) m_msg.req_digest().c_str()),
- PlString((const char*) m_msg.proposed_block_hex().c_str() ),
- PlTerm((long) m_msg.sender_id()),
- PlString((const char*) m_msg.signature().c_str()),
- PlTerm((long) m_replica_id)
- );
+ PlTermv args(PlTerm((long)m_msg.view()), PlTerm((long)m_msg.seq_number()),
+ PlString((const char*)m_msg.req_digest().c_str()),
+ PlString((const char*)m_msg.proposed_block_hex().c_str()), PlTerm((long)m_msg.sender_id()),
+ PlString((const char*)m_msg.signature().c_str()), PlTerm((long)m_replica_id));
return PlCall("effect_RECEIVE_PRE_PREPARE", args);
}
-std::string ReceivePrePrepare::identify() const
-{
- return str(
- boost::format( "<%1%, V=%2%, N=%3%, R=%4%>" )
- % name()
- % m_msg.view()
- % m_msg.seq_number()
- % m_replica_id
- );
+std::string ReceivePrePrepare::identify() const {
+ return str(boost::format("<%1%, V=%2%, N=%3%, R=%4%>") % name() % m_msg.view() % m_msg.seq_number() %
+ m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/ReceivePrepare.cpp b/src/fbft/actions/ReceivePrepare.cpp
index 2ea7060..e4b036e 100644
--- a/src/fbft/actions/ReceivePrepare.cpp
+++ b/src/fbft/actions/ReceivePrepare.cpp
@@ -3,36 +3,25 @@
#include "actions.h"
-#include
#include
+#include
namespace itcoin {
namespace fbft {
namespace actions {
-int ReceivePrepare::effect() const
-{
- PlTermv args(
- PlTerm((long) m_msg.view()),
- PlTerm((long) m_msg.seq_number()),
- PlString((const char*) m_msg.req_digest().c_str()),
- PlTerm((long) m_msg.sender_id()),
- PlString((const char*) m_msg.signature().c_str()),
- PlTerm((long) m_replica_id)
- );
+int ReceivePrepare::effect() const {
+ PlTermv args(PlTerm((long)m_msg.view()), PlTerm((long)m_msg.seq_number()),
+ PlString((const char*)m_msg.req_digest().c_str()), PlTerm((long)m_msg.sender_id()),
+ PlString((const char*)m_msg.signature().c_str()), PlTerm((long)m_replica_id));
return PlCall("effect_RECEIVE_PREPARE", args);
}
-std::string ReceivePrepare::identify() const
-{
- return str(
- boost::format( "<%1%, R=%2%>" )
- % name()
- % m_replica_id
- );
+std::string ReceivePrepare::identify() const {
+ return str(boost::format("<%1%, R=%2%>") % name() % m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/ReceiveRequest.cpp b/src/fbft/actions/ReceiveRequest.cpp
index 8d85611..037090a 100644
--- a/src/fbft/actions/ReceiveRequest.cpp
+++ b/src/fbft/actions/ReceiveRequest.cpp
@@ -3,37 +3,27 @@
#include "actions.h"
-#include
#include
+#include
-namespace messages=itcoin::fbft::messages;
+namespace messages = itcoin::fbft::messages;
namespace itcoin {
namespace fbft {
namespace actions {
-int ReceiveRequest::effect() const
-{
- PlTermv args(
- PlString((const char*) m_msg.digest().c_str()),
- PlTerm((long) m_msg.timestamp()),
- PlTerm((long) m_replica_id)
- );
+int ReceiveRequest::effect() const {
+ PlTermv args(PlString((const char*)m_msg.digest().c_str()), PlTerm((long)m_msg.timestamp()),
+ PlTerm((long)m_replica_id));
return PlCall("effect_RECEIVE_REQUEST", args);
}
-std::string ReceiveRequest::identify() const
-{
- return str(
- boost::format( "<%1%, T=%2%, H=%3%, R=%4%>" )
- % name()
- % m_msg.timestamp()
- % m_msg.height()
- % m_replica_id
- );
+std::string ReceiveRequest::identify() const {
+ return str(boost::format("<%1%, T=%2%, H=%3%, R=%4%>") % name() % m_msg.timestamp() % m_msg.height() %
+ m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/ReceiveViewChange.cpp b/src/fbft/actions/ReceiveViewChange.cpp
index dc70bf5..9273ebf 100644
--- a/src/fbft/actions/ReceiveViewChange.cpp
+++ b/src/fbft/actions/ReceiveViewChange.cpp
@@ -3,44 +3,30 @@
#include "actions.h"
-#include
#include
+#include
using namespace std;
-namespace messages=itcoin::fbft::messages;
+namespace messages = itcoin::fbft::messages;
namespace itcoin {
namespace fbft {
namespace actions {
-int ReceiveViewChange::effect() const
-{
- PlTermv args(
- PlTerm((long) m_msg.view()),
- PlTerm((long) m_msg.hi()),
- PlString((const char*) m_msg.c().c_str()),
- m_msg.pi_as_plterm(),
- m_msg.qi_as_plterm(),
- PlTerm((long) m_msg.sender_id()),
- PlString((const char*) m_msg.signature().c_str()),
- PlTerm((long) m_replica_id)
- );
+int ReceiveViewChange::effect() const {
+ PlTermv args(PlTerm((long)m_msg.view()), PlTerm((long)m_msg.hi()), PlString((const char*)m_msg.c().c_str()),
+ m_msg.pi_as_plterm(), m_msg.qi_as_plterm(), PlTerm((long)m_msg.sender_id()),
+ PlString((const char*)m_msg.signature().c_str()), PlTerm((long)m_replica_id));
return PlCall("effect_RECEIVE_VIEW_CHANGE", args);
}
-std::string ReceiveViewChange::identify() const
-{
- return str(
- boost::format( "<%1%, S=%2%, V=%3%, R=%4%>" )
- % name()
- % m_msg.sender_id()
- % m_msg.view()
- % m_replica_id
- );
+std::string ReceiveViewChange::identify() const {
+ return str(boost::format("<%1%, S=%2%, V=%3%, R=%4%>") % name() % m_msg.sender_id() % m_msg.view() %
+ m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/RecoverView.cpp b/src/fbft/actions/RecoverView.cpp
index 92285b2..c198955 100644
--- a/src/fbft/actions/RecoverView.cpp
+++ b/src/fbft/actions/RecoverView.cpp
@@ -3,9 +3,9 @@
#include "actions.h"
+#include
#include
#include
-#include
#include "../../blockchain/blockchain.h"
#include "../../wallet/wallet.h"
@@ -20,55 +20,32 @@ namespace itcoin {
namespace fbft {
namespace actions {
-RecoverView::RecoverView(uint32_t replica_id, uint32_t view):
-Action(replica_id), m_view(view)
-{
+RecoverView::RecoverView(uint32_t replica_id, uint32_t view) : Action(replica_id), m_view(view) {}
-}
+RecoverView::~RecoverView() {}
-RecoverView::~RecoverView()
-{
-
-}
-
-std::vector> RecoverView::BuildActives(
- const itcoin::FbftConfig& config,
- Blockchain& blockchain,
- RoastWallet& wallet
-)
-{
+std::vector>
+RecoverView::BuildActives(const itcoin::FbftConfig& config, Blockchain& blockchain, RoastWallet& wallet) {
std::vector> results{};
- PlTerm V, Replica_id{(long) config.id()};
+ PlTerm V, Replica_id{(long)config.id()};
PlQuery query("pre_RECOVER_VIEW", PlTermv(Replica_id, V));
- while ( query.next_solution() )
- {
- uint32_t v = (long) V;
- std::unique_ptr action =
- std::make_unique(config.id(), v);
+ while (query.next_solution()) {
+ uint32_t v = (long)V;
+ std::unique_ptr action = std::make_unique(config.id(), v);
results.emplace_back(std::move(action));
}
return results;
}
-int RecoverView::effect() const
-{
- PlTermv args(
- PlTerm((long) m_replica_id),
- PlTerm((long) m_view)
- );
+int RecoverView::effect() const {
+ PlTermv args(PlTerm((long)m_replica_id), PlTerm((long)m_view));
return PlCall("effect_RECOVER_VIEW", args);
}
-std::string RecoverView::identify() const
-{
- return str(
- boost::format( "<%1%, V=%2%, R=%3%>" )
- % name()
- % m_view
- % m_replica_id
- );
+std::string RecoverView::identify() const {
+ return str(boost::format("<%1%, V=%2%, R=%3%>") % name() % m_view % m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/RoastInit.cpp b/src/fbft/actions/RoastInit.cpp
index ab68fca..f2c9b86 100644
--- a/src/fbft/actions/RoastInit.cpp
+++ b/src/fbft/actions/RoastInit.cpp
@@ -15,57 +15,36 @@ namespace itcoin {
namespace fbft {
namespace actions {
-RoastInit::RoastInit(PlTerm Replica_id, PlTerm Req_digest, PlTerm V, PlTerm N):
-Action(Replica_id)
-{
+RoastInit::RoastInit(PlTerm Replica_id, PlTerm Req_digest, PlTerm V, PlTerm N) : Action(Replica_id) {
// Retrieve payload from the msg store
- std::string req_digest = (char*) Req_digest;
+ std::string req_digest = (char*)Req_digest;
m_request = Request::FindByDigest(m_replica_id, req_digest);
- m_view = (long) V;
+ m_view = (long)V;
- m_seq_number = (long) N;
+ m_seq_number = (long)N;
}
-RoastInit::~RoastInit()
-{
+RoastInit::~RoastInit() {}
+std::string RoastInit::identify() const {
+ return str(boost::format("<%1%, Request=%2%, V=%3%, N=%4%, R=%5%>") % name() % m_request.digest() % m_view %
+ m_seq_number % m_replica_id);
}
-std::string RoastInit::identify() const
-{
- return str(
- boost::format( "<%1%, Request=%2%, V=%3%, N=%4%, R=%5%>" )
- % name()
- % m_request.digest()
- % m_view
- % m_seq_number
- % m_replica_id
- );
-}
-
-int RoastInit::effect() const
-{
- PlTermv args(
- PlTerm((long) m_replica_id),
- PlTerm((long) m_view),
- PlTerm((long) m_seq_number),
- PlString((const char*) m_request.digest().c_str())
- );
+int RoastInit::effect() const {
+ PlTermv args(PlTerm((long)m_replica_id), PlTerm((long)m_view), PlTerm((long)m_seq_number),
+ PlString((const char*)m_request.digest().c_str()));
return PlCall("effect_ROAST_INIT", args);
}
-std::vector> RoastInit::BuildActives(
- const itcoin::FbftConfig& config,
- blockchain::Blockchain& blockchain,
- wallet::RoastWallet& wallet
-)
-{
+std::vector> RoastInit::BuildActives(const itcoin::FbftConfig& config,
+ blockchain::Blockchain& blockchain,
+ wallet::RoastWallet& wallet) {
std::vector> results{};
- PlTerm Req_digest, V, N, Replica_id{(long) config.id()};
+ PlTerm Req_digest, V, N, Replica_id{(long)config.id()};
PlQuery query("pre_ROAST_INIT", PlTermv(Replica_id, Req_digest, V, N));
- while ( query.next_solution() )
- {
+ while (query.next_solution()) {
actions::RoastInit action{Replica_id, Req_digest, V, N};
std::unique_ptr p_action = std::make_unique(action);
results.emplace_back(move(p_action));
@@ -73,6 +52,6 @@ std::vector> RoastInit::BuildActives(
return results;
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/RoastReceivePreSignature.cpp b/src/fbft/actions/RoastReceivePreSignature.cpp
index 5dd20c4..9951ad5 100644
--- a/src/fbft/actions/RoastReceivePreSignature.cpp
+++ b/src/fbft/actions/RoastReceivePreSignature.cpp
@@ -5,9 +5,9 @@
#include
+#include
#include
#include
-#include
#include "../../wallet/wallet.h"
@@ -19,84 +19,65 @@ namespace itcoin {
namespace fbft {
namespace actions {
-RoastReceivePreSignature::RoastReceivePreSignature(wallet::RoastWallet& wallet, uint32_t replica_id, messages::RoastPreSignature msg):
-Action(replica_id), m_wallet(wallet), m_msg(msg)
-{
+RoastReceivePreSignature::RoastReceivePreSignature(wallet::RoastWallet& wallet, uint32_t replica_id,
+ messages::RoastPreSignature msg)
+ : Action(replica_id), m_wallet(wallet), m_msg(msg){
-};
+ };
-RoastReceivePreSignature::~RoastReceivePreSignature()
-{
+RoastReceivePreSignature::~RoastReceivePreSignature(){
};
-int RoastReceivePreSignature::effect() const
-{
+int RoastReceivePreSignature::effect() const {
CBlock block_to_sign;
- PlTerm Replica_id{(long) m_replica_id}, V, N, Req_digest;
+ PlTerm Replica_id{(long)m_replica_id}, V, N, Req_digest;
int result = PlCall("roast_active", PlTermv(Replica_id, V, N, Req_digest));
- if (result)
- {
- uint32_t v = (long) V;
- uint32_t n = (long) N;
- string req_digest = (const char*) Req_digest;
+ if (result) {
+ uint32_t v = (long)V;
+ uint32_t n = (long)N;
+ string req_digest = (const char*)Req_digest;
PrePrepare ppp_msg = PrePrepare::FindByV_N_Req(m_replica_id, v, n, req_digest);
block_to_sign = ppp_msg.proposed_block();
- }
- else
- {
- string error_msg = str(
- boost::format("R%1% received PRE_SIGNATURE but ROAST is not active, it will be ignored.")
- % m_replica_id
- );
+ } else {
+ string error_msg =
+ str(boost::format("R%1% received PRE_SIGNATURE but ROAST is not active, it will be ignored.") %
+ m_replica_id);
BOOST_LOG_TRIVIAL(error) << error_msg;
return 0;
}
bool replica_id_found = false;
- for (uint32_t signer_id : m_msg.signers())
- {
- if (signer_id == m_replica_id)
- {
+ for (uint32_t signer_id : m_msg.signers()) {
+ if (signer_id == m_replica_id) {
replica_id_found = true;
break;
}
}
- if ( replica_id_found ) {
- string signature_share = m_wallet.GetSignatureShare(m_msg.signers(), m_msg.pre_signature(), block_to_sign);
+ if (replica_id_found) {
+ string signature_share =
+ m_wallet.GetSignatureShare(m_msg.signers(), m_msg.pre_signature(), block_to_sign);
string next_pre_sig_share = m_wallet.GetPreSignatureShare();
- PlTermv args(
- PlTerm((long) m_replica_id),
- m_msg.signers_as_plterm(),
- PlString((const char*) m_msg.pre_signature().c_str()),
- PlString((const char*) signature_share.c_str()),
- PlString((const char*) next_pre_sig_share.c_str())
- );
+ PlTermv args(PlTerm((long)m_replica_id), m_msg.signers_as_plterm(),
+ PlString((const char*)m_msg.pre_signature().c_str()),
+ PlString((const char*)signature_share.c_str()),
+ PlString((const char*)next_pre_sig_share.c_str()));
return PlCall("effect_RECEIVE_PRE_SIGNATURE", args);
- }
- else {
+ } else {
BOOST_LOG_TRIVIAL(info) << str(
- boost::format("R%1% received PRE_SIGNATURE but it is not part of the selected signers, it will be ignored.")
- % m_replica_id
- );
+ boost::format(
+ "R%1% received PRE_SIGNATURE but it is not part of the selected signers, it will be ignored.") %
+ m_replica_id);
return 0;
}
-
-
}
-std::string RoastReceivePreSignature::identify() const
-{
- return str(
- boost::format( "<%1%, msg=%2%, R=%3%>" )
- % name()
- % m_msg.identify()
- % m_replica_id
- );
+std::string RoastReceivePreSignature::identify() const {
+ return str(boost::format("<%1%, msg=%2%, R=%3%>") % name() % m_msg.identify() % m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/RoastReceiveSignatureShare.cpp b/src/fbft/actions/RoastReceiveSignatureShare.cpp
index 472f874..0d70006 100644
--- a/src/fbft/actions/RoastReceiveSignatureShare.cpp
+++ b/src/fbft/actions/RoastReceiveSignatureShare.cpp
@@ -3,34 +3,24 @@
#include "actions.h"
-#include
#include
+#include
namespace itcoin {
namespace fbft {
namespace actions {
-int RoastReceiveSignatureShare::effect() const
-{
- PlTermv args(
- PlTerm((long) m_replica_id),
- PlTerm((long) m_msg.sender_id()),
- PlString((const char*) m_msg.signature_share().c_str()),
- PlString((const char*) m_msg.next_pre_signature_share().c_str())
- );
+int RoastReceiveSignatureShare::effect() const {
+ PlTermv args(PlTerm((long)m_replica_id), PlTerm((long)m_msg.sender_id()),
+ PlString((const char*)m_msg.signature_share().c_str()),
+ PlString((const char*)m_msg.next_pre_signature_share().c_str()));
return PlCall("effect_RECEIVE_SIG_SHARE", args);
}
-std::string RoastReceiveSignatureShare::identify() const
-{
- return str(
- boost::format( "<%1%, msg=%2%, R=%3%>" )
- % name()
- % m_msg.identify()
- % m_replica_id
- );
+std::string RoastReceiveSignatureShare::identify() const {
+ return str(boost::format("<%1%, msg=%2%, R=%3%>") % name() % m_msg.identify() % m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/SendCommit.cpp b/src/fbft/actions/SendCommit.cpp
index 231007e..184a43d 100644
--- a/src/fbft/actions/SendCommit.cpp
+++ b/src/fbft/actions/SendCommit.cpp
@@ -3,9 +3,9 @@
#include "actions.h"
+#include
#include
#include
-#include
#include "../../blockchain/blockchain.h"
#include "../../wallet/wallet.h"
@@ -20,73 +20,49 @@ namespace itcoin {
namespace fbft {
namespace actions {
-SendCommit::SendCommit(RoastWallet& wallet,
- PlTerm Replica_id, PlTerm Req_digest, PlTerm V, PlTerm N)
-:Action(Replica_id), m_wallet(wallet)
-{
- m_view = (long) V;
- m_seq_number = (long) N;
+SendCommit::SendCommit(RoastWallet& wallet, PlTerm Replica_id, PlTerm Req_digest, PlTerm V, PlTerm N)
+ : Action(Replica_id), m_wallet(wallet) {
+ m_view = (long)V;
+ m_seq_number = (long)N;
// Retrieve payload from the msg store
- std::string req_digest = (const char*) Req_digest;
+ std::string req_digest = (const char*)Req_digest;
m_request = Request::FindByDigest(m_replica_id, req_digest);
}
-std::vector> SendCommit::BuildActives(
- const itcoin::FbftConfig& config,
- Blockchain& blockchain,
- RoastWallet& wallet
-)
-{
+std::vector>
+SendCommit::BuildActives(const itcoin::FbftConfig& config, Blockchain& blockchain, RoastWallet& wallet) {
std::vector> results{};
- PlTerm Req_digest, V, N, Replica_id{(long) config.id()};
+ PlTerm Req_digest, V, N, Replica_id{(long)config.id()};
PlQuery query("pre_SEND_COMMIT", PlTermv(Req_digest, V, N, Replica_id));
- while ( query.next_solution() )
- {
+ while (query.next_solution()) {
std::unique_ptr p_action =
- std::make_unique(wallet, Replica_id, Req_digest, V, N);
+ std::make_unique(wallet, Replica_id, Req_digest, V, N);
results.emplace_back(move(p_action));
}
return results;
}
-int SendCommit::effect() const
-{
+int SendCommit::effect() const {
std::string pre_signature = m_wallet.GetPreSignatureShare();
BOOST_LOG_TRIVIAL(debug) << str(
- boost::format( "%1% effect(), pre_signature that will be sent by R%2% = %3%" )
- % this->identify()
- % m_replica_id
- % pre_signature.substr(0,5)
- );
+ boost::format("%1% effect(), pre_signature that will be sent by R%2% = %3%") % this->identify() %
+ m_replica_id % pre_signature.substr(0, 5));
// We build the commit to send
- Commit msg{ m_replica_id,
- m_view, m_seq_number, pre_signature
- };
+ Commit msg{m_replica_id, m_view, m_seq_number, pre_signature};
- PlTermv args(
- PlTerm((long) m_view),
- PlTerm((long) m_seq_number),
- PlString((const char*) msg.pre_signature().c_str()),
- PlTerm((long) m_replica_id)
- );
+ PlTermv args(PlTerm((long)m_view), PlTerm((long)m_seq_number),
+ PlString((const char*)msg.pre_signature().c_str()), PlTerm((long)m_replica_id));
return PlCall("effect_SEND_COMMIT", args);
}
-std::string SendCommit::identify() const
-{
- return str(
- boost::format( "<%1%, Req=%2%, V=%3%, N=%4%, R=%5%>" )
- % name()
- % m_request.digest()
- % m_view
- % m_seq_number
- % m_replica_id
- );
+std::string SendCommit::identify() const {
+ return str(boost::format("<%1%, Req=%2%, V=%3%, N=%4%, R=%5%>") % name() % m_request.digest() % m_view %
+ m_seq_number % m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/SendNewView.cpp b/src/fbft/actions/SendNewView.cpp
index b276f07..b073aa0 100644
--- a/src/fbft/actions/SendNewView.cpp
+++ b/src/fbft/actions/SendNewView.cpp
@@ -3,9 +3,9 @@
#include "actions.h"
+#include
#include
#include
-#include
#include "../../blockchain/blockchain.h"
#include "../../wallet/wallet.h"
@@ -20,47 +20,33 @@ namespace itcoin {
namespace fbft {
namespace actions {
-std::vector> SendNewView::BuildActives(
- const itcoin::FbftConfig& config,
- Blockchain& blockchain,
- RoastWallet& wallet
-)
-{
+std::vector>
+SendNewView::BuildActives(const itcoin::FbftConfig& config, Blockchain& blockchain, RoastWallet& wallet) {
std::vector> results{};
- PlTerm Nu, Chi, Replica_id{(long) config.id()};
+ PlTerm Nu, Chi, Replica_id{(long)config.id()};
PlQuery query("pre_SEND_NEW_VIEW", PlTermv(Nu, Chi, Replica_id));
- while ( query.next_solution() )
- {
+ while (query.next_solution()) {
auto nu = NewView::nu_from_plterm(Nu);
auto chi = NewView::chi_from_plterm(Chi);
- unique_ptr action =
- std::make_unique(config.id(), nu, chi);
+ unique_ptr action = std::make_unique(config.id(), nu, chi);
results.emplace_back(std::move(action));
}
return results;
}
-int SendNewView::effect() const
-{
- PlTermv args(
- NewView::nu_as_plterm(m_nu), // Nu
- NewView::chi_as_plterm(m_chi), // Chi
- PlTerm((long) m_replica_id)
- );
+int SendNewView::effect() const {
+ PlTermv args(NewView::nu_as_plterm(m_nu), // Nu
+ NewView::chi_as_plterm(m_chi), // Chi
+ PlTerm((long)m_replica_id));
return PlCall("effect_SEND_NEW_VIEW", args);
}
-std::string SendNewView::identify() const
-{
- return str(
- boost::format( "<%1%, R=%2%>" )
- % name()
- % m_replica_id
- );
+std::string SendNewView::identify() const {
+ return str(boost::format("<%1%, R=%2%>") % name() % m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/SendPrePrepare.cpp b/src/fbft/actions/SendPrePrepare.cpp
index c753d7b..1a749c3 100644
--- a/src/fbft/actions/SendPrePrepare.cpp
+++ b/src/fbft/actions/SendPrePrepare.cpp
@@ -3,9 +3,9 @@
#include "actions.h"
+#include
#include
#include
-#include
#include "../../blockchain/blockchain.h"
#include "../../wallet/wallet.h"
@@ -20,52 +20,39 @@ namespace itcoin {
namespace fbft {
namespace actions {
-SendPrePrepare::SendPrePrepare(Blockchain& blockchain,
-PlTerm Replica_id, PlTerm Req_digest, PlTerm V, PlTerm N)
-: Action(Replica_id), m_blockchain(blockchain)
-{
- m_view = (long) V;
- m_seq_number = (long) N;
+SendPrePrepare::SendPrePrepare(Blockchain& blockchain, PlTerm Replica_id, PlTerm Req_digest, PlTerm V,
+ PlTerm N)
+ : Action(Replica_id), m_blockchain(blockchain) {
+ m_view = (long)V;
+ m_seq_number = (long)N;
// Retrieve request
- std::string req_digest = (char*) Req_digest;
+ std::string req_digest = (char*)Req_digest;
m_request = messages::Request::FindByDigest(m_replica_id, req_digest);
}
-std::vector> SendPrePrepare::BuildActives(
- const itcoin::FbftConfig& config,
- Blockchain& blockchain,
- RoastWallet& wallet
-)
-{
+std::vector>
+SendPrePrepare::BuildActives(const itcoin::FbftConfig& config, Blockchain& blockchain, RoastWallet& wallet) {
std::vector> results{};
- PlTerm Req_digest, V, N, Replica_id{(long) config.id()};
+ PlTerm Req_digest, V, N, Replica_id{(long)config.id()};
PlQuery query("pre_SEND_PRE_PREPARE", PlTermv(Req_digest, V, N, Replica_id));
- while ( query.next_solution() )
- {
+ while (query.next_solution()) {
std::unique_ptr action =
- std::make_unique(blockchain,
- Replica_id, Req_digest, V, N);
+ std::make_unique(blockchain, Replica_id, Req_digest, V, N);
results.emplace_back(std::move(action));
}
return results;
}
-int SendPrePrepare::effect() const
-{
+int SendPrePrepare::effect() const {
// We create the block to propose
CBlock proposed_block;
- try
- {
- proposed_block = m_blockchain.GenerateBlock( m_request.timestamp() );
- }
- catch(const std::runtime_error& e)
- {
+ try {
+ proposed_block = m_blockchain.GenerateBlock(m_request.timestamp());
+ } catch (const std::runtime_error& e) {
BOOST_LOG_TRIVIAL(error) << str(
- boost::format( "%1% effect(), GenerateBlock raised runtime exception = %2%" )
- % this->identify()
- % e.what()
- );
+ boost::format("%1% effect(), GenerateBlock raised runtime exception = %2%") % this->identify() %
+ e.what());
return 0;
}
@@ -73,40 +60,23 @@ int SendPrePrepare::effect() const
const uint32_t block_size_bytes = block_ser.GetHex().length() / 2;
const std::string block_hash = proposed_block.GetBlockHeader().GetHash().ToString();
- BOOST_LOG_TRIVIAL(debug) << str(
- boost::format( "%1% effect(), Proposed block size: %2% bytes, hash: %3%" )
- % this->identify()
- % block_size_bytes
- % block_hash
- );
+ BOOST_LOG_TRIVIAL(debug) << str(boost::format("%1% effect(), Proposed block size: %2% bytes, hash: %3%") %
+ this->identify() % block_size_bytes % block_hash);
// Now the PrePrepare is ready to be sent, we can save it into the message store
- messages::PrePrepare msg(m_replica_id,
- m_view, m_seq_number, m_request.digest().c_str(),
- proposed_block);
+ messages::PrePrepare msg(m_replica_id, m_view, m_seq_number, m_request.digest().c_str(), proposed_block);
- PlTermv args(
- PlString((const char*) m_request.digest().c_str()),
- PlString((const char*) msg.proposed_block_hex().c_str()),
- PlTerm((long) m_view),
- PlTerm((long) m_seq_number),
- PlTerm((long) m_replica_id)
- );
+ PlTermv args(PlString((const char*)m_request.digest().c_str()),
+ PlString((const char*)msg.proposed_block_hex().c_str()), PlTerm((long)m_view),
+ PlTerm((long)m_seq_number), PlTerm((long)m_replica_id));
return PlCall("effect_SEND_PRE_PREPARE", args);
}
-std::string SendPrePrepare::identify() const
-{
- return str(
- boost::format( "<%1%, Request=%2%, V=%3%, N=%4%, R=%5%>" )
- % name()
- % m_request.digest()
- % m_view
- % m_seq_number
- % m_replica_id
- );
+std::string SendPrePrepare::identify() const {
+ return str(boost::format("<%1%, Request=%2%, V=%3%, N=%4%, R=%5%>") % name() % m_request.digest() % m_view %
+ m_seq_number % m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/SendPrepare.cpp b/src/fbft/actions/SendPrepare.cpp
index 13a63d3..559b736 100644
--- a/src/fbft/actions/SendPrepare.cpp
+++ b/src/fbft/actions/SendPrepare.cpp
@@ -3,9 +3,9 @@
#include "actions.h"
+#include
#include
#include
-#include
#include "../../blockchain/blockchain.h"
#include "../../wallet/wallet.h"
@@ -20,58 +20,39 @@ namespace itcoin {
namespace fbft {
namespace actions {
-SendPrepare::SendPrepare(PlTerm Replica_id, PlTerm Req_digest, PlTerm V, PlTerm N)
-: Action(Replica_id)
-{
- m_view = (long) V;
- m_seq_number = (long) N;
+SendPrepare::SendPrepare(PlTerm Replica_id, PlTerm Req_digest, PlTerm V, PlTerm N) : Action(Replica_id) {
+ m_view = (long)V;
+ m_seq_number = (long)N;
// Retrieve payload from the msg store
- std::string req_digest = (char*) Req_digest;
+ std::string req_digest = (char*)Req_digest;
m_request = messages::Request::FindByDigest(m_replica_id, req_digest);
}
-std::vector> SendPrepare::BuildActives(
- const itcoin::FbftConfig& config,
- Blockchain& blockchain,
- RoastWallet& wallet
-)
-{
+std::vector>
+SendPrepare::BuildActives(const itcoin::FbftConfig& config, Blockchain& blockchain, RoastWallet& wallet) {
std::vector> results{};
- PlTerm Req_digest, V, N, Replica_id{(long) config.id()};
+ PlTerm Req_digest, V, N, Replica_id{(long)config.id()};
PlQuery query("pre_SEND_PREPARE", PlTermv(Req_digest, V, N, Replica_id));
- while ( query.next_solution() )
- {
+ while (query.next_solution()) {
std::unique_ptr action =
- std::make_unique(Replica_id, Req_digest, V, N);
+ std::make_unique(Replica_id, Req_digest, V, N);
results.emplace_back(std::move(action));
}
return results;
}
-int SendPrepare::effect() const
-{
- PlTermv args(
- PlString((const char*) m_request.digest().c_str()),
- PlTerm((long) m_view),
- PlTerm((long) m_seq_number),
- PlTerm((long) m_replica_id)
- );
+int SendPrepare::effect() const {
+ PlTermv args(PlString((const char*)m_request.digest().c_str()), PlTerm((long)m_view),
+ PlTerm((long)m_seq_number), PlTerm((long)m_replica_id));
return PlCall("effect_SEND_PREPARE", args);
}
-std::string SendPrepare::identify() const
-{
- return str(
- boost::format( "<%1%, Request=%2%, V=%3%, N=%4%, R=%5%>" )
- % name()
- % m_request.digest()
- % m_view
- % m_seq_number
- % m_replica_id
- );
+std::string SendPrepare::identify() const {
+ return str(boost::format("<%1%, Request=%2%, V=%3%, N=%4%, R=%5%>") % name() % m_request.digest() % m_view %
+ m_seq_number % m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/SendViewChange.cpp b/src/fbft/actions/SendViewChange.cpp
index b6c79d9..d49d9e1 100644
--- a/src/fbft/actions/SendViewChange.cpp
+++ b/src/fbft/actions/SendViewChange.cpp
@@ -3,9 +3,9 @@
#include "actions.h"
+#include
#include
#include
-#include
#include "../../blockchain/blockchain.h"
#include "../../wallet/wallet.h"
@@ -20,44 +20,29 @@ namespace itcoin {
namespace fbft {
namespace actions {
-std::vector> SendViewChange::BuildActives(
- const itcoin::FbftConfig& config,
- Blockchain& blockchain,
- RoastWallet& wallet
-)
-{
+std::vector>
+SendViewChange::BuildActives(const itcoin::FbftConfig& config, Blockchain& blockchain, RoastWallet& wallet) {
std::vector> results{};
- PlTerm V, Replica_id{(long) config.id()};
+ PlTerm V, Replica_id{(long)config.id()};
PlQuery query("pre_SEND_VIEW_CHANGE", PlTermv(V, Replica_id));
- while ( query.next_solution() )
- {
- uint32_t v = (long) V;
+ while (query.next_solution()) {
+ uint32_t v = (long)V;
std::unique_ptr action =
- std::make_unique(config.id(), v);
+ std::make_unique(config.id(), v);
results.emplace_back(std::move(action));
}
return results;
}
-int SendViewChange::effect() const
-{
- PlTermv args(
- PlTerm((long) m_view),
- PlTerm((long) m_replica_id)
- );
+int SendViewChange::effect() const {
+ PlTermv args(PlTerm((long)m_view), PlTerm((long)m_replica_id));
return PlCall("effect_SEND_VIEW_CHANGE", args);
}
-std::string SendViewChange::identify() const
-{
- return str(
- boost::format( "<%1%, V=%2%, R=%3%>" )
- % name()
- % m_view
- % m_replica_id
- );
+std::string SendViewChange::identify() const {
+ return str(boost::format("<%1%, V=%2%, R=%3%>") % name() % m_view % m_replica_id);
}
-}
-}
-}
+} // namespace actions
+} // namespace fbft
+} // namespace itcoin
diff --git a/src/fbft/actions/actions.h b/src/fbft/actions/actions.h
index 0ca3d55..65b27c1 100644
--- a/src/fbft/actions/actions.h
+++ b/src/fbft/actions/actions.h
@@ -9,21 +9,25 @@
#include "../messages/messages.h"
namespace itcoin {
- enum SIGNATURE_ALGO_TYPE : unsigned int;
- class FbftConfig;
-}
+enum SIGNATURE_ALGO_TYPE : unsigned int;
+class FbftConfig;
+} // namespace itcoin
-namespace itcoin { namespace blockchain {
- class Blockchain;
-}}
+namespace itcoin {
+namespace blockchain {
+class Blockchain;
+}
+} // namespace itcoin
-namespace itcoin { namespace wallet {
- class RoastWallet;
-}}
+namespace itcoin {
+namespace wallet {
+class RoastWallet;
+}
+} // namespace itcoin
-namespace blockchain=itcoin::blockchain;
-namespace wallet=itcoin::wallet;
-namespace messages=itcoin::fbft::messages;
+namespace blockchain = itcoin::blockchain;
+namespace wallet = itcoin::wallet;
+namespace messages = itcoin::fbft::messages;
namespace itcoin {
namespace fbft {
@@ -52,317 +56,337 @@ enum class ACTION_TYPE {
};
const std::string ACTION_TYPE_TYPE_AS_STRING[] = {
- "INVALID",
- "EXECUTE",
- "PROCESS_NEW_VIEW",
- "RECEIVE_BLOCK",
- "RECEIVE_COMMIT",
- "RECEIVE_NEW_VIEW",
- "RECEIVE_PREPARE",
- "RECEIVE_PRE_PREPARE",
- "RECEIVE_REQUEST",
- "RECEIVE_VIEW_CHANGE",
- "RECOVER_VIEW",
- "SEND_COMMIT",
- "SEND_NEW_VIEW",
- "SEND_PREPARE",
- "SEND_PRE_PREPARE",
- "SEND_VIEW_CHANGE",
- "ROAST_INIT",
- "ROAST_RECEIVE_PRE_SIGNATURE",
- "ROAST_RECEIVE_SIGNATURE_SHARE",
+ "INVALID",
+ "EXECUTE",
+ "PROCESS_NEW_VIEW",
+ "RECEIVE_BLOCK",
+ "RECEIVE_COMMIT",
+ "RECEIVE_NEW_VIEW",
+ "RECEIVE_PREPARE",
+ "RECEIVE_PRE_PREPARE",
+ "RECEIVE_REQUEST",
+ "RECEIVE_VIEW_CHANGE",
+ "RECOVER_VIEW",
+ "SEND_COMMIT",
+ "SEND_NEW_VIEW",
+ "SEND_PREPARE",
+ "SEND_PRE_PREPARE",
+ "SEND_VIEW_CHANGE",
+ "ROAST_INIT",
+ "ROAST_RECEIVE_PRE_SIGNATURE",
+ "ROAST_RECEIVE_SIGNATURE_SHARE",
};
class Action {
- public:
- Action(uint32_t replica_id);
- Action(PlTerm Replica_id);
- virtual ~Action() {};
+public:
+ Action(uint32_t replica_id);
+ Action(PlTerm Replica_id);
+ virtual ~Action(){};
- // Getters
- virtual std::string identify() const = 0;
- virtual std::optional> message() const;
- std::string name() const;
- virtual ACTION_TYPE type() const = 0;
+ // Getters
+ virtual std::string identify() const = 0;
+ virtual std::optional> message() const;
+ std::string name() const;
+ virtual ACTION_TYPE type() const = 0;
- // Operations
- virtual int effect() const = 0;
+ // Operations
+ virtual int effect() const = 0;
- // Operators
- friend std::ostream& operator<<(std::ostream& Str, const Action& action);
+ // Operators
+ friend std::ostream& operator<<(std::ostream& Str, const Action& action);
- protected:
- uint32_t m_replica_id;
+protected:
+ uint32_t m_replica_id;
};
class Execute : public Action {
- public:
- Execute(blockchain::Blockchain& blockchain, wallet::RoastWallet& wallet,
- PlTerm Replica_id, PlTerm Req_digest, PlTerm V, PlTerm N);
- ~Execute() {};
+public:
+ Execute(blockchain::Blockchain& blockchain, wallet::RoastWallet& wallet, PlTerm Replica_id,
+ PlTerm Req_digest, PlTerm V, PlTerm N);
+ ~Execute(){};
- std::string identify() const;
- ACTION_TYPE type() const { return ACTION_TYPE::EXECUTE; }
+ std::string identify() const;
+ ACTION_TYPE type() const { return ACTION_TYPE::EXECUTE; }
- int effect() const;
+ int effect() const;
- static std::vector> BuildActives(const itcoin::FbftConfig& config,
- blockchain::Blockchain& blockchain, wallet::RoastWallet& wallet);
+ static std::vector> BuildActives(const itcoin::FbftConfig& config,
+ blockchain::Blockchain& blockchain,
+ wallet::RoastWallet& wallet);
- private:
- blockchain::Blockchain& m_blockchain;
- wallet::RoastWallet& m_wallet;
+private:
+ blockchain::Blockchain& m_blockchain;
+ wallet::RoastWallet& m_wallet;
- messages::Request m_request;
- uint32_t m_view;
- uint32_t m_seq_number;
+ messages::Request m_request;
+ uint32_t m_view;
+ uint32_t m_seq_number;
};
-class ProcessNewView: public Action {
- public:
- ProcessNewView(PlTerm Replica_id, PlTerm Hi, PlTerm Nu, PlTerm Chi);
- ~ProcessNewView() {};
+class ProcessNewView : public Action {
+public:
+ ProcessNewView(PlTerm Replica_id, PlTerm Hi, PlTerm Nu, PlTerm Chi);
+ ~ProcessNewView(){};
- std::string identify() const;
- ACTION_TYPE type() const { return ACTION_TYPE::PROCESS_NEW_VIEW; }
+ std::string identify() const;
+ ACTION_TYPE type() const { return ACTION_TYPE::PROCESS_NEW_VIEW; }
- int effect() const;
+ int effect() const;
- static std::vector> BuildActives(const itcoin::FbftConfig& config,
- blockchain::Blockchain& blockchain, wallet::RoastWallet& wallet);
+ static std::vector>
+ BuildActives(const itcoin::FbftConfig& config, blockchain::Blockchain& blockchain,
+ wallet::RoastWallet& wallet);
- private:
- uint32_t m_hi;
- messages::new_view_nu_t m_nu;
- messages::new_view_chi_t m_chi;
+private:
+ uint32_t m_hi;
+ messages::new_view_nu_t m_nu;
+ messages::new_view_chi_t m_chi;
};
class ReceiveBlock : public Action {
- public:
- ReceiveBlock(uint32_t replica_id, messages::Block msg):Action(replica_id), m_msg(msg){};
- ~ReceiveBlock() {};
+public:
+ ReceiveBlock(uint32_t replica_id, messages::Block msg) : Action(replica_id), m_msg(msg){};
+ ~ReceiveBlock(){};
- std::string identify() const;
- std::optional> message() const {return std::optional>((const messages::Message&) m_msg);}
- ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_BLOCK; }
+ std::string identify() const;
+ std::optional> message() const {
+ return std::optional>((const messages::Message&)m_msg);
+ }
+ ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_BLOCK; }
- int effect() const;
+ int effect() const;
- private:
- messages::Block m_msg;
+private:
+ messages::Block m_msg;
};
class ReceiveCommit : public Action {
- public:
- ReceiveCommit(uint32_t replica_id, messages::Commit msg):Action(replica_id), m_msg(msg){};
- ~ReceiveCommit() {};
+public:
+ ReceiveCommit(uint32_t replica_id, messages::Commit msg) : Action(replica_id), m_msg(msg){};
+ ~ReceiveCommit(){};
- std::string identify() const;
- std::optional> message() const {return std::optional>((const messages::Message&) m_msg);}
- ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_COMMIT; }
+ std::string identify() const;
+ std::optional> message() const {
+ return std::optional>((const messages::Message&)m_msg);
+ }
+ ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_COMMIT; }
- int effect() const;
+ int effect() const;
- private:
- messages::Commit m_msg;
+private:
+ messages::Commit m_msg;
};
class ReceiveNewView : public Action {
- public:
- ReceiveNewView(wallet::RoastWallet& wallet, uint32_t replica_id, messages::NewView msg);
- ~ReceiveNewView() {};
+public:
+ ReceiveNewView(wallet::RoastWallet& wallet, uint32_t replica_id, messages::NewView msg);
+ ~ReceiveNewView(){};
- std::string identify() const;
- std::optional> message() const {return std::optional>((const messages::Message&) m_msg);}
- ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_NEW_VIEW; }
+ std::string identify() const;
+ std::optional> message() const {
+ return std::optional>((const messages::Message&)m_msg);
+ }
+ ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_NEW_VIEW; }
- int effect() const;
+ int effect() const;
- private:
- wallet::RoastWallet& m_wallet;
+private:
+ wallet::RoastWallet& m_wallet;
- messages::NewView m_msg;
+ messages::NewView m_msg;
};
class ReceivePrepare : public Action {
- public:
- ReceivePrepare(uint32_t replica_id, messages::Prepare msg): Action(replica_id), m_msg(msg){};;
- ~ReceivePrepare() {};
+public:
+ ReceivePrepare(uint32_t replica_id, messages::Prepare msg) : Action(replica_id), m_msg(msg){};
+ ;
+ ~ReceivePrepare(){};
- std::string identify() const;
- std::optional> message() const {return std::optional>((const messages::Message&) m_msg);}
- ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_PREPARE; }
+ std::string identify() const;
+ std::optional> message() const {
+ return std::optional>((const messages::Message&)m_msg);
+ }
+ ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_PREPARE; }
- int effect() const;
+ int effect() const;
- private:
- messages::Prepare m_msg;
+private:
+ messages::Prepare m_msg;
};
class ReceivePrePrepare : public Action {
- public:
- ReceivePrePrepare(uint32_t replica_id, blockchain::Blockchain& blockchain,
- double current_time, double pre_prepare_time_tolerance_delta, messages::PrePrepare msg);
- ~ReceivePrePrepare(){};
-
- std::string identify() const;
- std::optional> message() const {return std::optional>((const messages::Message&) m_msg);}
- ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_PRE_PREPARE; }
-
- int effect() const;
-
- private:
- blockchain::Blockchain& m_blockchain;
- double m_current_time;
- double m_pre_prepare_time_tolerance_delta;
- messages::PrePrepare m_msg;
+public:
+ ReceivePrePrepare(uint32_t replica_id, blockchain::Blockchain& blockchain, double current_time,
+ double pre_prepare_time_tolerance_delta, messages::PrePrepare msg);
+ ~ReceivePrePrepare(){};
+
+ std::string identify() const;
+ std::optional> message() const {
+ return std::optional>((const messages::Message&)m_msg);
+ }
+ ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_PRE_PREPARE; }
+
+ int effect() const;
+
+private:
+ blockchain::Blockchain& m_blockchain;
+ double m_current_time;
+ double m_pre_prepare_time_tolerance_delta;
+ messages::PrePrepare m_msg;
};
class ReceiveRequest : public Action {
- public:
- ReceiveRequest(uint32_t replica_id, messages::Request request): Action(replica_id), m_msg(request){};
- ~ReceiveRequest(){};
+public:
+ ReceiveRequest(uint32_t replica_id, messages::Request request) : Action(replica_id), m_msg(request){};
+ ~ReceiveRequest(){};
- std::string identify() const;
- std::optional> message() const {return std::optional>((const messages::Message&) m_msg);}
- ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_REQUEST; }
+ std::string identify() const;
+ std::optional> message() const {
+ return std::optional>((const messages::Message&)m_msg);
+ }
+ ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_REQUEST; }
- int effect() const;
+ int effect() const;
- private:
- messages::Request m_msg;
+private:
+ messages::Request m_msg;
};
class ReceiveViewChange : public Action {
- public:
- ReceiveViewChange(uint32_t replica_id, messages::ViewChange msg): Action(replica_id), m_msg(msg){};
- ~ReceiveViewChange(){};
+public:
+ ReceiveViewChange(uint32_t replica_id, messages::ViewChange msg) : Action(replica_id), m_msg(msg){};
+ ~ReceiveViewChange(){};
- std::string identify() const;
- std::optional> message() const {return std::optional>((const messages::Message&) m_msg);}
- ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_VIEW_CHANGE; }
+ std::string identify() const;
+ std::optional> message() const {
+ return std::optional>((const messages::Message&)m_msg);
+ }
+ ACTION_TYPE type() const { return ACTION_TYPE::RECEIVE_VIEW_CHANGE; }
- int effect() const;
+ int effect() const;
- private:
- messages::ViewChange m_msg;
+private:
+ messages::ViewChange m_msg;
};
-class RecoverView: public Action {
- public:
- RecoverView(uint32_t replica_id, uint32_t view);
- ~RecoverView();
+class RecoverView : public Action {
+public:
+ RecoverView(uint32_t replica_id, uint32_t view);
+ ~RecoverView();
- std::string identify() const;
- ACTION_TYPE type() const { return ACTION_TYPE::RECOVER_VIEW; }
- int effect() const;
+ std::string identify() const;
+ ACTION_TYPE type() const { return ACTION_TYPE::RECOVER_VIEW; }
+ int effect() const;
- static std::vector