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: Handle P2P with SourceHub ACP #2848

Merged
merged 6 commits into from
Jul 19, 2024

Conversation

AndrewSisley
Copy link
Contributor

@AndrewSisley AndrewSisley commented Jul 18, 2024

Relevant issue(s)

Resolves #2366

Description

Handles P2P with SourceHub ACP.

Local ACP remains blocked off, as documents synced would essentially become public unless encrypted.

The testing assumes that a distributed SourceHub chain would be tested in the SourceHub repo, and so it doesn't bother spinning up a chain per node and dealing with SourceHub sync stuff. Long term we'll want some Defra-based testing around this, but I think we can get away without it. Feel very free to argue against this :)

@AndrewSisley AndrewSisley added feature New feature or request area/auth Related to the authorization and authentication of data labels Jul 18, 2024
@AndrewSisley AndrewSisley added this to the DefraDB v0.13 milestone Jul 18, 2024
@AndrewSisley AndrewSisley requested a review from a team July 18, 2024 20:49
@AndrewSisley AndrewSisley self-assigned this Jul 18, 2024
@AndrewSisley AndrewSisley changed the title feat: Handle P2P with SourceHub ACP feature: Handle P2P with SourceHub ACP Jul 18, 2024
@AndrewSisley AndrewSisley changed the title feature: Handle P2P with SourceHub ACP feature: Handle P2P with SourceHub ACP Jul 18, 2024
@AndrewSisley AndrewSisley changed the title feature: Handle P2P with SourceHub ACP feat: Handle P2P with SourceHub ACP Jul 18, 2024
Copy link

codecov bot commented Jul 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.29%. Comparing base (517333c) to head (5af21e6).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2848      +/-   ##
===========================================
- Coverage    79.40%   79.29%   -0.11%     
===========================================
  Files          323      323              
  Lines        24691    24693       +2     
===========================================
- Hits         19604    19578      -26     
- Misses        3684     3698      +14     
- Partials      1403     1417      +14     
Flag Coverage Δ
all-tests 79.29% <100.00%> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
acp/source_hub_client.go 88.19% <100.00%> (+0.25%) ⬆️
internal/db/errors.go 65.68% <ø> (ø)
internal/db/p2p_replicator.go 74.88% <100.00%> (+0.72%) ⬆️
internal/db/p2p_schema_root.go 77.87% <100.00%> (+0.18%) ⬆️

... and 13 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 517333c...5af21e6. Read the comment docs.

Copy link
Contributor

@islamaliev islamaliev left a comment

Choose a reason for hiding this comment

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

LGTM! Left a few comments

Comment on lines 109 to 111
if acpType == SourceHubACPType {
addedToSourceHub = true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: why not to put in the end of the loop body this:

if acpType == SourceHubACPType {
	break
}

todo: and please leave a short comment reminding why we do it

Copy link
Contributor Author

@AndrewSisley AndrewSisley Jul 18, 2024

Choose a reason for hiding this comment

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

why not to put in the end of the loop body this

That would be much nicer lol, thanks 😁

  • Simplify addedToSourceHub stuff

testUtils.AddPolicy{
Identity: immutable.Some(1),
Policy: `
name: test
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: this seems like a regular policy and doesn't really improve testing readability. Would be nice to extract it to a const.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to shrug this one off as personal preference, as I prefer it inline - partly so that I can see that it is just a regular policy. I could store it in a var called totallyNormalAndUnimportantUserPolicy, but that would make me even more suspicious and would cause me to read it even more carefully than if it was inline (and I'd have to bounce around out of the test to do so) :)

Copy link
Member

Choose a reason for hiding this comment

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

Happy as is

Copy link
Member

@nasdf nasdf left a comment

Choose a reason for hiding this comment

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

Changes look good! One potential issue to resolve.

// TODO-ACP: remove this check/loop after https://github.com/sourcenetwork/defradb/issues/2366
if col.Description().Policy.HasValue() {
return ErrReplicatorSomeColsHavePolicy
if db.acp.HasValue() && !db.acp.Value().SupportsP2P() {
Copy link
Member

Choose a reason for hiding this comment

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

todo: the switch case above this also checks for a policy (unsure why there is not a todo there). It might be cleaner to combine both checks outside of the switch case

Copy link
Contributor Author

@AndrewSisley AndrewSisley Jul 19, 2024

Choose a reason for hiding this comment

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

Nice spot! Yeah I'll pull them both out of the switch and remove one of the error types. Thanks Keenan :)

  • replicator error stuff

Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

Lovely work, finally ties a lot of pieces together.

Just left some todos and questions. Please resolve before merge.

acp/README.md Outdated
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: Would be nice to add a complete p2p flow example using sourcehub acp below under a new heading called Sourcehub P2P or something, similar to how we have other examples in this README.md

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 think that is too lengthy to include in this document and it will help drown out the information currently contained within it.

Comment on lines -252 to -253
// This test documents that we don't allow adding p2p collections that have a policy
// until the following is implemented:
Copy link
Member

Choose a reason for hiding this comment

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

todo: Still makes sense to have the comment that this test documents that we don't allow adding p2p collections that have a policy for local acp.

Copy link
Contributor Author

@AndrewSisley AndrewSisley Jul 19, 2024

Choose a reason for hiding this comment

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

I will delete the test

  • Delete test

@@ -110,6 +111,12 @@ func addPolicyACP(

expectedErrorRaised := AssertError(s.t, s.testCase.Description, err, action.ExpectedError)
assertExpectedErrorRaised(s.t, s.testCase.Description, action.ExpectedError, expectedErrorRaised)

// The policy should only be added to a SourceHub chain once - there is no need to loop through
Copy link
Member

Choose a reason for hiding this comment

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

question: What happens if a node tries to re-add the same exact policy ? Guessing it will output a new policyID and still add the policy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That has not changed, the test framework will still attempt to re-add the policy.

// until the following is implemented:
// TODO-ACP: ACP <> P2P https://github.com/sourcenetwork/defradb/issues/2366
func TestACP_P2POneToOneReplicatorWithPermissionedCollection_Error(t *testing.T) {
func TestACP_P2POneToOneReplicatorWithPermissionedCollection_LocalACP(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

todo: I like the documentation on what the test does (can just add that its for local acp case)

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 dont think it is worth the eye/brain-space here. This one-liner should have been in the description, and I have a large dislike for the description prop as they are very often misleading.

It will save us time in the long run to let the test definition define itself.

testUtils.AddPolicy{
Identity: immutable.Some(1),
Policy: `
name: test
Copy link
Member

Choose a reason for hiding this comment

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

Happy as is

@AndrewSisley AndrewSisley requested a review from nasdf July 19, 2024 15:15
@AndrewSisley AndrewSisley merged commit 25a3063 into sourcenetwork:develop Jul 19, 2024
40 of 42 checks passed
@AndrewSisley AndrewSisley deleted the 2366-p2p-acp branch July 19, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/auth Related to the authorization and authentication of data feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for P2P and ACP
4 participants