Skip to content

Commit e8308c1

Browse files
committed
Removed access to the current view stored in DBRB process
1 parent 19b8cec commit e8308c1

16 files changed

+83
-108
lines changed

extensions/fastfinality/src/FastFinalityActions.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,16 @@ namespace catapult { namespace fastfinality {
387387
std::strftime(buffer, 40 ,"%F %T", std::localtime(&time));
388388
return buffer;
389389
}
390+
391+
auto GetCurrentView(const std::shared_ptr<FastFinalityFsm>& pFsmShared, extensions::ServiceState& state) {
392+
const auto& fastFinalityData = pFsmShared->fastFinalityData();
393+
auto roundStart = utils::FromTimePoint(fastFinalityData.round().RoundStart);
394+
auto view = dbrb::View{ state.pluginManager().dbrbViewFetcher().getView(roundStart) };
395+
auto bootstrapView = dbrb::View{ state.config(fastFinalityData.currentBlockHeight()).Network.DbrbBootstrapProcesses };
396+
view.merge(bootstrapView);
397+
398+
return view;
399+
}
390400
}
391401

392402
action CreateFastFinalityDetectRoundAction(
@@ -482,7 +492,7 @@ namespace catapult { namespace fastfinality {
482492
TRY_GET_FSM()
483493

484494
const auto& dbrbProcess = pFsmShared->dbrbProcess();
485-
auto view = dbrbProcess.currentView();
495+
auto view = GetCurrentView(pFsmShared, state);
486496
auto maxUnreachableNodeCount = dbrb::View::maxInvalidProcesses(view.Data.size());
487497
view.Data.erase(dbrbProcess.id());
488498
auto pMessageSender = dbrbProcess.messageSender();
@@ -551,14 +561,6 @@ namespace catapult { namespace fastfinality {
551561
CATAPULT_LOG(debug) << "skipping block producing, current time is too far in the round";
552562
pFsmShared->processEvent(WaitForBlock{});
553563
}
554-
555-
DelayAction(pFsmShared, pFsmShared->timer(), round.RoundTimeMillis / chain::CommitteePhaseCount, [pFsmWeak] {
556-
TRY_GET_FSM()
557-
558-
auto dbrbProcess = pFsmShared->dbrbProcess();
559-
auto pMessageSender = dbrbProcess.messageSender();
560-
pMessageSender->findNodes(dbrbProcess.currentView().Data);
561-
});
562564
};
563565
}
564566

@@ -588,11 +590,11 @@ namespace catapult { namespace fastfinality {
588590

589591
action CreateFastFinalityGenerateBlockAction(
590592
const std::weak_ptr<FastFinalityFsm>& pFsmWeak,
591-
const cache::CatapultCache& cache,
593+
extensions::ServiceState& state,
592594
const std::shared_ptr<config::BlockchainConfigurationHolder>& pConfigHolder,
593595
const harvesting::BlockGenerator& blockGenerator,
594596
const model::BlockElementSupplier& lastBlockElementSupplier) {
595-
return [pFsmWeak, &cache, pConfigHolder, blockGenerator, lastBlockElementSupplier]() {
597+
return [pFsmWeak, &state, pConfigHolder, blockGenerator, lastBlockElementSupplier]() {
596598
TRY_GET_FSM()
597599

598600
auto& fastFinalityData = pFsmShared->fastFinalityData();
@@ -608,7 +610,7 @@ namespace catapult { namespace fastfinality {
608610
return;
609611
}
610612

611-
if (!context.tryCalculateDifficulty(cache.sub<cache::BlockDifficultyCache>(), config.Network)) {
613+
if (!context.tryCalculateDifficulty(state.cache().sub<cache::BlockDifficultyCache>(), config.Network)) {
612614
CATAPULT_LOG(debug) << "skipping block propose attempt due to error calculating difficulty";
613615
pFsmShared->processEvent(BlockGenerationFailed{});
614616
return;
@@ -633,10 +635,11 @@ namespace catapult { namespace fastfinality {
633635
pPacket->Type = ionet::PacketType::Push_Block;
634636
std::memcpy(static_cast<void*>(pPacket->Data()), pBlock.get(), pBlock->Size);
635637

636-
DelayAction(pFsmShared, pFsmShared->timer(), config.Network.CommitteeSilenceInterval.millis(), [pFsmWeak, pPacket] {
638+
DelayAction(pFsmShared, pFsmShared->timer(), config.Network.CommitteeSilenceInterval.millis(), [pFsmWeak, pPacket, &state] {
637639
TRY_GET_FSM()
638640

639-
pFsmShared->dbrbProcess().broadcast(pPacket, pFsmShared->dbrbProcess().currentView().Data);
641+
auto view = GetCurrentView(pFsmShared, state);
642+
pFsmShared->dbrbProcess().broadcast(pPacket, view.Data);
640643
});
641644

642645
pFsmShared->processEvent(BlockGenerationSucceeded{});

extensions/fastfinality/src/FastFinalityActions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace catapult { namespace fastfinality {
6161

6262
action CreateFastFinalityGenerateBlockAction(
6363
const std::weak_ptr<FastFinalityFsm>& pFsmWeak,
64-
const cache::CatapultCache& cache,
64+
extensions::ServiceState& state,
6565
const std::shared_ptr<config::BlockchainConfigurationHolder>& pConfigHolder,
6666
const harvesting::BlockGenerator& blockGenerator,
6767
const model::BlockElementSupplier& lastBlockElementSupplier);

extensions/fastfinality/src/FastFinalityService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ namespace catapult { namespace fastfinality {
167167
actions.DetectRound = CreateFastFinalityDetectRoundAction(pFsmShared, lastBlockElementSupplier, state);
168168
actions.CheckConnections = CreateFastFinalityCheckConnectionsAction(pFsmShared, state);
169169
actions.SelectBlockProducer = CreateFastFinalitySelectBlockProducerAction(pFsmShared, state);
170-
actions.GenerateBlock = CreateFastFinalityGenerateBlockAction(pFsmShared, state.cache(), pConfigHolder, CreateHarvesterBlockGenerator(state), lastBlockElementSupplier);
170+
actions.GenerateBlock = CreateFastFinalityGenerateBlockAction(pFsmShared, state, pConfigHolder, CreateHarvesterBlockGenerator(state), lastBlockElementSupplier);
171171
actions.WaitForBlock = CreateFastFinalityWaitForBlockAction(pFsmShared, pConfigHolder);
172172
actions.CommitBlock = CreateFastFinalityCommitBlockAction(pFsmShared, blockRangeConsumer, state);
173173
actions.IncrementRound = CreateFastFinalityIncrementRoundAction(pFsmShared, pConfigHolder);

extensions/fastfinality/src/dbrb/DbrbProcess.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,11 @@ namespace catapult { namespace dbrb {
6666
return m_strand;
6767
}
6868

69-
std::shared_ptr<MessageSender> DbrbProcess::messageSender() {
69+
std::shared_ptr<MessageSender> DbrbProcess::messageSender() const {
7070
return m_pMessageSender;
7171
}
7272

73-
const View& DbrbProcess::currentView() {
74-
return m_currentView;
75-
}
76-
77-
const View& DbrbProcess::bootstrapView() {
78-
return m_bootstrapView;
79-
}
80-
81-
const ProcessId& DbrbProcess::id() {
73+
const ProcessId& DbrbProcess::id() const {
8274
return m_id;
8375
}
8476

@@ -99,17 +91,17 @@ namespace catapult { namespace dbrb {
9991
}
10092

10193
if (!(broadcastView <= pThis->m_currentView)) {
102-
CATAPULT_LOG(debug) << "[DBRB] BROADCAST: " << broadcastView << " is not a subview of the current view " << pThis->m_currentView << ", aborting broadcast";
94+
CATAPULT_LOG(debug) << "[DBRB] BROADCAST: broadcast view is not a subview of the current view, aborting broadcast";
10395
return;
10496
}
10597

10698
if (!(pThis->m_bootstrapView <= broadcastView)) {
107-
CATAPULT_LOG(debug) << "[DBRB] BROADCAST: bootstrap view " << pThis->m_bootstrapView << " is not a subview of the broadcast view " << broadcastView << ", aborting broadcast";
99+
CATAPULT_LOG(debug) << "[DBRB] BROADCAST: bootstrap view is not a subview of the broadcast view, aborting broadcast";
108100
return;
109101
}
110102

111103
if (!broadcastView.isMember(pThis->m_id)) {
112-
CATAPULT_LOG(debug) << "[DBRB] BROADCAST: not a member of the broadcast view " << broadcastView << ", aborting broadcast";
104+
CATAPULT_LOG(debug) << "[DBRB] BROADCAST: not a member of the broadcast view, aborting broadcast";
113105
return;
114106
}
115107

@@ -166,7 +158,7 @@ namespace catapult { namespace dbrb {
166158
// Basic private methods:
167159

168160
void DbrbProcess::disseminate(const std::shared_ptr<Message>& pMessage, std::set<ProcessId> recipients, uint64_t delayMillis) {
169-
CATAPULT_LOG(trace) << "[DBRB] disseminating message " << pMessage->Type << " to " << View{ recipients };
161+
CATAPULT_LOG(trace) << "[DBRB] disseminating message " << pMessage->Type << " to " << recipients.size() << " recipient(s)";
170162
auto pPacket = pMessage->toNetworkPacket();
171163
for (auto iter = recipients.begin(); iter != recipients.end(); ++iter) {
172164
if (m_id == *iter) {
@@ -209,7 +201,7 @@ namespace catapult { namespace dbrb {
209201
disseminate(pMessage, std::set<ProcessId>{ recipient }, delayMillis);
210202
}
211203

212-
Signature DbrbProcess::sign(const Payload& payload, const View& view) {
204+
Signature DbrbProcess::sign(const Payload& payload, const View& view) const {
213205
// Forms a hash based on payload and the broadcast view and signs it.
214206
uint32_t packetPayloadSize = view.packedSize();
215207
auto pPacket = ionet::CreateSharedPacket<ionet::Packet>(packetPayloadSize);
@@ -258,7 +250,7 @@ namespace catapult { namespace dbrb {
258250
}
259251

260252
if (message.BootstrapView != m_bootstrapView) {
261-
CATAPULT_LOG(debug) << "[DBRB] PREPARE: Aborting message processing (invalid bootstrap view)\nExpected bootstrap view: " << m_bootstrapView << "\nActual bootstrap view: " << message.BootstrapView;
253+
CATAPULT_LOG(debug) << "[DBRB] PREPARE: Aborting message processing (invalid bootstrap view)";
262254
return;
263255
}
264256

@@ -356,7 +348,7 @@ namespace catapult { namespace dbrb {
356348

357349
void DbrbProcess::onAcknowledgedQuorumCollected(const AcknowledgedMessage& message, BroadcastData& data) {
358350
// Replacing certificate.
359-
CATAPULT_LOG(trace) << "[DBRB] ACKNOWLEDGED: Quorum collected in view " << message.View << ". Payload " << data.Payload->Type;
351+
CATAPULT_LOG(trace) << "[DBRB] ACKNOWLEDGED: Quorum collected for payload " << data.Payload->Type;
360352
data.Certificate.clear();
361353
const auto& acknowledgedSet = data.QuorumManager.AcknowledgedPayloads[message.View];
362354
for (const auto& [processId, hash] : acknowledgedSet) {
@@ -506,10 +498,6 @@ namespace catapult { namespace dbrb {
506498
CATAPULT_LOG(debug) << "[DBRB] getting config at height " << height;
507499
const auto& config = pConfigHolder->Config(height).Network;
508500
auto bootstrapView = View{ config.DbrbBootstrapProcesses };
509-
if (bootstrapView.Data.empty()) {
510-
CATAPULT_LOG(debug) << "[DBRB] no bootstrap nodes, getting config at height " << height + Height(1);
511-
bootstrapView = View{ pConfigHolder->Config(height + Height(1)).Network.DbrbBootstrapProcesses };
512-
}
513501
if (bootstrapView.Data.empty())
514502
CATAPULT_THROW_RUNTIME_ERROR("Bootstrap view is empty")
515503
auto isBootstrapProcess = bootstrapView.isMember(m_id);
@@ -526,7 +514,7 @@ namespace catapult { namespace dbrb {
526514
pThis->m_bootstrapView = bootstrapView;
527515
auto bootstrapViewCopy = bootstrapView;
528516
pThis->m_currentView.merge(bootstrapViewCopy);
529-
CATAPULT_LOG(debug) << "[DBRB] Current view (" << pThis->m_currentView.Data.size() << ") is now set to " << pThis->m_currentView;
517+
CATAPULT_LOG(debug) << "[DBRB] Current view size " << pThis->m_currentView.Data.size();
530518

531519
pThis->m_pMessageSender->findNodes(pThis->m_currentView.Data);
532520

extensions/fastfinality/src/dbrb/DbrbProcess.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,14 @@ namespace catapult { namespace dbrb {
4545

4646
public:
4747
boost::asio::io_context::strand& strand();
48-
std::shared_ptr<MessageSender> messageSender();
49-
const View& currentView();
50-
const View& bootstrapView();
51-
const ProcessId& id();
48+
std::shared_ptr<MessageSender> messageSender() const;
49+
const ProcessId& id() const;
5250

5351
protected:
5452
virtual void disseminate(const std::shared_ptr<Message>& pMessage, std::set<ProcessId> recipients, uint64_t delayMillis);
5553
virtual void send(const std::shared_ptr<Message>& pMessage, const ProcessId& recipient, uint64_t delayMillis);
5654

57-
Signature sign(const Payload& payload, const View& view);
55+
Signature sign(const Payload& payload, const View& view) const;
5856
static bool verify(const ProcessId&, const Payload&, const View&, const Signature&);
5957

6058
void onPrepareMessageReceived(const PrepareMessage&);

extensions/fastfinality/src/dbrb/DbrbProcessContainer.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ namespace catapult { namespace dbrb {
3434
return m_shardingEnabled;
3535
}
3636

37-
const auto& currentView() const {
38-
if (m_shardingEnabled) {
39-
return m_pShardedDbrbProcess->currentView();
40-
} else {
41-
return m_pDbrbProcess->currentView();
42-
}
43-
}
44-
4537
const auto& strand() const {
4638
if (m_shardingEnabled) {
4739
return m_pShardedDbrbProcess->strand();

extensions/fastfinality/src/dbrb/QuorumManager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace catapult { namespace dbrb {
1111

1212
bool QuorumManager::update(const AcknowledgedMessage& message, ionet::PacketType payloadType) {
13-
CATAPULT_LOG(trace) << "[DBRB] QUORUM: Received ACKNOWLEDGED message in view " << message.View << ".";
1413
auto& set = AcknowledgedPayloads[message.View];
1514
const auto& payloadHash = message.PayloadHash;
1615
set.emplace(message.Sender, payloadHash);

extensions/fastfinality/src/dbrb/ShardedDbrbProcess.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,10 @@ namespace catapult { namespace dbrb {
6262
return m_strand;
6363
}
6464

65-
std::shared_ptr<MessageSender> ShardedDbrbProcess::messageSender() {
65+
std::shared_ptr<MessageSender> ShardedDbrbProcess::messageSender() const {
6666
return m_pMessageSender;
6767
}
6868

69-
const View& ShardedDbrbProcess::currentView() const {
70-
return m_currentView;
71-
}
72-
7369
const ProcessId& ShardedDbrbProcess::id() const {
7470
return m_id;
7571
}
@@ -95,12 +91,12 @@ namespace catapult { namespace dbrb {
9591
}
9692

9793
if (broadcastView > pThis->m_currentView) {
98-
CATAPULT_LOG(debug) << "[DBRB] BROADCAST: " << broadcastView << " is not a subview of the current view " << pThis->m_currentView << ", aborting broadcast";
94+
CATAPULT_LOG(debug) << "[DBRB] BROADCAST: broadcast view is not a subview of the current view, aborting broadcast";
9995
return;
10096
}
10197

10298
if (!broadcastView.isMember(pThis->m_id)) {
103-
CATAPULT_LOG(debug) << "[DBRB] BROADCAST: not a member of the current view " << pThis->m_currentView << ", aborting broadcast";
99+
CATAPULT_LOG(debug) << "[DBRB] BROADCAST: not a member of the current view, aborting broadcast";
104100
return;
105101
}
106102

@@ -136,7 +132,7 @@ namespace catapult { namespace dbrb {
136132
// Basic private methods:
137133

138134
void ShardedDbrbProcess::disseminate(const std::shared_ptr<Message>& pMessage, ViewData recipients) {
139-
CATAPULT_LOG(trace) << "[DBRB] disseminating message " << pMessage->Type << " to " << View{ recipients };
135+
CATAPULT_LOG(trace) << "[DBRB] disseminating message " << pMessage->Type << " to " << recipients.size() << " recipient(s)";
140136
auto pPacket = pMessage->toNetworkPacket();
141137
for (auto iter = recipients.begin(); iter != recipients.end(); ++iter) {
142138
if (m_id == *iter) {
@@ -158,7 +154,7 @@ namespace catapult { namespace dbrb {
158154
disseminate(pMessage, ViewData{ recipient });
159155
}
160156

161-
Signature ShardedDbrbProcess::sign(ionet::PacketType type, const Payload& payload, const DbrbTreeView& view) {
157+
Signature ShardedDbrbProcess::sign(ionet::PacketType type, const Payload& payload, const DbrbTreeView& view) const {
162158
// Forms a hash based on message type, payload and the broadcast view and signs it.
163159
uint32_t packetPayloadSize = 2 * sizeof(uint32_t) + view.size() * ProcessId_Size;
164160
auto pPacket = ionet::CreateSharedPacket<ionet::Packet>(packetPayloadSize);
@@ -511,10 +507,6 @@ namespace catapult { namespace dbrb {
511507
CATAPULT_LOG(debug) << "[DBRB] getting config at height " << height;
512508
const auto& config = pConfigHolder->Config(height).Network;
513509
auto bootstrapView = View{ config.DbrbBootstrapProcesses };
514-
if (bootstrapView.Data.empty()) {
515-
CATAPULT_LOG(debug) << "[DBRB] no bootstrap nodes, getting config at height " << height + Height(1);
516-
bootstrapView = View{ pConfigHolder->Config(height + Height(1)).Network.DbrbBootstrapProcesses };
517-
}
518510
auto isBootstrapProcess = bootstrapView.isMember(m_id);
519511

520512
view.merge(bootstrapView);
@@ -533,7 +525,7 @@ namespace catapult { namespace dbrb {
533525
pThis->m_pMessageSender->findNodes(view.Data);
534526
pThis->m_shardSize = shardSize;
535527
pThis->m_currentView = view;
536-
CATAPULT_LOG(debug) << "[DBRB] Current view (" << view.Data.size() << ") is now set to " << view;
528+
CATAPULT_LOG(debug) << "[DBRB] Current view size " << view.Data.size();
537529

538530
if (pThis->m_pTransactionSender) {
539531
bool isRegistrationRequired = false;

extensions/fastfinality/src/dbrb/ShardedDbrbProcess.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,15 @@ namespace catapult { namespace dbrb {
4141

4242
public:
4343
boost::asio::io_context::strand& strand();
44-
std::shared_ptr<MessageSender> messageSender();
45-
const View& currentView() const;
44+
std::shared_ptr<MessageSender> messageSender() const;
4645
const ProcessId& id() const;
4746
size_t shardSize() const;
4847

4948
protected:
5049
void disseminate(const std::shared_ptr<Message>& pMessage, ViewData recipients);
5150
void send(const std::shared_ptr<Message>& pMessage, const ProcessId& recipient);
5251

53-
Signature sign(ionet::PacketType type, const Payload& payload, const DbrbTreeView& view);
52+
Signature sign(ionet::PacketType type, const Payload& payload, const DbrbTreeView& view) const;
5453
static bool verify(ionet::PacketType type, const ProcessId&, const Payload&, const DbrbTreeView&, const Signature&);
5554

5655
void onPrepareMessageReceived(const ShardPrepareMessage&);

extensions/fastfinality/src/utils/FastFinalityUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace catapult { namespace fastfinality {
4949
boost::asio::post(pFsmShared->dbrbProcess().strand(), [pFsmWeak, pConfigHolder, lastBlockElementSupplier, pPromise]() {
5050
auto pFsmShared = pFsmWeak.lock();
5151
const auto& dbrbProcess = pFsmShared->dbrbProcess();
52-
if (!pFsmShared || pFsmShared->stopped() || dbrbProcess.currentView().Data.empty()) {
52+
if (!pFsmShared || pFsmShared->stopped()) {
5353
CATAPULT_LOG(warning) << "aborting node states retrieval";
5454
pPromise->set_value({});
5555
return;

0 commit comments

Comments
 (0)