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