Skip to content

Commit 2481fc3

Browse files
committed
comment
Signed-off-by: turuslan <[email protected]>
1 parent f6e4227 commit 2481fc3

File tree

10 files changed

+74
-6
lines changed

10 files changed

+74
-6
lines changed

src/blockchain/block_tree.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,24 @@ namespace lean::blockchain {
153153
*/
154154
[[nodiscard]] virtual BlockIndex lastFinalized() const = 0;
155155

156+
/**
157+
* Get message for "/leanconsensus/req/status/1/ssz_snappy" protocol.
158+
* Returns hash and slot for finalized and best blocks.
159+
*/
156160
virtual StatusMessage getStatusMessage() const = 0;
157161

162+
/**
163+
* Get `SignedBlock` for "/leanconsensus/req/blocks_by_root/1/ssz_snappy"
164+
* protocol.
165+
*/
158166
virtual outcome::result<std::optional<SignedBlock>> tryGetSignedBlock(
159167
const BlockHash block_hash) const = 0;
160168

169+
// TODO(turuslan): state transition function
170+
/**
171+
* Import pre-sorted batch of `SignedBlock`.
172+
* May change best and finalized block.
173+
*/
161174
virtual void import(std::vector<SignedBlock> blocks) = 0;
162175
};
163176

src/blockchain/impl/block_tree_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,14 +824,14 @@ namespace lean::blockchain {
824824
.state_root = header.state_root,
825825
.body = std::move(body),
826826
},
827-
// TODO: signature
827+
// TODO(turuslan): signature
828828
.signature = {},
829829
};
830830
}
831831

832832
void BlockTreeImpl::import(std::vector<SignedBlock> blocks) {
833833
for (auto &block : blocks) {
834-
// TODO: signature
834+
// TODO(turuslan): signature
835835
std::ignore = addBlock(block.message);
836836
}
837837
}

src/libp2p/peer/peer_id_from.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include <qtils/bytes.hpp>
1313

1414
namespace libp2p {
15+
/**
16+
* Convert secp256k1 public key to `PeerId`.
17+
*/
1518
inline PeerId peerIdFromSecp256k1(
1619
const crypto::secp256k1::PublicKey &public_key) {
1720
return libp2p::PeerId::fromPublicKey(

src/modules/networking/networking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "utils/sample_peer.hpp"
2727

2828
namespace lean::modules {
29-
// TODO: gossip [from,seqno,signature,key]=None
29+
// TODO(turuslan): gossip [from,seqno,signature,key]=None
3030

3131
inline auto gossipTopic(std::string_view type) {
3232
return std::format("/leanconsensus/devnet0/{}/ssz_snappy", type);
@@ -421,7 +421,7 @@ namespace lean::modules {
421421
});
422422
}
423423

424-
// TODO: detect finalized change
424+
// TODO(turuslan): detect finalized change
425425
void NetworkingImpl::receiveBlock(std::optional<libp2p::PeerId> from_peer,
426426
SignedBlock &&block) {
427427
auto slot_hash = block.message.slotHash();

src/modules/networking/networking.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ namespace lean::modules {
3232
class StatusProtocol;
3333
class BlockRequestProtocol;
3434

35+
/**
36+
* Network module.
37+
*
38+
* Sends produced blocks and signed votes.
39+
* Syncs blocks from other peers.
40+
* Receives votes from other peers.
41+
*
42+
* Protocols:
43+
* - Status handshake protocol (best and finalized block info).
44+
* - Block request protocol (`SignedBlock` by hash).
45+
* - `SignedBlock` and `SignedVote` gossip protocol.
46+
*/
3547
class NetworkingImpl final : public Singleton<Networking>, public Networking {
3648
NetworkingImpl(NetworkingLoader &loader,
3749
qtils::SharedRef<log::LoggingSystem> logging_system,

src/modules/production/production.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ namespace lean::modules {
6868
// Notify subscribers
6969
loader_.dispatch_block_produced(std::make_shared<const Block>(block));
7070

71-
// TODO: signature
71+
// TODO(turuslan): signature
7272
loader_.dispatch_SendSignedBlock(
7373
std::make_shared<messages::SendSignedBlock>(
7474
SignedBlock{.message = block}));

src/modules/shared/macro.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,37 @@
66

77
#pragma once
88

9+
/**
10+
* Macro to work with subscriptions and messages.
11+
*
12+
* struct Message { ... };
13+
*
14+
* struct IModule {
15+
* // Send `Message` to subscription
16+
* VIRTUAL_DISPATCH(Message);
17+
*
18+
* // Received `Message` from subscription
19+
* VIRTUAL_ON_DISPATCH(Message);
20+
* };
21+
* struct Module : IModule {
22+
* ON_DISPATCH_SUBSCRIPTION(Message);
23+
*
24+
* void start() {
25+
* ON_DISPATCH_SUBSCRIBE(Message);
26+
* }
27+
*
28+
* DISPATCH_OVERRIDE(Message) {
29+
* log("dispatch Message");
30+
* dispatchDerive(subscription, message);
31+
* }
32+
*
33+
* ON_DISPATCH_OVERRIDE(Message);
34+
* };
35+
* ON_DISPATCH_IMPL(Module, Message) {
36+
* log("received Message");
37+
* }
38+
*/
39+
940
#define VIRTUAL_DISPATCH(T) \
1041
virtual void dispatch_##T(std::shared_ptr<const messages::T> message) = 0
1142
#define DISPATCH_OVERRIDE(T) \

src/qtils/to_shared_ptr.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <memory>
1010

1111
namespace qtils {
12+
/**
13+
* Make `shared_ptr` from object of type `T`.
14+
*/
1215
template <typename T>
1316
auto toSharedPtr(T &&t) {
1417
return std::make_shared<std::remove_cvref_t<T>>(std::forward<T>(t));

src/se/subscription_fwd.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ namespace lean {
8989
Derive,
9090
};
9191

92+
/**
93+
* Get `EventType` auto-assigned to type `T`.
94+
*/
9295
class DeriveEventType {
9396
public:
9497
template <typename T>
@@ -105,6 +108,9 @@ namespace lean {
105108
}
106109
};
107110

111+
/**
112+
* Call `notify` with `EventType` auto-assigned to type `T`.
113+
*/
108114
template <typename T>
109115
void dispatchDerive(auto &subscription, const std::shared_ptr<T> &message) {
110116
subscription.notify(DeriveEventType::get<std::remove_cvref_t<T>>(),

src/utils/__debug_env.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <cstdlib>
44
#include <string>
55

6-
// TODO: config
6+
// TODO(turuslan): config
77
inline size_t getPeerIndex() {
88
static size_t i = [] {
99
if (auto s = getenv("PeerIndex")) {

0 commit comments

Comments
 (0)