Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: waku store sync 2.0 storage and tests #3215

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

SionoiS
Copy link
Contributor

@SionoiS SionoiS commented Dec 17, 2024

Description

Second PR for new Waku store sync 2.0

Include everything Storage related and tests

Specification
Research issue

Changes

  • Storage interface
  • Storage impl.
  • tests

N.B. Cannot be merged before #3213
Followed by #3216

Issue

@SionoiS SionoiS self-assigned this Dec 17, 2024
@SionoiS SionoiS changed the title feat: waksu store sync 2.0 storage and tests feat: waku store sync 2.0 storage and tests Dec 17, 2024
Copy link

github-actions bot commented Dec 17, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:3215

Built from 8535fff

Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, went through this in some detail. lgtm! Good job :). Would it be useful to have a set of unit tests for each public method (insert, batchInsert, prune) to test the boundary conditions at each?

@SionoiS
Copy link
Contributor Author

SionoiS commented Jan 13, 2025

Right, went through this in some detail. lgtm! Good job :). Would it be useful to have a set of unit tests for each public method (insert, batchInsert, prune) to test the boundary conditions at each?

Yes, I will add some.

Comment on lines 7 to 10
method insert*(
self: SyncStorage, element: ID
): Result[void, string] {.base, gcsafe, raises: [].} =
discard
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe insert should be idempotent?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the "idempotent" word but, what does it mean in this context ;P ?

Copy link
Contributor Author

@SionoiS SionoiS Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, when inserting with the same element the first call would be ok() but if you call again err() since the element was already present.

An idempotent function would always insert the same element at the same index and would result in no side effect when calling the same func with the same element multiple times.

Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for it 🥳
Approving to not block
I just added some nitpick comments ;P

waku/waku_store_sync/storage/range_processing.nim Outdated Show resolved Hide resolved
Comment on lines 7 to 10
method insert*(
self: SyncStorage, element: ID
): Result[void, string] {.base, gcsafe, raises: [].} =
discard
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the "idempotent" word but, what does it mean in this context ;P ?

waku/waku_store_sync/storage/storage.nim Outdated Show resolved Hide resolved
waku/waku_store_sync/storage/storage.nim Outdated Show resolved Hide resolved
waku/waku_store_sync/storage/seq_storage.nim Show resolved Hide resolved
self: SeqStorage,
inputBounds: Slice[ID],
inputFingerprint: Fingerprint,
output: var SyncPayload,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not return it inside a Result?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well there's no way for the proc to fail.

Also, the var payload could have been local to the proc but the caller has a loop so it's inconvenient.

# entire range is after any of our elements
return none(Slice[int])

return some(lower ..< upper)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the returned Slice not include the upper too?

Suggested change
return some(lower ..< upper)
return some(lower .. upper)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I'm pretty sure that the Slice[ID] exclude the upper bound so we do the same.

Comment on lines +115 to +116
let state = ItemSet(elements: @[], reconciled: true)
output.itemSets.add(state)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit puzzled about these two lines :)
Are we trying to "return" an empty SyncPayload?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's a valid case where one side have an empty range.

Peer 1:
range A to F
fingerprint 0x53...

Peer 2:
range A to F
no elements :(
send back an empty item set

waku/waku_store_sync/storage/seq_storage.nim Outdated Show resolved Hide resolved
Comment on lines +162 to +173
let slice =
if idxSlice.isNone():
if not inputItemSet.reconciled:
output.ranges.add((inputBounds, itemSetRange))
let state = ItemSet(elements: @[], reconciled: true)
output.itemSets.add(state)
else:
output.ranges.add((inputBounds, skipRange))

return
else:
idxSlice.get()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some room for encapsulation as apparently we have similar approach two or three times

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are slightly different. One has a return the other continue

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.

3 participants