diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -494,8 +494,8 @@ add_library(server addrdb.cpp addrman.cpp - avalanche/avalanche.cpp avalanche/peermanager.cpp + avalanche/processor.cpp banman.cpp blockencodings.cpp blockfilter.cpp diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -114,8 +114,9 @@ addrdb.h \ addrman.h \ attributes.h \ - avalanche/avalanche.h \ avalanche/peermanager.h \ + avalanche/processor.h \ + avalanche/protocol.h \ banman.h \ base58.h \ bloom.h \ @@ -294,8 +295,8 @@ libbitcoin_server_a_SOURCES = \ addrdb.cpp \ addrman.cpp \ - avalanche/avalanche.cpp \ avalanche/peermanager.cpp \ + avalanche/processor.cpp \ banman.cpp \ blockencodings.cpp \ blockfilter.cpp \ diff --git a/src/Makefile.test.include b/src/Makefile.test.include --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -79,8 +79,8 @@ # test_bitcoin binary # BITCOIN_TESTS =\ - avalanche/test/avalanche_tests.cpp \ avalanche/test/peermanager_tests.cpp \ + avalanche/test/processor_tests.cpp \ test/scriptnum10.h \ test/activation_tests.cpp \ test/addrman_tests.cpp \ diff --git a/src/avalanche/avalanche.h b/src/avalanche/processor.h rename from src/avalanche/avalanche.h rename to src/avalanche/processor.h --- a/src/avalanche/avalanche.h +++ b/src/avalanche/processor.h @@ -2,17 +2,15 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_AVALANCHE_AVALANCHE_H -#define BITCOIN_AVALANCHE_AVALANCHE_H +#ifndef BITCOIN_AVALANCHE_PROCESSOR_H +#define BITCOIN_AVALANCHE_PROCESSOR_H +#include #include #include #include #include -#include // for CInv #include -#include -#include #include #include @@ -143,74 +141,6 @@ bool addNodeToQuorum(NodeId nodeid); }; -class AvalancheVote { - uint32_t error; - uint256 hash; - -public: - AvalancheVote() : error(-1), hash() {} - AvalancheVote(uint32_t errorIn, uint256 hashIn) - : error(errorIn), hash(hashIn) {} - - const uint256 &GetHash() const { return hash; } - uint32_t GetError() const { return error; } - - // serialization support - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(error); - READWRITE(hash); - } -}; - -class AvalancheResponse { - uint64_t round; - uint32_t cooldown; - std::vector votes; - -public: - AvalancheResponse() : round(-1), cooldown(-1) {} - AvalancheResponse(uint64_t roundIn, uint32_t cooldownIn, - std::vector votesIn) - : round(roundIn), cooldown(cooldownIn), votes(votesIn) {} - - uint64_t getRound() const { return round; } - uint32_t getCooldown() const { return cooldown; } - const std::vector &GetVotes() const { return votes; } - - // serialization support - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(round); - READWRITE(cooldown); - READWRITE(votes); - } -}; - -class AvalanchePoll { - uint64_t round; - std::vector invs; - -public: - AvalanchePoll(uint64_t roundIn, std::vector invsIn) - : round(roundIn), invs(invsIn) {} - - const std::vector &GetInvs() const { return invs; } - - // serialization support - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(round); - READWRITE(invs); - } -}; - class AvalancheBlockUpdate { union { CBlockIndex *pindex; @@ -342,8 +272,8 @@ bool isAccepted(const CBlockIndex *pindex) const; int getConfidence(const CBlockIndex *pindex) const; + // TDOD: Refactor the API to remove the dependency on avalanche/protocol.h void sendResponse(CNode *pfrom, AvalancheResponse response) const; - bool registerVotes(NodeId nodeid, const AvalancheResponse &response, std::vector &updates); @@ -369,4 +299,4 @@ */ extern std::unique_ptr g_avalanche; -#endif // BITCOIN_AVALANCHE_AVALANCHE_H +#endif // BITCOIN_AVALANCHE_PROCESSOR_H diff --git a/src/avalanche/avalanche.cpp b/src/avalanche/processor.cpp rename from src/avalanche/avalanche.cpp rename to src/avalanche/processor.cpp --- a/src/avalanche/avalanche.cpp +++ b/src/avalanche/processor.cpp @@ -2,7 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include #include #include diff --git a/src/avalanche/protocol.h b/src/avalanche/protocol.h new file mode 100644 --- /dev/null +++ b/src/avalanche/protocol.h @@ -0,0 +1,83 @@ +// Copyright (c) 2020 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_AVALANCHE_PROTOCOL_H +#define BITCOIN_AVALANCHE_PROTOCOL_H + +#include // for CInv +#include +#include + +#include +#include + +class AvalancheVote { + uint32_t error; + uint256 hash; + +public: + AvalancheVote() : error(-1), hash() {} + AvalancheVote(uint32_t errorIn, uint256 hashIn) + : error(errorIn), hash(hashIn) {} + + const uint256 &GetHash() const { return hash; } + uint32_t GetError() const { return error; } + + // serialization support + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream &s, Operation ser_action) { + READWRITE(error); + READWRITE(hash); + } +}; + +class AvalancheResponse { + uint64_t round; + uint32_t cooldown; + std::vector votes; + +public: + AvalancheResponse() : round(-1), cooldown(-1) {} + AvalancheResponse(uint64_t roundIn, uint32_t cooldownIn, + std::vector votesIn) + : round(roundIn), cooldown(cooldownIn), votes(votesIn) {} + + uint64_t getRound() const { return round; } + uint32_t getCooldown() const { return cooldown; } + const std::vector &GetVotes() const { return votes; } + + // serialization support + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream &s, Operation ser_action) { + READWRITE(round); + READWRITE(cooldown); + READWRITE(votes); + } +}; + +class AvalanchePoll { + uint64_t round; + std::vector invs; + +public: + AvalanchePoll(uint64_t roundIn, std::vector invsIn) + : round(roundIn), invs(invsIn) {} + + const std::vector &GetInvs() const { return invs; } + + // serialization support + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream &s, Operation ser_action) { + READWRITE(round); + READWRITE(invs); + } +}; + +#endif // BITCOIN_AVALANCHE_PROTOCOL_H diff --git a/src/avalanche/test/CMakeLists.txt b/src/avalanche/test/CMakeLists.txt --- a/src/avalanche/test/CMakeLists.txt +++ b/src/avalanche/test/CMakeLists.txt @@ -12,8 +12,8 @@ fixture.cpp TESTS - avalanche_tests.cpp peermanager_tests.cpp + processor_tests.cpp ) target_link_libraries(test-avalanche server testutil) diff --git a/src/avalanche/test/avalanche_tests.cpp b/src/avalanche/test/processor_tests.cpp rename from src/avalanche/test/avalanche_tests.cpp rename to src/avalanche/test/processor_tests.cpp --- a/src/avalanche/test/avalanche_tests.cpp +++ b/src/avalanche/test/processor_tests.cpp @@ -2,7 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include #include #include // For PeerLogicValidation @@ -41,7 +41,7 @@ } }; -BOOST_FIXTURE_TEST_SUITE(avalanche_tests, TestChain100Setup) +BOOST_FIXTURE_TEST_SUITE(processor_tests, TestChain100Setup) #define REGISTER_VOTE_AND_CHECK(vr, vote, state, finalized, confidence) \ vr.registerVote(NO_NODE, vote); \ diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/rpc/avalanche.cpp b/src/rpc/avalanche.cpp --- a/src/rpc/avalanche.cpp +++ b/src/rpc/avalanche.cpp @@ -2,7 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include #include #include #include diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/test/sanitizer_suppressions/ubsan b/test/sanitizer_suppressions/ubsan --- a/test/sanitizer_suppressions/ubsan +++ b/test/sanitizer_suppressions/ubsan @@ -32,7 +32,7 @@ unsigned-integer-overflow:validation.cpp vptr:fs.cpp # Only occurs with the cmake build and clang-7 -vptr:avalanche_tests.cpp +vptr:avalanche/test/processor_tests.cpp # The vptr suppressions are only necessary for clang < 9 vptr:boost/test/tree/observer.hpp vptr:boost/system/error_code.hpp