Answer is “neither” precisely, but closer to the first.
Every time a block is modified, a delta is stored to say what used to be at that position, so that regeneration applies the delta to put back to original state (ordered by a static distance field done at world-gen time which lets it “fill in holes from the bottom” and “collapse towers from the top”), and beacon plot changes move those deltas between a seperate locked storage etc.
It gets a bit more complex than that in terms of application of deltas and manipulation of the delta for resources and liquids (eg no flowing liquids get inserted back, its left to the liquid simulation to re-flow from the sources and a lot of effort was put into the flow behaviour of liquids so that this would always “do the right thing” and reflow to the original state precisely as long as the terrain is back to its original state as well
There are certain types of operations then, which permanently modify (and can never be recovered) the state of the world, eg removal of resin/oil blocks and resources; but also to a lesser extent because dealing with it was more complexity than was deemed worth, chisel rotating surface-resource meshes (if you do it, they wont rotate back when regen occurs)
As a developer, there are cheats to apply changes to the world that are permanent as well, though never used (was just handy when implementing resin/oil behaviour to add “fake” natural source blocks)