Skip to content

FileStore::init() deletes the newest records on devices without a real-time clock #15

Open

Description

@mclueppers

Version: master at 84e09a6 (also 0.1.7)
Platform: ESP32 / ESP32-S3 (Arduino, LittleFS), used through microReticulum. It affects any ARDUINO target, where microStore::time() is millis() plus an offset.
Toolchain: pioarduino Arduino core 3.3 / ESP-IDF 5.5, xtensa GCC 14

What happens. init() calls sweep(), which deletes every record whose timestamp is later than microStore::time(). On a device without a real-time clock that clock is millis()/1000 plus an offset the application persists periodically; microReticulum writes it every 10 minutes and restores it before opening its stores. After a reboot the clock therefore resumes from the last saved offset, up to 10 minutes behind where it was. Every record written after that save now carries a future timestamp and is deleted at boot.

Those are the newest records in the store. Through microReticulum they are the paths, known destinations and packet hashes learned in the last minutes before each restart, which is exactly what a node needs to resume forwarding. A device that restarts before its first offset is saved loses all of them, because its clock resumes near zero.

How to reproduce (host): write records stamped ahead of microStore::time(), reopen the store, and count. test_file_store_future_timestamps_survive_reload on the branch below does this: two records at now + 3600 and now + 7200, reopened; master keeps 0 of 2.

Expected: records survive a reopen when the clock has gone backwards; at worst their TTL is measured from the reopen.
Actual: they are deleted.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions