aboutsummaryrefslogtreecommitdiff
path: root/roomserver/storage/sqlite3/events_table.go
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-09-16 13:00:52 +0100
committerGitHub <noreply@github.com>2020-09-16 13:00:52 +0100
commit18231f25b437d2f03b3be1e0536fc46d45c8691f (patch)
tree5a3ef66c25268df8214be69f0c9e1f5f925da14f /roomserver/storage/sqlite3/events_table.go
parentba6c7c4a5c4166b7085343886ab69ef331238ff4 (diff)
Implement rejected events (#1426)
* WIP Event rejection * Still send back errors for rejected events Instead, discard them at the federationapi /send layer rather than re-implementing checks at the clientapi/PerformJoin layer. * Implement rejected events Critically, rejected events CAN cause state resolution to happen as it can merge forks in the DAG. This is fine, _provided_ we do not add the rejected event when performing state resolution, which is what this PR does. It also fixes the error handling when NotAllowed happens, as we were checking too early and needlessly handling NotAllowed in more than one place. * Update test to match reality * Modify InputRoomEvents to no longer return an error Errors do not serialise across HTTP boundaries in polylith mode, so instead set fields on the InputRoomEventsResponse. Add `Err()` function to make the API shape basically the same. * Remove redundant returns; linting * Update blacklist
Diffstat (limited to 'roomserver/storage/sqlite3/events_table.go')
-rw-r--r--roomserver/storage/sqlite3/events_table.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/roomserver/storage/sqlite3/events_table.go b/roomserver/storage/sqlite3/events_table.go
index a866c85d..773e9ade 100644
--- a/roomserver/storage/sqlite3/events_table.go
+++ b/roomserver/storage/sqlite3/events_table.go
@@ -41,13 +41,14 @@ const eventsSchema = `
depth INTEGER NOT NULL,
event_id TEXT NOT NULL UNIQUE,
reference_sha256 BLOB NOT NULL,
- auth_event_nids TEXT NOT NULL DEFAULT '[]'
+ auth_event_nids TEXT NOT NULL DEFAULT '[]',
+ is_rejected BOOLEAN NOT NULL DEFAULT FALSE
);
`
const insertEventSQL = `
- INSERT INTO roomserver_events (room_nid, event_type_nid, event_state_key_nid, event_id, reference_sha256, auth_event_nids, depth)
- VALUES ($1, $2, $3, $4, $5, $6, $7)
+ INSERT INTO roomserver_events (room_nid, event_type_nid, event_state_key_nid, event_id, reference_sha256, auth_event_nids, depth, is_rejected)
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
ON CONFLICT DO NOTHING;
`
@@ -63,7 +64,7 @@ const bulkSelectStateEventByIDSQL = "" +
" ORDER BY event_type_nid, event_state_key_nid ASC"
const bulkSelectStateAtEventByIDSQL = "" +
- "SELECT event_type_nid, event_state_key_nid, event_nid, state_snapshot_nid FROM roomserver_events" +
+ "SELECT event_type_nid, event_state_key_nid, event_nid, state_snapshot_nid, is_rejected FROM roomserver_events" +
" WHERE event_id IN ($1)"
const updateEventStateSQL = "" +
@@ -150,13 +151,14 @@ func (s *eventStatements) InsertEvent(
referenceSHA256 []byte,
authEventNIDs []types.EventNID,
depth int64,
+ isRejected bool,
) (types.EventNID, types.StateSnapshotNID, error) {
// attempt to insert: the last_row_id is the event NID
var eventNID int64
insertStmt := sqlutil.TxStmt(txn, s.insertEventStmt)
result, err := insertStmt.ExecContext(
ctx, int64(roomNID), int64(eventTypeNID), int64(eventStateKeyNID),
- eventID, referenceSHA256, eventNIDsAsArray(authEventNIDs), depth,
+ eventID, referenceSHA256, eventNIDsAsArray(authEventNIDs), depth, isRejected,
)
if err != nil {
return 0, 0, err
@@ -261,6 +263,7 @@ func (s *eventStatements) BulkSelectStateAtEventByID(
&result.EventStateKeyNID,
&result.EventNID,
&result.BeforeStateSnapshotNID,
+ &result.IsRejected,
); err != nil {
return nil, err
}