diff --git a/PROGRESS.md b/PROGRESS.md index bc22c3e..4ba3292 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -60,7 +60,7 @@ Implementation checklist for Parrhesia relay. - [x] NIP-17/59 recipient-protected giftwrap read path (`kind:1059`) - [x] NIP-29 group event policy + relay metadata events - [x] NIP-43 membership request flow (`28934/28935/28936`, `8000/8001`, `13534`) -- [x] NIP-EE (feature-flagged): `443`, `445`, `10051` handling +- [x] Marmot MIP relay surface: `443`, `445`, `10051` handling - [x] MLS retention policy + tests for commit race edge cases ## Phase 8 — management API + operations diff --git a/config/config.exs b/config/config.exs index 33f4af4..a953ef3 100644 --- a/config/config.exs +++ b/config/config.exs @@ -39,7 +39,6 @@ config :parrhesia, nip_45_count: true, nip_50_search: true, nip_77_negentropy: true, - nip_ee_mls: false, marmot_push_notifications: false ], storage: [ diff --git a/lib/parrhesia/policy/event_policy.ex b/lib/parrhesia/policy/event_policy.ex index 8ab7285..3ca46b2 100644 --- a/lib/parrhesia/policy/event_policy.ex +++ b/lib/parrhesia/policy/event_policy.ex @@ -30,7 +30,6 @@ defmodule Parrhesia.Policy.EventPolicy do | :pow_below_minimum | :pubkey_banned | :event_banned - | :mls_disabled @spec authorize_read([map()], MapSet.t(String.t())) :: :ok | {:error, policy_error()} def authorize_read(filters, authenticated_pubkeys) when is_list(filters) do @@ -57,8 +56,7 @@ defmodule Parrhesia.Policy.EventPolicy do fn -> enforce_pow(event) end, fn -> enforce_protected_event(event, authenticated_pubkeys) end, fn -> enforce_media_metadata_policy(event) end, - fn -> enforce_push_notification_policy(event) end, - fn -> enforce_mls_feature_flag(event) end + fn -> enforce_push_notification_policy(event) end ] Enum.reduce_while(checks, :ok, fn check, :ok -> @@ -135,7 +133,6 @@ defmodule Parrhesia.Policy.EventPolicy do def error_message(:pow_below_minimum), do: "pow: minimum proof-of-work difficulty not met" def error_message(:pubkey_banned), do: "blocked: pubkey is banned" def error_message(:event_banned), do: "blocked: event is banned" - def error_message(:mls_disabled), do: "blocked: mls feature flag is disabled" defp maybe_require_auth_for_write(authenticated_pubkeys) do if config_bool([:policies, :auth_required_for_writes], false) and @@ -651,14 +648,6 @@ defmodule Parrhesia.Policy.EventPolicy do end end - defp enforce_mls_feature_flag(event) do - if event["kind"] in [443, 445, 10_051] and not config_bool([:features, :nip_ee_mls], false) do - {:error, :mls_disabled} - else - :ok - end - end - defp config_bool([scope, key], default) do case Application.get_env(:parrhesia, scope, []) |> Keyword.get(key, default) do true -> true diff --git a/lib/parrhesia/storage/adapters/postgres/events.ex b/lib/parrhesia/storage/adapters/postgres/events.ex index 905ab52..6bbd398 100644 --- a/lib/parrhesia/storage/adapters/postgres/events.ex +++ b/lib/parrhesia/storage/adapters/postgres/events.ex @@ -855,12 +855,12 @@ defmodule Parrhesia.Storage.Adapters.Postgres.Events do defp parse_unix_seconds(_unix_seconds), do: nil defp maybe_apply_mls_group_retention(nil, 445, created_at) do - if Application.get_env(:parrhesia, :features, []) |> Keyword.get(:nip_ee_mls, false) do - ttl = - :parrhesia - |> Application.get_env(:policies, []) - |> Keyword.get(:mls_group_event_ttl_seconds, 300) + ttl = + :parrhesia + |> Application.get_env(:policies, []) + |> Keyword.get(:mls_group_event_ttl_seconds, 300) + if is_integer(ttl) and ttl > 0 do created_at + ttl else nil diff --git a/lib/parrhesia/web/connection.ex b/lib/parrhesia/web/connection.ex index 67197b2..32ac5f8 100644 --- a/lib/parrhesia/web/connection.ex +++ b/lib/parrhesia/web/connection.ex @@ -443,8 +443,7 @@ defmodule Parrhesia.Web.Connection do :push_notification_replay_window_exceeded, :push_notification_missing_expiration, :push_notification_expiration_too_far, - :push_notification_server_recipients_exceeded, - :mls_disabled + :push_notification_server_recipients_exceeded ], do: EventPolicy.error_message(reason) diff --git a/lib/parrhesia/web/relay_info.ex b/lib/parrhesia/web/relay_info.ex index ec18246..02f47fb 100644 --- a/lib/parrhesia/web/relay_info.ex +++ b/lib/parrhesia/web/relay_info.ex @@ -37,15 +37,6 @@ defmodule Parrhesia.Web.RelayInfo do 86, 98 ] - |> maybe_add_mls() - end - - defp maybe_add_mls(nips) do - if Parrhesia.Config.get([:features, :nip_ee_mls], false) do - ["EE" | nips] - else - nips - end end defp limitations do diff --git a/test/parrhesia/config_test.exs b/test/parrhesia/config_test.exs index 830ea7b..0132518 100644 --- a/test/parrhesia/config_test.exs +++ b/test/parrhesia/config_test.exs @@ -12,7 +12,6 @@ defmodule Parrhesia.ConfigTest do assert Parrhesia.Config.get([:policies, :marmot_media_reject_mip04_v1]) == true assert Parrhesia.Config.get([:policies, :marmot_push_max_trigger_age_seconds]) == 120 assert Parrhesia.Config.get([:features, :nip_50_search]) == true - assert Parrhesia.Config.get([:features, :nip_ee_mls]) == false assert Parrhesia.Config.get([:features, :marmot_push_notifications]) == false end diff --git a/test/parrhesia/policy/event_policy_test.exs b/test/parrhesia/policy/event_policy_test.exs index 1a66308..772e826 100644 --- a/test/parrhesia/policy/event_policy_test.exs +++ b/test/parrhesia/policy/event_policy_test.exs @@ -229,7 +229,6 @@ defmodule Parrhesia.Policy.EventPolicyTest do Application.put_env( :parrhesia, :features, - nip_ee_mls: false, marmot_push_notifications: true ) @@ -281,7 +280,6 @@ defmodule Parrhesia.Policy.EventPolicyTest do Application.put_env( :parrhesia, :features, - nip_ee_mls: false, marmot_push_notifications: true ) @@ -337,7 +335,6 @@ defmodule Parrhesia.Policy.EventPolicyTest do Application.put_env( :parrhesia, :features, - nip_ee_mls: false, marmot_push_notifications: true ) @@ -424,15 +421,6 @@ defmodule Parrhesia.Policy.EventPolicyTest do ) end - test "rejects mls kinds when feature is disabled" do - Application.put_env(:parrhesia, :features, nip_ee_mls: false) - - event = %{"kind" => 443, "tags" => [], "pubkey" => String.duplicate("d", 64), "id" => ""} - - assert {:error, :mls_disabled} = - EventPolicy.authorize_write(event, MapSet.new([String.duplicate("d", 64)])) - end - test "enforces min pow difficulty" do Application.put_env(:parrhesia, :policies, min_pow_difficulty: 8) diff --git a/test/parrhesia/storage/adapters/postgres/events_query_count_test.exs b/test/parrhesia/storage/adapters/postgres/events_query_count_test.exs index 2eb24a6..03ee915 100644 --- a/test/parrhesia/storage/adapters/postgres/events_query_count_test.exs +++ b/test/parrhesia/storage/adapters/postgres/events_query_count_test.exs @@ -346,7 +346,7 @@ defmodule Parrhesia.Storage.Adapters.Postgres.EventsQueryCountTest do }) assert {:ok, results} = - Events.query(%{}, [%{"kinds" => [445], "#h" => [group_id]}], []) + Events.query(%{}, [%{"kinds" => [445], "#h" => [group_id]}], now: 1_700_000_700) tie_winner_id = Enum.min([tie_a["id"], tie_b["id"]]) tie_loser_id = Enum.max([tie_a["id"], tie_b["id"]]) @@ -368,7 +368,7 @@ defmodule Parrhesia.Storage.Adapters.Postgres.EventsQueryCountTest do end) assert {:ok, results} = - Events.query(%{}, [%{"kinds" => [445], "#h" => [group_id]}], []) + Events.query(%{}, [%{"kinds" => [445], "#h" => [group_id]}], now: 1_700_001_100) expected_ids = events diff --git a/test/parrhesia/storage/adapters/postgres/events_test.exs b/test/parrhesia/storage/adapters/postgres/events_test.exs index 421aa0e..bd0a7d6 100644 --- a/test/parrhesia/storage/adapters/postgres/events_test.exs +++ b/test/parrhesia/storage/adapters/postgres/events_test.exs @@ -28,12 +28,9 @@ defmodule Parrhesia.Storage.Adapters.Postgres.EventsTest do assert normalized.pubkey == Base.decode16!(pubkey, case: :lower) end - test "applies MLS retention TTL to kind 445 when enabled" do - previous_features = Application.get_env(:parrhesia, :features, []) + test "applies MLS retention TTL to kind 445" do previous_policies = Application.get_env(:parrhesia, :policies, []) - Application.put_env(:parrhesia, :features, Keyword.put(previous_features, :nip_ee_mls, true)) - Application.put_env( :parrhesia, :policies, @@ -41,7 +38,6 @@ defmodule Parrhesia.Storage.Adapters.Postgres.EventsTest do ) on_exit(fn -> - Application.put_env(:parrhesia, :features, previous_features) Application.put_env(:parrhesia, :policies, previous_policies) end) @@ -60,11 +56,8 @@ defmodule Parrhesia.Storage.Adapters.Postgres.EventsTest do end test "keeps explicit expiration tag for kind 445 when present" do - previous_features = Application.get_env(:parrhesia, :features, []) previous_policies = Application.get_env(:parrhesia, :policies, []) - Application.put_env(:parrhesia, :features, Keyword.put(previous_features, :nip_ee_mls, true)) - Application.put_env( :parrhesia, :policies, @@ -72,7 +65,6 @@ defmodule Parrhesia.Storage.Adapters.Postgres.EventsTest do ) on_exit(fn -> - Application.put_env(:parrhesia, :features, previous_features) Application.put_env(:parrhesia, :policies, previous_policies) end) diff --git a/test/parrhesia/web/conformance_test.exs b/test/parrhesia/web/conformance_test.exs index 5478bf5..5504a47 100644 --- a/test/parrhesia/web/conformance_test.exs +++ b/test/parrhesia/web/conformance_test.exs @@ -97,14 +97,6 @@ defmodule Parrhesia.Web.ConformanceTest do end test "kind 445 commit ACK implies durable visibility before wrapped welcome ACK" do - previous_features = Application.get_env(:parrhesia, :features, []) - - Application.put_env(:parrhesia, :features, Keyword.put(previous_features, :nip_ee_mls, true)) - - on_exit(fn -> - Application.put_env(:parrhesia, :features, previous_features) - end) - {:ok, state} = Connection.init(subscription_index: nil) commit_event = @@ -158,9 +150,7 @@ defmodule Parrhesia.Web.ConformanceTest do Application.put_env( :parrhesia, :features, - previous_features - |> Keyword.put(:marmot_push_notifications, true) - |> Keyword.put(:nip_ee_mls, false) + Keyword.put(previous_features, :marmot_push_notifications, true) ) Application.put_env( diff --git a/test/parrhesia/web/connection_test.exs b/test/parrhesia/web/connection_test.exs index 2ecea05..18480df 100644 --- a/test/parrhesia/web/connection_test.exs +++ b/test/parrhesia/web/connection_test.exs @@ -159,14 +159,6 @@ defmodule Parrhesia.Web.ConnectionTest do end test "malformed kind 445 envelope EVENT is rejected" do - previous_features = Application.get_env(:parrhesia, :features, []) - - Application.put_env(:parrhesia, :features, Keyword.put(previous_features, :nip_ee_mls, true)) - - on_exit(fn -> - Application.put_env(:parrhesia, :features, previous_features) - end) - state = connection_state() event = @@ -232,9 +224,7 @@ defmodule Parrhesia.Web.ConnectionTest do Application.put_env( :parrhesia, :features, - previous_features - |> Keyword.put(:marmot_push_notifications, true) - |> Keyword.put(:nip_ee_mls, false) + Keyword.put(previous_features, :marmot_push_notifications, true) ) Application.put_env( @@ -285,9 +275,7 @@ defmodule Parrhesia.Web.ConnectionTest do Application.put_env( :parrhesia, :features, - previous_features - |> Keyword.put(:marmot_push_notifications, true) - |> Keyword.put(:nip_ee_mls, false) + Keyword.put(previous_features, :marmot_push_notifications, true) ) Application.put_env(