celestiaorg / celestia-core

A fork of CometBFT
Apache License 2.0
481 stars 264 forks source link

Return a new file when reading trace files #1360

Open evan-forbes opened 4 months ago

evan-forbes commented 4 months ago

Can we return a fresh copy of the file, instead of a pointer to the file? so that the caller can operate on it as it wishes, e.g., closes, etc.

          this is what we did in a previous iteration, and we still had the issue with data being cut off or overwritten in the file. Each file object is supposed to be a descriptor to the file, with its own cursor, so in theory we should be able to do as you say, but for some reason, we still occasionally hit that issue

_Originally posted by @evan-forbes in https://github.com/celestiaorg/celestia-core/pull/1340#discussion_r1592236786_

ideally, we'd be able to return a new file that can be used independently from the one that is being written to. When this was tried in the past, we've ran into issues setting the seek for the file. This would sometimes cause the data to be written to the beginning of the file or overwriting previous data.