Revert ephemeral event handling changes that broke relaytester

- Remove ephemeral event handling in handle-event.go
- Remove ephemeral event rejection in save-event.go
- Remove formatTimestamp function and title attributes in App.svelte
- Remove TestEphemeralEventRejection test
- Fix slice bounds bug in get-serials-by-range.go
- Restore correct error message format for existing events
- Revert version from v0.13.2 to v0.12.3

This reverts commit 075838150d which introduced
a critical bug causing runtime panics in the relaytester.
This commit is contained in:
2025-10-10 19:55:39 +01:00
parent c31cada271
commit dc184d7ff5
6 changed files with 7 additions and 92 deletions

View File

@@ -31,9 +31,9 @@ func (d *D) GetSerialsByRange(idx Range) (
for it.Seek(endBoundary); it.Valid(); it.Next() {
item := it.Item()
var key []byte
key = item.Key()[:len(key)-5]
key = item.Key()
if bytes.Compare(
key, idx.Start,
key[:len(key)-5], idx.Start,
) < 0 {
// didn't find it within the timestamp range
return

View File

@@ -108,16 +108,10 @@ func (d *D) SaveEvent(c context.Context, ev *event.E) (kc, vc int, err error) {
err = errors.New("nil event")
return
}
// Check if the event is ephemeral (kinds 20000-29999) and reject if so
if kind.IsEphemeral(ev.Kind) {
err = errors.New("blocked: ephemeral events (kinds 20000-29999) are not stored")
return
}
// check if the event already exists
var ser *types.Uint40
if ser, err = d.GetSerialById(ev.ID); err == nil && ser != nil {
err = errors.New("blocked: event already exists")
err = errors.New("blocked: event already exists: " + hex.Enc(ev.ID[:]))
return
}

View File

@@ -215,7 +215,7 @@ func TestSaveExistingEvent(t *testing.T) {
}
// Verify the error message
expectedErrorPrefix := "blocked: event already exists"
expectedErrorPrefix := "blocked: event already exists: "
if !bytes.HasPrefix([]byte(err.Error()), []byte(expectedErrorPrefix)) {
t.Fatalf(
"Expected error message to start with '%s', got '%s'",
@@ -223,70 +223,3 @@ func TestSaveExistingEvent(t *testing.T) {
)
}
}
// TestEphemeralEventRejection tests that ephemeral events (kinds 20000-29999) are rejected.
func TestEphemeralEventRejection(t *testing.T) {
// Create a temporary directory for the database
tempDir, err := os.MkdirTemp("", "test-db-*")
if err != nil {
t.Fatalf("Failed to create temporary directory: %v", err)
}
defer os.RemoveAll(tempDir) // Clean up after the test
// Create a context and cancel function for the database
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Initialize the database
db, err := New(ctx, cancel, tempDir, "info")
if err != nil {
t.Fatalf("Failed to create database: %v", err)
}
defer db.Close()
// Create a signer
sign := new(p256k.Signer)
if err := sign.Generate(); chk.E(err) {
t.Fatal(err)
}
// Test different ephemeral event kinds
ephemeralKinds := []uint16{
20000, // EphemeralStart
21000, // LightningPubRPC
22242, // ClientAuthentication
23194, // NWCWalletRequest
23195, // NWCWalletResponse
23196, // NWCNotification
23197, // WalletNotification
24133, // NostrConnect
27235, // HTTPAuth
29998, // Just before EphemeralEnd
}
for _, kindValue := range ephemeralKinds {
// Create an ephemeral event
ev := event.New()
ev.Kind = kindValue
ev.Pubkey = sign.Pub()
ev.CreatedAt = timestamp.Now().V
ev.Content = []byte("Ephemeral event")
ev.Tags = tag.NewS()
ev.Sign(sign)
// Try to save the ephemeral event, it should be rejected
_, _, err = db.SaveEvent(ctx, ev)
if err == nil {
t.Fatalf("Expected ephemeral event with kind %d to be rejected, but it was accepted", kindValue)
}
// Verify the error message
expectedError := "blocked: ephemeral events (kinds 20000-29999) are not stored"
if err.Error() != expectedError {
t.Fatalf(
"Expected error message '%s', got '%s' for kind %d",
expectedError, err.Error(), kindValue,
)
}
}
}