0ceanSlim / grain

Go Relay Architecture for Implementing Nostr 🌾
MIT License
12 stars 1 forks source link

MaxCreatedAt limit config not updating after relay start #28

Closed UTXOnly closed 4 weeks ago

UTXOnly commented 4 weeks ago

What happened

Receiving error below when adding events from a timestamp that should be within the allowed timestamp range:

["OK","1fa30db9ed533b4e5934e6f0809f3d8952611db0b8b1acd5838a552894768b40",false,"invalid: event created_at timestamp is out of allowed range"]

Steps to reproduce

Example

GRAIN log

Received message: ["EVENT", {"id": "1fa30db9ed533b4e5934e6f0809f3d8952611db0b8b1acd5838a552894768b40", "pubkey": "4503baa127bdfd0b054384dc5ba82cb0e2a8367cbdb0629179f00db1a34caacc", "kind": 1, "created_at": 1730059414, "tags": [], "content": "test", "sig": "9a7e6c2f15e172855cbb7fabd8fbfb00013a267e3fea77ec1623141870349be4cd0071f82ebed3c0ff5448231a8cb5bb892e0008d5ea75b623feda718e9a253c"}]
Event 1fa30db9ed533b4e5934e6f0809f3d8952611db0b8b1acd5838a552894768b40 created_at timestamp 1730059414 is out of range [1577836800, 1730058724]

OK note returned to client

nostpy-cli send_event -privkey <REDACTED> -kind 1 -content "test" --relay ws://localhost:8181
Verification successful for event: 1fa30db9ed533b4e5934e6f0809f3d8952611db0b8b1acd5838a552894768b40
Sending event:
('EVENT', {'id': '1fa30db9ed533b4e5934e6f0809f3d8952611db0b8b1acd5838a552894768b40', 'pubkey': '4503baa127bdfd0b054384dc5ba82cb0e2a8367cbdb0629179f00db1a34caacc', 'kind': 1, 'created_at': 1730059414, 'tags': [], 'content': 'test', 'sig': '9a7e6c2f15e172855cbb7fabd8fbfb00013a267e3fea77ec1623141870349be4cd0071f82ebed3c0ff5448231a8cb5bb892e0008d5ea75b623feda718e9a253c'})
to ws://localhost:8181
Response from ws://localhost:8181 is : 
["OK","1fa30db9ed533b4e5934e6f0809f3d8952611db0b8b1acd5838a552894768b40",false,"invalid: event created_at timestamp is out of allowed range"]

Observations

It looks like the function below is setting the value of cfg.EventTimeConstraints.MaxCreatedAt to 5 minutes ahead of now.Unix() but that value is stuck at 5 minutes ahead of the relay start time.

    // Adjust max_created_at based on string value or default to current time
    if strings.HasPrefix(cfg.EventTimeConstraints.MaxCreatedAtString, "now") {
        offset := strings.TrimPrefix(cfg.EventTimeConstraints.MaxCreatedAtString, "now")
        fmt.Printf("Offset is: %s", offset)
        duration, err := time.ParseDuration(offset)
        if err != nil {
            fmt.Printf("Invalid time offset for max_created_at: %s\n", offset)
            cfg.EventTimeConstraints.MaxCreatedAt = now.Unix() // Default to now if parsing fails
        } else {
            cfg.EventTimeConstraints.MaxCreatedAt = now.Add(duration).Unix()
        }
    } else if cfg.EventTimeConstraints.MaxCreatedAt == 0 {
        // Default to the current time if it's set to zero and no "now" keyword is used
        cfg.EventTimeConstraints.MaxCreatedAt = now.Unix()
    }
}

Example

2024/10/27 16:34:52 New connection from IP: 127.0.0.1, User-Agent: Python/3.10 websockets/11.0.3, Origin: 
Received message: ["EVENT", {"id": "8bd911ee94ac7d7bde717f0c8595075db2e43f32eb06f14135ac1f02e4a9ceee", "pubkey": "4503baa127bdfd0b054384dc5ba82cb0e2a8367cbdb0629179f00db1a34caacc", "kind": 1, "created_at": 1730061292, "tags": [], "content": "test", "sig": "bd456673793828f4c4d2da531d56178e1e33129b3a30e0a4bc8c190a004d6a20ed2b66e0effc03c64b4470b97b7a98b823d26b6ec2e8baac79ac7ac49dcd3c85"}]
Event 8bd911ee94ac7d7bde717f0c8595075db2e43f32eb06f14135ac1f02e4a9ceee created_at timestamp 1730061292 is out of range [1577836800, 1730061143]
Error receiving message: EOF
2024/10/27 16:36:27 New connection from IP: 127.0.0.1, User-Agent: Python/3.10 websockets/11.0.3, Origin: 
Received message: ["EVENT", {"id": "7b5255ba5d7bbb89dae6ca50ef16794d11c82d609bf634e4973922d8d3b9421e", "pubkey": "4503baa127bdfd0b054384dc5ba82cb0e2a8367cbdb0629179f00db1a34caacc", "kind": 1, "created_at": 1730061387, "tags": [], "content": "test", "sig": "ee0ea8f4b4a4619dc4eec89221769a7b061e0991e33a01409339932046228166e7716e49a70c421b94c5d49fb260f3652027be16b25c00a780641bbaf2949862"}]
Event 7b5255ba5d7bbb89dae6ca50ef16794d11c82d609bf634e4973922d8d3b9421e created_at timestamp 1730061387 is out of range [1577836800, 1730061143]
UTXOnly commented 4 weeks ago

Resolved by #29