@@ -1092,70 +1092,55 @@ impl InnerRelay {
1092
1092
}
1093
1093
}
1094
1094
1095
- // Check if event status
1096
- let status: DatabaseEventStatus = self . state . database ( ) . check_id ( & event. id ) . await ?;
1097
-
1098
- // Event deleted
1099
- if let DatabaseEventStatus :: Deleted = status {
1100
- return Ok ( None ) ;
1101
- }
1102
-
1103
- // Check if coordinate has been deleted
1104
- // TODO: remove this since it's checked also later?
1105
- if let Some ( coordinate) = event. coordinate ( ) {
1106
- if self
1107
- . state
1108
- . database ( )
1109
- . has_coordinate_been_deleted ( & coordinate, & event. created_at )
1110
- . await ?
1111
- {
1112
- return Ok ( None ) ;
1113
- }
1114
- }
1095
+ // Check the event status
1096
+ match self . state . database ( ) . check_id ( & event. id ) . await ? {
1097
+ // Already saved, continue with code execution
1098
+ DatabaseEventStatus :: Saved => { }
1099
+ // Deleted, immediately return
1100
+ DatabaseEventStatus :: Deleted => return Ok ( None ) ,
1101
+ // Not existent, verify the event and try to save it to the database
1102
+ DatabaseEventStatus :: NotExistent => {
1103
+ // Check if the event was already verified.
1104
+ //
1105
+ // This is useful if someone continues to send the same invalid event:
1106
+ // since invalid events aren't stored in the database,
1107
+ // skipping this check would result in the re-verification of the event.
1108
+ // This may also be useful to avoid double verification if the event is received at the exact same time by many different Relay instances.
1109
+ //
1110
+ // This is important since event signature verification is a heavy job!
1111
+ if !self . state . verified ( & event. id ) ? {
1112
+ event. verify ( ) ?;
1113
+ }
1115
1114
1116
- // TODO: check if filter match
1117
-
1118
- // Check if the event exists
1119
- if let DatabaseEventStatus :: NotExistent = status {
1120
- // Check if the event was already verified.
1121
- //
1122
- // This is useful if someone continues to send the same invalid event:
1123
- // since invalid events aren't stored in the database,
1124
- // skipping this check would result in the re-verification of the event.
1125
- // This may also be useful to avoid double verification if the event is received at the exact same time by many different Relay instances.
1126
- //
1127
- // This is important since event signature verification is a heavy job!
1128
- if !self . state . verified ( & event. id ) ? {
1129
- event. verify ( ) ?;
1130
- }
1115
+ // Save into the database
1116
+ let send_notification: bool = match self . state . database ( ) . save_event ( & event) . await ?
1117
+ {
1118
+ SaveEventStatus :: Success => true ,
1119
+ SaveEventStatus :: Rejected ( reason) => match reason {
1120
+ RejectedReason :: Ephemeral => true ,
1121
+ RejectedReason :: Duplicate => true ,
1122
+ RejectedReason :: Deleted => false ,
1123
+ RejectedReason :: Expired => false ,
1124
+ RejectedReason :: Replaced => false ,
1125
+ RejectedReason :: InvalidDelete => false ,
1126
+ RejectedReason :: Other => true ,
1127
+ } ,
1128
+ } ;
1131
1129
1132
- // Save into the database
1133
- let send_notification: bool = match self . state . database ( ) . save_event ( & event) . await ? {
1134
- SaveEventStatus :: Success => true ,
1135
- SaveEventStatus :: Rejected ( reason) => match reason {
1136
- RejectedReason :: Ephemeral => true ,
1137
- RejectedReason :: Duplicate => true ,
1138
- RejectedReason :: Deleted => false ,
1139
- RejectedReason :: Expired => false ,
1140
- RejectedReason :: Replaced => false ,
1141
- RejectedReason :: InvalidDelete => false ,
1142
- RejectedReason :: Other => true ,
1143
- } ,
1144
- } ;
1130
+ // If the notification should NOT be sent, immediately return.
1131
+ if !send_notification {
1132
+ return Ok ( None ) ;
1133
+ }
1145
1134
1146
- // If the notification should NOT be sent, immediately return.
1147
- if !send_notification {
1148
- return Ok ( None ) ;
1135
+ // Send notification
1136
+ self . send_notification (
1137
+ RelayNotification :: Event {
1138
+ subscription_id : subscription_id. clone ( ) ,
1139
+ event : Box :: new ( event. clone ( ) ) ,
1140
+ } ,
1141
+ true ,
1142
+ ) ;
1149
1143
}
1150
-
1151
- // Send notification
1152
- self . send_notification (
1153
- RelayNotification :: Event {
1154
- subscription_id : subscription_id. clone ( ) ,
1155
- event : Box :: new ( event. clone ( ) ) ,
1156
- } ,
1157
- true ,
1158
- ) ;
1159
1144
}
1160
1145
1161
1146
Ok ( Some ( RelayMessage :: Event {
0 commit comments