@@ -69,7 +69,7 @@ SubscriptionSource::SubscriptionSource(
6969 std::chrono::steady_clock::duration const connectionTimeout,
7070 std::chrono::steady_clock::duration const retryDelay
7171)
72- : log_(fmt::format(" GrpcSource [{}:{}]" , ip, wsPort))
72+ : log_(fmt::format(" SubscriptionSource [{}:{}]" , ip, wsPort))
7373 , wsConnectionBuilder_(ip, wsPort)
7474 , validatedLedgers_(std::move(validatedLedgers))
7575 , subscriptions_(std::move(subscriptions))
133133SubscriptionSource::setForwarding (bool isForwarding)
134134{
135135 isForwarding_ = isForwarding;
136+ LOG (log_.info ()) << " Forwarding set to " << isForwarding_;
136137}
137138
138139std::chrono::steady_clock::time_point
@@ -168,6 +169,7 @@ SubscriptionSource::subscribe()
168169 wsConnection_ = std::move (connection).value ();
169170 isConnected_ = true ;
170171 onConnect_ ();
172+ LOG (log_.info ()) << " Connected" ;
171173
172174 auto const & subscribeCommand = getSubscribeCommandJson ();
173175 auto const writeErrorOpt = wsConnection_->write (subscribeCommand, yield);
@@ -224,10 +226,11 @@ SubscriptionSource::handleMessage(std::string const& message)
224226 auto validatedLedgers = boost::json::value_to<std::string>(result.at (JS (validated_ledgers)));
225227 setValidatedRange (std::move (validatedLedgers));
226228 }
227- LOG (log_.info ()) << " Received a message on ledger subscription stream. Message : " << object;
229+ LOG (log_.debug ()) << " Received a message on ledger subscription stream. Message: " << object;
228230
229231 } else if (object.contains (JS (type)) && object.at (JS (type)) == JS_LedgerClosed) {
230- LOG (log_.info ()) << " Received a message on ledger subscription stream. Message : " << object;
232+ LOG (log_.debug ()) << " Received a message of type 'ledgerClosed' on ledger subscription stream. Message: "
233+ << object;
231234 if (object.contains (JS (ledger_index))) {
232235 ledgerIndex = object.at (JS (ledger_index)).as_int64 ();
233236 }
@@ -245,11 +248,16 @@ SubscriptionSource::handleMessage(std::string const& message)
245248 // 2 - Validated transaction
246249 // Only forward proposed transaction, validated transactions are sent by Clio itself
247250 if (object.contains (JS (transaction)) and !object.contains (JS (meta))) {
251+ LOG (log_.debug ()) << " Forwarding proposed transaction: " << object;
248252 subscriptions_->forwardProposedTransaction (object);
249253 } else if (object.contains (JS (type)) && object.at (JS (type)) == JS_ValidationReceived) {
254+ LOG (log_.debug ()) << " Forwarding validation: " << object;
250255 subscriptions_->forwardValidation (object);
251256 } else if (object.contains (JS (type)) && object.at (JS (type)) == JS_ManifestReceived) {
257+ LOG (log_.debug ()) << " Forwarding manifest: " << object;
252258 subscriptions_->forwardManifest (object);
259+ } else {
260+ LOG (log_.error ()) << " Unknown message: " << object;
253261 }
254262 }
255263 }
@@ -261,7 +269,7 @@ SubscriptionSource::handleMessage(std::string const& message)
261269
262270 return std::nullopt ;
263271 } catch (std::exception const & e) {
264- LOG (log_.error ()) << " Exception in handleMessage : " << e.what ();
272+ LOG (log_.error ()) << " Exception in handleMessage: " << e.what ();
265273 return util::requests::RequestError{fmt::format (" Error handling message: {}" , e.what ())};
266274 }
267275}
@@ -273,13 +281,11 @@ SubscriptionSource::handleError(util::requests::RequestError const& error, boost
273281 isForwarding_ = false ;
274282 if (not stop_) {
275283 onDisconnect_ ();
284+ LOG (log_.info ()) << " Disconnected" ;
276285 }
277286
278287 if (wsConnection_ != nullptr ) {
279- auto const err = wsConnection_->close (yield);
280- if (err) {
281- LOG (log_.error ()) << " Error closing websocket connection: " << err->message ();
282- }
288+ wsConnection_->close (yield);
283289 wsConnection_.reset ();
284290 }
285291
0 commit comments