Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/protocol.h
// Copyright (c) 2020 The Bitcoin developers | // Copyright (c) 2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_AVALANCHE_PROTOCOL_H | #ifndef BITCOIN_AVALANCHE_PROTOCOL_H | ||||
#define BITCOIN_AVALANCHE_PROTOCOL_H | #define BITCOIN_AVALANCHE_PROTOCOL_H | ||||
#include <protocol.h> // for CInv | #include <protocol.h> // for CInv | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <vector> | #include <vector> | ||||
class AvalancheVote { | namespace avalanche { | ||||
class Vote { | |||||
uint32_t error; | uint32_t error; | ||||
uint256 hash; | uint256 hash; | ||||
public: | public: | ||||
AvalancheVote() : error(-1), hash() {} | Vote() : error(-1), hash() {} | ||||
AvalancheVote(uint32_t errorIn, uint256 hashIn) | Vote(uint32_t errorIn, uint256 hashIn) : error(errorIn), hash(hashIn) {} | ||||
: error(errorIn), hash(hashIn) {} | |||||
const uint256 &GetHash() const { return hash; } | const uint256 &GetHash() const { return hash; } | ||||
uint32_t GetError() const { return error; } | uint32_t GetError() const { return error; } | ||||
// serialization support | // serialization support | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(error); | READWRITE(error); | ||||
READWRITE(hash); | READWRITE(hash); | ||||
} | } | ||||
}; | }; | ||||
class AvalancheResponse { | class Response { | ||||
uint64_t round; | uint64_t round; | ||||
uint32_t cooldown; | uint32_t cooldown; | ||||
std::vector<AvalancheVote> votes; | std::vector<Vote> votes; | ||||
public: | public: | ||||
AvalancheResponse() : round(-1), cooldown(-1) {} | Response() : round(-1), cooldown(-1) {} | ||||
AvalancheResponse(uint64_t roundIn, uint32_t cooldownIn, | Response(uint64_t roundIn, uint32_t cooldownIn, std::vector<Vote> votesIn) | ||||
std::vector<AvalancheVote> votesIn) | |||||
: round(roundIn), cooldown(cooldownIn), votes(votesIn) {} | : round(roundIn), cooldown(cooldownIn), votes(votesIn) {} | ||||
uint64_t getRound() const { return round; } | uint64_t getRound() const { return round; } | ||||
uint32_t getCooldown() const { return cooldown; } | uint32_t getCooldown() const { return cooldown; } | ||||
const std::vector<AvalancheVote> &GetVotes() const { return votes; } | const std::vector<Vote> &GetVotes() const { return votes; } | ||||
// serialization support | // serialization support | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(round); | READWRITE(round); | ||||
READWRITE(cooldown); | READWRITE(cooldown); | ||||
READWRITE(votes); | READWRITE(votes); | ||||
} | } | ||||
}; | }; | ||||
class AvalanchePoll { | class Poll { | ||||
uint64_t round; | uint64_t round; | ||||
std::vector<CInv> invs; | std::vector<CInv> invs; | ||||
public: | public: | ||||
AvalanchePoll(uint64_t roundIn, std::vector<CInv> invsIn) | Poll(uint64_t roundIn, std::vector<CInv> invsIn) | ||||
: round(roundIn), invs(invsIn) {} | : round(roundIn), invs(invsIn) {} | ||||
const std::vector<CInv> &GetInvs() const { return invs; } | const std::vector<CInv> &GetInvs() const { return invs; } | ||||
// serialization support | // serialization support | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(round); | READWRITE(round); | ||||
READWRITE(invs); | READWRITE(invs); | ||||
} | } | ||||
}; | }; | ||||
} // namespace avalanche | |||||
#endif // BITCOIN_AVALANCHE_PROTOCOL_H | #endif // BITCOIN_AVALANCHE_PROTOCOL_H |