@@ -878,119 +878,94 @@ Peer::recvAuthenticatedMessage(AuthenticatedMessage&& msg)
878
878
{
879
879
ZoneScoped;
880
880
releaseAssert (!threadIsMain () || !useBackgroundThread ());
881
+ RECURSIVE_LOCK_GUARD (mStateMutex , guard);
881
882
882
- // TODO: Remove if I get rid of the special lock scoping vv
883
- std::shared_ptr<CapacityTrackedMessage> msgTracker = nullptr ;
884
-
885
- // TODO: Move back if I git rid of lock scoping vv
886
- Scheduler::ActionType type = Scheduler::ActionType::NORMAL_ACTION;
887
- std::string queueName;
883
+ if (shouldAbort (guard))
888
884
{
889
- RECURSIVE_LOCK_GUARD (mStateMutex , guard);
890
-
891
- if (shouldAbort (guard))
892
- {
893
- return false ;
894
- }
885
+ return false ;
886
+ }
895
887
896
- std::string errorMsg;
897
- if (getState (guard) >= GOT_HELLO &&
898
- msg.v0 ().message .type () != ERROR_MSG)
888
+ std::string errorMsg;
889
+ if (getState (guard) >= GOT_HELLO && msg.v0 ().message .type () != ERROR_MSG)
890
+ {
891
+ if (!mHmac .checkAuthenticatedMessage (msg, errorMsg))
899
892
{
900
- if (!mHmac . checkAuthenticatedMessage (msg, errorMsg ))
893
+ if (!threadIsMain ( ))
901
894
{
902
- if (!threadIsMain ())
903
- {
904
- mAppConnector .postOnMainThread (
905
- [self = shared_from_this (), errorMsg]() {
906
- self->sendErrorAndDrop (ERR_AUTH, errorMsg);
907
- },
908
- " Peer::sendErrorAndDrop" );
909
- }
910
- else
911
- {
912
- sendErrorAndDrop (ERR_AUTH, errorMsg);
913
- }
914
- return false ;
895
+ mAppConnector .postOnMainThread (
896
+ [self = shared_from_this (), errorMsg]() {
897
+ self->sendErrorAndDrop (ERR_AUTH, errorMsg);
898
+ },
899
+ " Peer::sendErrorAndDrop" );
900
+ }
901
+ else
902
+ {
903
+ sendErrorAndDrop (ERR_AUTH, errorMsg);
915
904
}
905
+ return false ;
916
906
}
907
+ }
917
908
918
- // NOTE: Additionally, we may use state snapshots to verify TRANSACTION
919
- // type messages in the background.
920
-
921
- // Start tracking capacity here, so read throttling is applied
922
- // appropriately. Flow control might not be started at that time
923
- msgTracker = std::make_shared<CapacityTrackedMessage>(
924
- shared_from_this (), msg.v0 ().message );
925
-
926
- std::string cat;
927
-
928
- switch (msgTracker->getMessage ().type ())
929
- {
930
- case HELLO:
931
- case AUTH:
932
- cat = AUTH_ACTION_QUEUE;
933
- break ;
934
- // control messages
935
- case PEERS:
936
- case ERROR_MSG:
937
- case SEND_MORE:
938
- case SEND_MORE_EXTENDED:
939
- cat = " CTRL" ;
940
- break ;
941
- // high volume flooding
942
- case TRANSACTION:
943
- case FLOOD_ADVERT:
944
- case FLOOD_DEMAND:
945
- {
946
- cat = " TX" ;
947
- type = Scheduler::ActionType::DROPPABLE_ACTION;
948
- break ;
949
- }
909
+ // NOTE: Additionally, we may use state snapshots to verify TRANSACTION type
910
+ // messages in the background.
950
911
951
- // consensus, inbound
952
- case GET_TX_SET:
953
- case GET_SCP_QUORUMSET:
954
- case GET_SCP_STATE:
955
- cat = " SCPQ" ;
956
- type = Scheduler::ActionType::DROPPABLE_ACTION;
957
- break ;
912
+ // Start tracking capacity here, so read throttling is applied
913
+ // appropriately. Flow control might not be started at that time
914
+ auto msgTracker = std::make_shared<CapacityTrackedMessage>(
915
+ shared_from_this (), msg.v0 ().message );
958
916
959
- // consensus, self
960
- case DONT_HAVE:
961
- case TX_SET:
962
- case GENERALIZED_TX_SET:
963
- case SCP_QUORUMSET:
964
- case SCP_MESSAGE:
965
- cat = " SCP" ;
966
- break ;
917
+ std::string cat;
918
+ Scheduler::ActionType type = Scheduler::ActionType::NORMAL_ACTION;
967
919
968
- default :
969
- cat = " MISC" ;
970
- }
920
+ switch (msgTracker->getMessage ().type ())
921
+ {
922
+ case HELLO:
923
+ case AUTH:
924
+ cat = AUTH_ACTION_QUEUE;
925
+ break ;
926
+ // control messages
927
+ case PEERS:
928
+ case ERROR_MSG:
929
+ case SEND_MORE:
930
+ case SEND_MORE_EXTENDED:
931
+ cat = " CTRL" ;
932
+ break ;
933
+ // high volume flooding
934
+ case TRANSACTION:
935
+ case FLOOD_ADVERT:
936
+ case FLOOD_DEMAND:
937
+ {
938
+ cat = " TX" ;
939
+ type = Scheduler::ActionType::DROPPABLE_ACTION;
940
+ break ;
941
+ }
971
942
972
- // processing of incoming messages during authenticated must be
973
- // in-order, so while not authenticated, place all messages onto
974
- // AUTH_ACTION_QUEUE scheduler queue
975
- queueName = isAuthenticated (guard) ? cat : AUTH_ACTION_QUEUE;
976
- type = isAuthenticated (guard) ? type
977
- : Scheduler::ActionType::NORMAL_ACTION;
943
+ // consensus, inbound
944
+ case GET_TX_SET:
945
+ case GET_SCP_QUORUMSET:
946
+ case GET_SCP_STATE:
947
+ cat = " SCPQ" ;
948
+ type = Scheduler::ActionType::DROPPABLE_ACTION;
949
+ break ;
978
950
979
- // TODO: This scope (ending here) exists to ensure this doesn't hold the
980
- // state lock upon entry to the transaction queue. This can cause
981
- // deadlocks! I think it's safe to release the lock here as there's no
982
- // longer any state querying. In practice though, if I end up posting
983
- // the tryAdd action onto some tx-queue specific thread, then I can
984
- // remove the scoping I added here and the lock will be released upon
985
- // return from this function (like it always has).
951
+ // consensus, self
952
+ case DONT_HAVE:
953
+ case TX_SET:
954
+ case GENERALIZED_TX_SET:
955
+ case SCP_QUORUMSET:
956
+ case SCP_MESSAGE:
957
+ cat = " SCP" ;
958
+ break ;
986
959
987
- // TODO: Really investigate whether this peer+transaction queue locking
988
- // each other issue can come up anywhere else.
960
+ default :
961
+ cat = " MISC " ;
989
962
}
990
963
991
- // TODO: vv Remove asserts if I get rid of the scoping above
992
- releaseAssert (msgTracker);
993
- releaseAssert (!queueName.empty ());
964
+ // processing of incoming messages during authenticated must be in-order, so
965
+ // while not authenticated, place all messages onto AUTH_ACTION_QUEUE
966
+ // scheduler queue
967
+ auto queueName = isAuthenticated (guard) ? cat : AUTH_ACTION_QUEUE;
968
+ type = isAuthenticated (guard) ? type : Scheduler::ActionType::NORMAL_ACTION;
994
969
995
970
// If a message is already scheduled, drop
996
971
if (mAppConnector .checkScheduledAndCache (msgTracker))
@@ -1027,9 +1002,6 @@ Peer::recvAuthenticatedMessage(AuthenticatedMessage&& msg)
1027
1002
self->recvMessage (t);
1028
1003
},
1029
1004
" Peer::recvMessage" ); // TODO: Change message to something better
1030
- // TODO: If I end up running this on a different thread then I need to
1031
- // be sure to std::move `msgTracker` into the lambda as-per the note
1032
- // below.
1033
1005
}
1034
1006
else
1035
1007
{
0 commit comments