Skip to content

Commit

Permalink
Fix adding state events to the database (#3133)
Browse files Browse the repository at this point in the history
When we're adding state to the database, we check which eventNIDs are
already in a block, if we already have that eventNID, we remove it from
the list. In its current form we would skip over eventNIDs in the case
we already found a match (we're decrementing `i` twice)
My theory is, that when we later get the state blocks, we are receiving
"too many" eventNIDs (well, yea, we stored too many), which may or may
not can result in state resets when comparing different state snapshots.
(e.g. when adding state we stored a eventNID by accident because we
skipped it, later we add more state and are not adding it because we
don't skip it)
  • Loading branch information
S7evinK committed Jul 4, 2023
1 parent 2ee03fd commit 4c3a526
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions roomserver/storage/shared/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,17 @@ func (d *Database) addState(
var found bool
for i := len(state) - 1; i >= 0; i-- {
found = false
blocksLoop:
for _, events := range blocks {
for _, event := range events {
if state[i].EventNID == event {
found = true
break
break blocksLoop
}
}
}
if found {
state = append(state[:i], state[i+1:]...)
i--
}
}
}
Expand Down

0 comments on commit 4c3a526

Please sign in to comment.