spacemeshos / post

Spacemesh POST protocol implementation
MIT License
20 stars 21 forks source link

Add option to keep redundant files #263

Closed xearl4 closed 8 months ago

xearl4 commented 9 months ago

A long-standing pain point for go-spacemesh users is that it simply deletes postdata files that are deemed "redundant". For a go-spacemesh managed through smapp, the behaviour may be reasonable and comprehensible. For CLI users, however, this often means that a simple config mistake of setting the wrong num-units in the config file leads to weeks of postdata file initialisation being quickly wiped out.

With this change, the current default behaviour is preserved: redundant files are deleted. If the new option is enabled, an info entry is logged for redundant files, but they are not deleted.

This change prepares the stage for a dependent change in go-spacemesh.

schinzelh commented 9 months ago

Fixes https://github.com/spacemeshos/go-spacemesh/issues/4594

xearl4 commented 9 months ago

postcli in post/cmd/postcli might also benefit from the new functional option of the Initializer, if you find some time to take a look at it.

Sure. Main question is: what do we want the default to be? Should postcli default to deleting, and keep files if you pass a CLI flag -- or should it keep redundant files by default, and only delete when passed, say, --cleanup?

fasmat commented 9 months ago

postcli requires explicitly stating numUnits; a user specifying fewer units than they have on disk thereby probably intends to initialize the value they provided.

On the other hand having a -keepFiles flag makes less sense then having a -deleteFiles flag. So I guess the default should probably be to not delete 🤔

pigmej commented 9 months ago

I agree with @fasmat here.

by default, it should not delete UNLESS specified.

postcli case is a bit specific because we support from file etc., so trying to guess what the user wanted is, IMO tricky; we should basically do what the user said us to do, so whatever is specified -> ok.

fasmat commented 8 months ago

Hi @xearl4 @schinzelh,

we just merged a change that adds additional checks to postcli to prevent users from accidentally corrupting/deleting their files: https://github.com/spacemeshos/post/pull/270 and released the changed version as v0.12.0 (pre-release for now).

With the upcoming v1.4.x version of go-spacemesh the post data directory can be set to read only after initialization to prevent accidental deletion / corruption of existing data and with the upcoming multi-smeshing release we plan to remove initialization from the node completely and only use postcli for creating PoST data.

I will therefore close this PR. If you feel additional changes are needed feel free to re-open and update your PR and re-start the discussion 🙂

xearl4 commented 8 months ago

Sounds good, thanks!