Skip to content

feat: Add P2P syncing of lenses#122

Merged
AndrewSisley merged 6 commits into
mainfrom
117-p2p-2
Sep 19, 2025
Merged

feat: Add P2P syncing of lenses#122
AndrewSisley merged 6 commits into
mainfrom
117-p2p-2

Conversation

@AndrewSisley

@AndrewSisley AndrewSisley commented Sep 12, 2025

Copy link
Copy Markdown
Collaborator

Relevant issue(s)

Resolves #117

Description

Adds the ability to sync lenses over a P2P network.

Sync is done synchronously, on demand. Consumers, including Defra, will manage concurrency and timing.

As with the Store PR, testing is very light atm due to time pressure. Testing should ideally be expanded fairly soon.

@AndrewSisley AndrewSisley added this to the LensVM v1.0 milestone Sep 12, 2025
@AndrewSisley AndrewSisley self-assigned this Sep 12, 2025
AndrewSisley added a commit to sourcenetwork/defradb that referenced this pull request Sep 15, 2025
## Relevant issue(s)

Resolves #4007

## Description

Tweaks the `net.Host` interface easier to consume by removing elements
that require direct reference to the exact concrete type.

This is required by Lens, so that a trimmed down `net.Host` interface
can be consumed without making Lens dependant on Defra. The alternative
is to extract `net` to a new repository - this may be desirable long
term, so Lens can spin up a `net.Host` instance, but even if we go that
route I'd be in favour of this change as it allows external apps to
consume the interface without a direct reference.

`net.Host.PeerInfo()` should now be the only interface member containing
a a concrete custom type, I have left it, as this function is syntax
sugar around `ID()` and `Addrs()` and is never going to be required by
anything consuming the type.

The Lens code may be viewed in this PR:
sourcenetwork/lens#122 - see
`host-go/p2p/host.go` for the re declaration of a subset of the
`net.Host` interface.
@AndrewSisley AndrewSisley force-pushed the 117-p2p-2 branch 11 times, most recently from c0352d2 to 997e3f8 Compare September 17, 2025 18:23
@AndrewSisley AndrewSisley changed the title (DO NOT REVIEW) feat: Add P2P syncing of lenses feat: Add P2P syncing of lenses Sep 17, 2025
@AndrewSisley AndrewSisley requested a review from a team September 17, 2025 19:01
@AndrewSisley AndrewSisley marked this pull request as ready for review September 17, 2025 19:01

@fredcarle fredcarle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Just one minor todo before merge.

I do like our new testing frameowrk but I find myself having to relearn it everytime I review updated/new test actions lol.

Comment thread tests/integration/test.go Outdated
func (test *Test) Execute(t testing.TB) {
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

todo: Please document why 5 second is specifically important/chosen.

@AndrewSisley AndrewSisley Sep 19, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

:) I don't remember changing this to 5, It will probably be reverted. The tests are quick and there is nothing special about either number.

  • Revert timeout

@AndrewSisley

Copy link
Copy Markdown
Collaborator Author

I do like our new testing frameowrk but I find myself having to relearn it everytime I review updated/new test actions lol.

Yeah, I have that problem when working in Defra now 😅 The migration has started, and I have a branch that (mostly) updates the AddCollection action, but I was hoping to get far more done before the end of this sprint - so we can use it for the v1 testing.

@AndrewSisley AndrewSisley merged commit 2153f5d into main Sep 19, 2025
4 checks passed
@AndrewSisley AndrewSisley deleted the 117-p2p-2 branch September 19, 2025 15:20
fredcarle pushed a commit to sourcenetwork/defradb that referenced this pull request Mar 4, 2026
## Relevant issue(s)

Resolves #4007

## Description

Tweaks the `net.Host` interface easier to consume by removing elements
that require direct reference to the exact concrete type.

This is required by Lens, so that a trimmed down `net.Host` interface
can be consumed without making Lens dependant on Defra. The alternative
is to extract `net` to a new repository - this may be desirable long
term, so Lens can spin up a `net.Host` instance, but even if we go that
route I'd be in favour of this change as it allows external apps to
consume the interface without a direct reference.

`net.Host.PeerInfo()` should now be the only interface member containing
a a concrete custom type, I have left it, as this function is syntax
sugar around `ID()` and `Addrs()` and is never going to be required by
anything consuming the type.

The Lens code may be viewed in this PR:
sourcenetwork/lens#122 - see
`host-go/p2p/host.go` for the re declaration of a subset of the
`net.Host` interface.
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.

Add P2P fetching of Lenses

2 participants