Skip to content

Emit clear when a range of blocks is cleared from local storage - #849

Open
gmaclennan wants to merge 1 commit into
holepunchto:mainfrom
gmaclennan:add-clear-event
Open

Emit clear when a range of blocks is cleared from local storage#849
gmaclennan wants to merge 1 commit into
holepunchto:mainfrom
gmaclennan:add-clear-event

Conversation

@gmaclennan

Copy link
Copy Markdown
Contributor

append and truncate emit session events, but core.clear() emits nothing, so there is no way to observe blocks being removed from local storage. Applications that derive state from the local bitfield (e.g. announcing what they have to other peers over a side channel) need to know when that state shrinks as well as when it grows.

This PR emits a clear event with the cleared range (start, end) after the clear has been flushed, mirroring the truncate event. It is emitted only from the default session state, so atomic batches and named sessions do not emit until their changes land.

No behavior change; observability only.

Use case: CoMapeo peers broadcast their "haves" to each other on first connection, before replicating cores. We need to re-broadcast these haves after a clear.

  • The event signature (start, end) matches clear(start, end)'s arguments. If preferred, we could follow truncate's style, which could carry a richer payload, but the range is what the one known consumer needs.

append and truncate emit session events, but core.clear() emits
nothing, so there is no way to observe blocks being removed from local
storage (e.g. to re-announce state derived from the local bitfield)
without wrapping core.clear. Emit a clear event with the cleared range
after the state has been flushed, mirroring the truncate event.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant