Commit graph

2506 commits

Author SHA1 Message Date
Tak Wai Wong 0f4febc65a Update script and config to start local dendrite with authorization checks (#934)
- Update the start-local-dendrite.sh to be able to start local dendrite
with / without authorization checks
- Update dendrite config to support command line arg
2022-11-16 09:05:04 -08:00
Pat Fives b9e047dfac Refactor to track roles associated with channels (#915)
update interfaces to set and remove space entitlements or channel roles

all forge tests passing

all integration tests passing
2022-11-14 20:41:25 -08:00
Tak Wai Wong 22230a238a Make module type property available in the contract + publish client types (#923)
Add the new property moduleType to EntitlementModuleInfo.

Re-generate the typescript types, Go types, and the abi
2022-11-14 10:27:34 -08:00
John Terzis 40830b8a37 Space,Channel soft deletion with dendrite gating, tests (#889)
Closes HNT-244.

The following PR implements Space,Channel soft deletion using on-chain
`disabled` flag scope to space, channel respectively. On message sync,
dendrite will now gate disabled rooms by performing a leave on the user
attempting to sync unless the user is the owner (more on this later). To
re-join, given rooms (spaces,channels) are created by default using
`invite` membership state, the owner will need to undo the on-chain
`disabled` flag, setting it false then re-invite users that left the
room as a side effect of it becoming disabled previously.

The owner does not leave the space, channel because if they did then
there would be no one left to invite users let alone themselves back in
if the action is ever undone.

What is not implemented in this PR:
1. **Transitive leaves on channels in a space** - If a space is
disabled, users will leave the space but not the channels within the
space. To allow for fully disabling a space and all its' channels, the
client can offer a view to the owner that iterates over the channels and
space to disable all on-chain. Furthermore, we could implement a batch
on-chain method that fully disables all channels within a space (plus
the space) in one on-chain call to save the owner gas.
2. **Data deletion** - No data is remove from the DAGs or on-chain.
Therefore deletion is soft and reversible.
3. **New hook to check if a room is disabled** - the client can leverage
existing on-chain public read only methods `getSpaceInfoBySpaceId`,
`getChannelInfoByChannelId` to read the state of each in order to remove
spaces, channels from a member's view that are disabled.
2022-11-09 17:07:51 -07:00
Tak Wai Wong df41f84bfa generate localhost and goerli types (#895) 2022-11-09 14:23:54 -08:00
Tak Wai Wong 29dabec35e fix copy path of the deploy script (#856) 2022-11-07 11:53:26 -08:00
Tak Wai Wong 147b17eccf write out the rolemanager address in the json (#837)
Need the address to implement the ZionRoleManagerShim

I ran this in  zion-governance/ and it worked :
forge script scripts/Local.s.sol:DeployLocal --rpc-url
http://localhost:8545/ --private-key … --broadcast

space-manager.json has the rolemanager address
2022-11-04 14:04:03 -07:00
Tak Wai Wong 78a4a213d4 Refresh dendrite with latest contract changes (#836)
sync latest dendrite main & space manager contract changes from our
fork.

Co-authored-by: Tak Wai Wong <tak@hntlabs.com>
2022-11-04 11:23:15 -07:00
Giuseppe Rodriguez 686450bdad HNT-320-321 Updates create channel to take role ids and makes contract types script simpler (#807)
Closes HNT-320

Co-authored-by: Tak Wai Wong <64229756+tak-hntlabs@users.noreply.github.com>
2022-11-03 21:35:44 -07:00
Tak Wai Wong a7ab7524da servers/dendrite Move calculation (#2856) commit 98d3f88bfb (#826) 2022-11-03 19:15:07 -07:00
Tak Wai Wong a9d3bdc058 subtree pull from dendrite fork for fix #2383 (#802)
Pull the fix for https://github.com/matrix-org/dendrite/issues/2838 into
the dendrite subtree. Includes latest dendrite main.

Signed-off-by: `Devon Hudson <devonhudson@librem.one>`
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Brian Meek <brian@hntlabs.com>
Signed-off-by: Austin Ellis <austin@hntlabs.com>
Signed-off-by: `Rubin Poster <rubinposter@gmail.com>`
Signed-off-by: `ash lea <example@thisismyactual.email>`
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
Co-authored-by: devonh <devon.dmytro@gmail.com>
Co-authored-by: Till <2353100+S7evinK@users.noreply.github.com>
Co-authored-by: Ashley Nelson <fant@shley.email>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Brian Meek <brian@hntlabs.com>
Co-authored-by: Tak Wai Wong <takwaiw@gmail.com>
Co-authored-by: Jean Lucas <jean@4ray.co>
Co-authored-by: Kabir Kwatra <kabir@kwatra.me>
Co-authored-by: sergekh2 <gitgitgit@khorun.com>
Co-authored-by: texuf <texuf.eth@gmail.com>
Co-authored-by: kegsay <kegan@matrix.org>
Co-authored-by: Brian Meek <brian@here.video>
Co-authored-by: John Terzis <john.c.terzis@gmail.com>
Co-authored-by: John Terzis <john@hntlabs.com>
Co-authored-by: Kerem <kerem.kazan@gmail.com>
Co-authored-by: Neboer <43609792+Neboer@users.noreply.github.com>
Co-authored-by: X. Ding <dingsm@gmail.com>
Co-authored-by: dxl <dxl@plotbridge.com>
Co-authored-by: ash lea <ashkitten@users.noreply.github.com>
Co-authored-by: 0x1a8510f2 <admin@0x1a8510f2.space>
Co-authored-by: Till Faelligen <tfaelligen@gmail.com>
Co-authored-by: Till Faelligen <davidf@element.io>
2022-11-02 16:28:06 -07:00
John Terzis b4223a1a18 Jterzis/sync dendrite (#793) 2022-11-01 23:17:48 -07:00
Tak Wai Wong 424df14000 Sync dendrite fork changes for gating, and single chain support (#778)
* Latest dendrite main (8c7b274e4e)
* Gating implementation from John and Tak

Fixes for https://github.com/matrix-org/dendrite/issues/2838 and
https://github.com/matrix-org/dendrite/issues/2842

Co-authored-by: Tak Wai Wong <tak@hntlabs.com>
2022-11-01 11:09:34 -07:00
Pat Fives 6cce0b9b43 Update create space interface, allow for setting specific users and multiple tokens during space creation (#734)
This PR finishes changing all the public interfaces at the moment for
space creation and updates the client.

All integration and forge tests passing.

Local and Goerli ABIs generated.

Co-authored-by: g <5714678+giuseppecrj@users.noreply.github.com>
2022-10-26 14:00:59 -04:00
Pat Fives 4c9f469a0c Update token entitlement logic to handle multiple tokens, decode entitlement data into structs (#729)
This change updates token entitlement data structures and allows for
multiple tokens to be set for a single role, permitting the AND
operation for multiple token requirements.

It also decodes structs when creating a space and setting a new token
entitlement.

Added new tests for multiple tokens gating a role. 

Also generates localhost AND Goerli ABIs.

Forge and integration tests all pass
2022-10-25 21:02:11 -07:00
Pat Fives 322e63e912 Fixes HNT-122 Mint space nft when creating a space and use to gate via token entitlement module (#702)
Update tests to gate ownership on NFT. Verified all tests pass.
2022-10-24 18:22:20 -07:00
John Terzis 01b94a9803 Jterzis/pull dendrite fork (#712)
Co-authored-by: Tak Wai Wong <64229756+tak-hntlabs@users.noreply.github.com>
Co-authored-by: Tak Wai Wong <tak@hntlabs.com>
Co-authored-by: John Terzis <john@hntlabs.com>
2022-10-21 17:38:05 -07:00
Tak Wai Wong e0a3d62205 Integration test for Read permission (#680)
Added integration tests for the Read permission:
Test1: verifies that the token user is granted to join the space.
Test2: verifies that the non-token user is denied. But the test fails
because of this bug:
https://linear.app/hnt-labs/issue/HNT-205/createspacewithtokenentitlement-should-not-add-the-everyone-role-by

Added test util functions to facilitate the implementation of the
permission tests.

The test suite is currently disabled with "describe.skip". The test file
has comments about how to turn on gating check to run the test. Will
make this better in future PR.
2022-10-20 13:45:50 -07:00
Tak Wai Wong ce57591c65 Regenerate types due to solidity contract changes (#676)
Fix build break and re-generate the types.

yarn test passed except for the 2 unreadcount tests. Tested with sample
app. Can create space now
2022-10-19 18:54:41 -07:00
Pat Fives 0a1463fd65 Generate new ABIs, fix name ref in ZionClient (#660) 2022-10-17 20:40:47 -07:00
John Terzis 478579eea1 Jterzis/update dendrite (#656)
Pulls in upstream latest changes from [dendrite-fork
](https://github.com/HereNotThere/dendrite)to subtree at
servers/dendrite here.

Co-authored-by: Tak Wai Wong <64229756+tak-hntlabs@users.noreply.github.com>
Co-authored-by: Tak Wai Wong <tak@hntlabs.com>
Co-authored-by: John Terzis <john@hntlabs.com>
2022-10-17 15:59:47 -07:00
Tak Wai Wong 9a6bb3dc78 Generate goerli contract types for typescript and golang (#627) 2022-10-13 15:53:52 -07:00
Giuseppe Rodriguez 093f9ef21d HNT-121 Add createChannel function to space manager (#611)
Closes HNT-137
Co-authored-by: John Terzis <john@hntlabs.com>
2022-10-13 14:34:52 -07:00
texuf 32d48002f7 Merge commit '1bf9dc0ca2c2eae4efd4b282a39d3bfe42e5e10e' into austin.ellis/dendrite
# Conflicts:
#	servers/dendrite/build/docker/Dockerfile.polylith
2022-09-28 15:12:34 -07:00
texuf 1bf9dc0ca2
Merge pull request #38 from HereNotThere/austin.ellis/merge1
Merge branch 'main' of github.com:matrix-org/dendrite
2022-09-28 14:55:13 -07:00
texuf 6be121163f
Merge pull request #36 from HereNotThere/austin.ellis/merge0
Merge branch 'main' of github.com:matrix-org/dendrite
2022-09-28 14:54:31 -07:00
texuf 66773a1744 Merge branch 'main' of github.com:matrix-org/dendrite into austin.ellis/merge1 2022-09-28 09:05:00 -07:00
Neil Alexander 3f9e38e80a
Consistent *sql.Tx usage across sync API (#2744)
This tidies up the `storage` package so that everything takes a
transaction parameter instead of something things that do and some that
don't.
2022-09-28 10:18:03 +01:00
texuf a574ed5369
Fix for `sql: converting argument $1 type: unsupported type []interfa… (#2743)
…ce {}, a slice of interface` in new notifications select

The sqlite3 version was just not working, original pr here:
https://github.com/matrix-org/dendrite/pull/2688

signed off by: austin ellis <austin@hntlabs.com>

This doesn't fix the notification counts, they still only work about 1
out of every 5 times in my tests. I will stick with my other fix locally
for reliable notification delivery:
https://github.com/matrix-org/dendrite/pull/2701
2022-09-28 06:19:34 +02:00
texuf 48fce3be10 Merge branch 'main' of github.com:matrix-org/dendrite into austin.ellis/merge
# Conflicts:
#	syncapi/streams/stream_notificationdata.go
#	userapi/consumers/syncapi_readupdate.go
2022-09-27 14:55:38 -07:00
Neil Alexander 083ae01520
Promote reindexing log level 2022-09-27 17:30:40 +01:00
Neil Alexander 34993717fd
Update search docs 2022-09-27 17:10:47 +01:00
Till 87be32ca26
Fulltext implementation using Bleve (#2675)
Based on #2480

This actually indexes events based on their event type. They are removed
from the index if we receive a `m.room.redaction` event on the
`OutputRoomEvent` stream.
An admin endpoint is added to reindex all existing events.


Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2022-09-27 18:06:49 +02:00
Neil Alexander 6c67552bf9
Return M_UNRECOGNIZED for unknown CS API endpoints/actions (#2740)
Fixes #2739.
2022-09-27 15:50:22 +01:00
Till 249b32c4f3
Refactor notifications (#2688)
This PR changes the handling of notifications
- removes the `StreamEvent` and `ReadUpdate` stream
- listens on the `OutputRoomEvent` stream in the UserAPI to inform the
SyncAPI about unread notifications
- listens on the `OutputReceiptEvent` stream in the UserAPI to set
receipts/update notifications
- sets the `read_markers` directly from within the internal UserAPI

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2022-09-27 15:01:34 +02:00
Neil Alexander f18bce93cc
Pinecone hybrid routing (update to matrix-org/pinecone#67) 2022-09-27 11:15:49 +01:00
Neil Alexander d531202b0e
Build Docker images using Go 1.19 (related to #2714) 2022-09-27 10:52:03 +01:00
Dov Alperin b5bfff47d2
Use /usr/bin/env bash in shebangs to make them universal (#2735)
Some systems (like nixos) don't have bash living at `/bin/bash` so using
`/usr/bin/env bash` we can make these scripts universal.

### Pull Request Checklist

<!-- Please read docs/CONTRIBUTING.md before submitting your pull
request -->

* [X] I have added added tests for PR _or_ I have justified why this PR
doesn't need tests.
* [x] Pull request includes a [sign
off](https://github.com/matrix-org/dendrite/blob/main/docs/CONTRIBUTING.md#sign-off)

Signed-off-by: `Dov Alperin <git@dov.dev>`

Signed-off-by: `Dov Alperin <git@dov.dev>`
2022-09-27 09:42:08 +01:00
PiotrKozimor 12649ccedd
Improve selectRoomIDsWithAnyMembershipSQL performance (#2738)
Recently I have observed that dendrite spends a lot of time (~390s) in
`selectRoomIDsWithAnyMembershipSQL` query

```
dendrite_syncapi=# select total_exec_time, left(query,100) from pg_stat_statements order by total_exec_time desc limit 5 ;
  total_exec_time   |                                                 left
--------------------+------------------------------------------------------------------------------------------------------
  747826.5800519128 | SELECT event_id, id, headered_event_json, session_id, exclude_from_sync, transaction_id, history_vis
  389130.5490339942 | SELECT DISTINCT room_id, membership FROM syncapi_current_room_state WHERE type = $2 AND state_key =
 376104.17514700035 | SELECT psd.datname, xact_commit, xact_rollback, blks_read, blks_hit, tup_returned, tup_fetched, tup_
   363644.164092031 | SELECT event_type_nid, event_state_key_nid, event_nid FROM roomserver_events WHERE event_nid = ANY($
  58570.48104699995 | SELECT event_id, headered_event_json FROM syncapi_current_room_state WHERE room_id = $1 AND ( $2::te
(5 rows)
```

Explain analyze showed correct usage of `syncapi_room_state_unique`
index:

```
dendrite_syncapi=#
explain analyze SELECT distinct room_id, membership FROM syncapi_current_room_state WHERE type = 'm.room.member' AND state_key = '@qjfl:dendrite.stg.globekeeper.com';
                                                                               QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Unique  (cost=2749.38..2749.56 rows=24 width=52) (actual time=2.933..2.956 rows=65 loops=1)
   ->  Sort  (cost=2749.38..2749.44 rows=24 width=52) (actual time=2.932..2.937 rows=65 loops=1)
         Sort Key: room_id, membership
         Sort Method: quicksort  Memory: 34kB
         ->  Index Scan using syncapi_room_state_unique on syncapi_current_room_state  (cost=0.41..2748.83 rows=24 width=52) (actual time=0.030..2.890 rows=65 loops=1)
               Index Cond: ((type = 'm.room.member'::text) AND (state_key = '@qjfl:dendrite.stg.globekeeper.com'::text))
 Planning Time: 0.140 ms
 Execution Time: 2.990 ms
(8 rows)
```

Multi-column indexes in Postgres shall perform well for leftmost
columns, but I gave it a try and created
`syncapi_current_room_state_type_state_key_idx` index. I could observe
significant performance improvement. Execution time dropped from 2.9 ms
to 0.24 ms:

```
explain analyze SELECT distinct room_id, membership FROM syncapi_current_room_state WHERE type = 'm.room.member' AND state_key = '@qjfl:dendrite.stg.globekeeper.com';
                                                                             QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Unique  (cost=96.46..96.64 rows=24 width=52) (actual time=0.199..0.218 rows=65 loops=1)
   ->  Sort  (cost=96.46..96.52 rows=24 width=52) (actual time=0.199..0.202 rows=65 loops=1)
         Sort Key: room_id, membership
         Sort Method: quicksort  Memory: 34kB
         ->  Bitmap Heap Scan on syncapi_current_room_state  (cost=4.53..95.91 rows=24 width=52) (actual time=0.048..0.139 rows=65 loops=1)
               Recheck Cond: ((type = 'm.room.member'::text) AND (state_key = '@qjfl:dendrite.stg.globekeeper.com'::text))
               Heap Blocks: exact=59
               ->  Bitmap Index Scan on syncapi_current_room_state_type_state_key_idx  (cost=0.00..4.53 rows=24 width=0) (actual time=0.037..0.037 rows=65 loops=1)
                     Index Cond: ((type = 'm.room.member'::text) AND (state_key = '@qjfl:dendrite.stg.globekeeper.com'::text))
 Planning Time: 0.236 ms
 Execution Time: 0.242 ms
(11 rows)
```

Next improvement is skipping DISTINCT and rely on map assignment in
`SelectRoomIDsWithAnyMembership`. Execution time drops by almost half:

```
explain analyze SELECT room_id, membership FROM syncapi_current_room_state WHERE type = 'm.room.member' AND state_key = '@qjfl:dendrite.stg.globekeeper.com';
                                                                       QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on syncapi_current_room_state  (cost=4.53..95.91 rows=24 width=52) (actual time=0.032..0.113 rows=65 loops=1)
   Recheck Cond: ((type = 'm.room.member'::text) AND (state_key = '@qjfl:dendrite.stg.globekeeper.com'::text))
   Heap Blocks: exact=59
   ->  Bitmap Index Scan on syncapi_current_room_state_type_state_key_idx  (cost=0.00..4.53 rows=24 width=0) (actual time=0.021..0.021 rows=65 loops=1)
         Index Cond: ((type = 'm.room.member'::text) AND (state_key = '@qjfl:dendrite.stg.globekeeper.com'::text))
 Planning Time: 0.087 ms
 Execution Time: 0.136 ms
(7 rows)
```

In our env we spend only 1s on inserting to table, so the write penalty
of creating an index should be small.
```
dendrite_syncapi=# select total_exec_time, left(query,100) from pg_stat_statements where query like '%INSERT%syncapi_current_room_state%' order by total_exec_time desc;
  total_exec_time   |                                                 left
--------------------+------------------------------------------------------------------------------------------------------
 1139.9057619999971 | INSERT INTO syncapi_current_room_state (room_id, event_id, type, sender, contains_url, state_key, he
(1 row)
``` 

This PR does not require test modifications.

### Pull Request Checklist

<!-- Please read docs/CONTRIBUTING.md before submitting your pull
request -->

* [x] I have added added tests for PR _or_ I have justified why this PR
doesn't need tests.
* [x] Pull request includes a [sign
off](https://github.com/matrix-org/dendrite/blob/main/docs/CONTRIBUTING.md#sign-off)

Signed-off-by: `Piotr Kozimor <p1996k@gmail.com>`
2022-09-27 09:41:36 +01:00
networkException 40fec70d13
Add pinecone demo container image (#2710)
This pull request adds the configuration and CI steps to build and
publish a container wrapping the `dendrite-demo-pinecone` command as
well as fixes a sentence structure issue in the pull request template.

As this does not touch any go source code no tests have been added

### Pull Request Checklist

<!-- Please read docs/CONTRIBUTING.md before submitting your pull
request -->

* [x] I have added tests for PR _or_ I have justified why this PR
doesn't need tests.
* [x] Pull request includes a [sign
off](https://github.com/matrix-org/dendrite/blob/main/docs/CONTRIBUTING.md#sign-off)

Signed-off-by: networkException <git@nwex.de> (by private sign-off)
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
2022-09-27 09:39:39 +01:00
Tak Wai Wong 65ee181de4
Authorization - config, interface, and default implementation (#33)
* add config yaml for enable_auth

* zion_space_manager_localhost.go

* Placeholders for authorization

* rename func and type

* re-run go mod tidy

Co-authored-by: Tak Wai Wong <tak@hntlabs.com>
2022-09-26 16:46:52 -07:00
Tak Wai Wong acf0742b40
Merge branch 'matrix-org:main' into main 2022-09-26 13:30:39 -07:00
Neil Alexander f022fc1397
Remove origin field from PDUs (#2737)
This nukes the `origin` field from PDUs as per
matrix-org/matrix-spec#998, matrix-org/gomatrixserverlib#341.
2022-09-26 17:35:35 +01:00
Neil Alexander 3e87096a21
Use TxStmt in SQLite pusher table 2022-09-26 09:54:54 +01:00
Till Faelligen 3c416517b0
Fix possible "Database is locked" issue 2022-09-26 10:45:35 +02:00
Neil Alexander 8d64c24b23
Update documentation to state that Dendrite requires PostgreSQL UTF-8 encoding 2022-09-26 09:33:34 +01:00
Brian Meek 08d7e67c31 Update docker images for Dendrite to use buster
Signed-off-by: Brian Meek <brian@hntlabs.com>
2022-09-25 19:08:28 -05:00
Brian Meek 745dfe1404 Merge dendrite-fork
Signed-off-by: Brian Meek <brian@hntlabs.com>
2022-09-24 14:07:49 -05:00
Brian Meek 1ac21a8e55
Update dependencies
Signed-off-by: Brian Meek <brian@hntlabs.com>
2022-09-24 14:05:08 -05:00
Brian Meek 0850f690d9 Merge branch 'main' of https://github.com/matrix-org/dendrite 2022-09-24 14:01:04 -05:00