mirror of
https://github.com/matrix-org/dendrite
synced 2024-12-05 03:42:34 +01:00
Check event is not rejected (#3243)
Companion PR to https://github.com/matrix-org/gomatrixserverlib/pull/421
This commit is contained in:
parent
1b124fe9cb
commit
4fa8512d57
7 changed files with 49 additions and 3 deletions
|
@ -202,12 +202,25 @@ func main() {
|
|||
authEvents[i] = authEventEntries[i].PDU
|
||||
}
|
||||
|
||||
// Get the roomNID
|
||||
roomInfo, err = roomserverDB.RoomInfo(ctx, authEvents[0].RoomID().String())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Resolving state")
|
||||
var resolved Events
|
||||
resolved, err = gomatrixserverlib.ResolveConflicts(
|
||||
gomatrixserverlib.RoomVersion(*roomVersion), events, authEvents, func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
|
||||
return rsAPI.QueryUserIDForSender(ctx, roomID, senderID)
|
||||
},
|
||||
func(eventID string) bool {
|
||||
isRejected, rejectedErr := roomserverDB.IsEventRejected(ctx, roomInfo.RoomNID, eventID)
|
||||
if rejectedErr != nil {
|
||||
return true
|
||||
}
|
||||
return isRejected
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
2
go.mod
2
go.mod
|
@ -22,7 +22,7 @@ require (
|
|||
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
|
||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
|
||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20231023121512-16e7431168be
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20231024124730-58af9a2712ca
|
||||
github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7
|
||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
|
||||
github.com/mattn/go-sqlite3 v1.14.17
|
||||
|
|
4
go.sum
4
go.sum
|
@ -208,8 +208,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw
|
|||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20231023121512-16e7431168be h1:bZP16ydP8uRoRBo1p/7WHMexjg7JJGj81fKzZ1FULb4=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20231023121512-16e7431168be/go.mod h1:M8m7seOroO5ePlgxA7AFZymnG90Cnh94rYQyngSrZkk=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20231024124730-58af9a2712ca h1:JCP72vU4Vcmur2071RwYVOSoekR+ZjbC03wZD5lAAK0=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20231024124730-58af9a2712ca/go.mod h1:M8m7seOroO5ePlgxA7AFZymnG90Cnh94rYQyngSrZkk=
|
||||
github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7 h1:6t8kJr8i1/1I5nNttw6nn1ryQJgzVlBmSGgPiiaTdw4=
|
||||
github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7/go.mod h1:ReWMS/LoVnOiRAdq9sNUC2NZnd1mZkMNB52QhpTRWjg=
|
||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
|
||||
|
|
|
@ -498,6 +498,13 @@ func (t *missingStateReq) resolveStatesAndCheck(ctx context.Context, roomVersion
|
|||
roomVersion, gomatrixserverlib.ToPDUs(stateEventList), gomatrixserverlib.ToPDUs(authEventList), func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
|
||||
return t.inputer.Queryer.QueryUserIDForSender(ctx, roomID, senderID)
|
||||
},
|
||||
func(eventID string) bool {
|
||||
isRejected, err := t.db.IsEventRejected(ctx, t.roomInfo.RoomNID, eventID)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
return isRejected
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -165,6 +165,13 @@ func (r *Queryer) QueryStateAfterEvents(
|
|||
info.RoomVersion, gomatrixserverlib.ToPDUs(stateEvents), gomatrixserverlib.ToPDUs(authEvents), func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
|
||||
return r.QueryUserIDForSender(ctx, roomID, senderID)
|
||||
},
|
||||
func(eventID string) bool {
|
||||
isRejected, rejectedErr := r.DB.IsEventRejected(ctx, info.RoomNID, eventID)
|
||||
if rejectedErr != nil {
|
||||
return true
|
||||
}
|
||||
return isRejected
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("state.ResolveConflictsAdhoc: %w", err)
|
||||
|
@ -676,6 +683,13 @@ func (r *Queryer) QueryStateAndAuthChain(
|
|||
info.RoomVersion, gomatrixserverlib.ToPDUs(stateEvents), gomatrixserverlib.ToPDUs(authEvents), func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
|
||||
return r.QueryUserIDForSender(ctx, roomID, senderID)
|
||||
},
|
||||
func(eventID string) bool {
|
||||
isRejected, rejectedErr := r.DB.IsEventRejected(ctx, info.RoomNID, eventID)
|
||||
if rejectedErr != nil {
|
||||
return true
|
||||
}
|
||||
return isRejected
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -45,6 +45,7 @@ type StateResolutionStorage interface {
|
|||
AddState(ctx context.Context, roomNID types.RoomNID, stateBlockNIDs []types.StateBlockNID, state []types.StateEntry) (types.StateSnapshotNID, error)
|
||||
Events(ctx context.Context, roomVersion gomatrixserverlib.RoomVersion, eventNIDs []types.EventNID) ([]types.Event, error)
|
||||
EventsFromIDs(ctx context.Context, roomInfo *types.RoomInfo, eventIDs []string) ([]types.Event, error)
|
||||
IsEventRejected(ctx context.Context, roomNID types.RoomNID, eventID string) (bool, error)
|
||||
}
|
||||
|
||||
type StateResolution struct {
|
||||
|
@ -1066,6 +1067,13 @@ func (v *StateResolution) resolveConflictsV2(
|
|||
func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
|
||||
return v.Querier.QueryUserIDForSender(ctx, roomID, senderID)
|
||||
},
|
||||
func(eventID string) bool {
|
||||
isRejected, err := v.db.IsEventRejected(ctx, v.roomInfo.RoomNID, eventID)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
return isRejected
|
||||
},
|
||||
)
|
||||
}()
|
||||
|
||||
|
|
|
@ -250,3 +250,7 @@ func (u *RoomUpdater) MarkEventAsSent(eventNID types.EventNID) error {
|
|||
func (u *RoomUpdater) MembershipUpdater(targetUserNID types.EventStateKeyNID, targetLocal bool) (*MembershipUpdater, error) {
|
||||
return u.d.membershipUpdaterTxn(u.ctx, u.txn, u.roomInfo.RoomNID, targetUserNID, targetLocal)
|
||||
}
|
||||
|
||||
func (u *RoomUpdater) IsEventRejected(ctx context.Context, roomNID types.RoomNID, eventID string) (bool, error) {
|
||||
return u.d.IsEventRejected(ctx, roomNID, eventID)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue