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: P2P ACP #3317

Merged
merged 10 commits into from
Jan 20, 2025
Merged

Conversation

fredcarle
Copy link
Collaborator

Relevant issue(s)

Resolves #3179

Description

This PR brings ACP functionality to the P2P system. This ensures that permissioned collections do not share blocks of registered documents without ensuring the requesting node has access. This is bypassed on collection replication because the node sending the blocks is sending to peers explicitly.

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

Some new and updated integration tests.

Specify the platform(s) on which this was tested:

  • MacOS

@fredcarle fredcarle added the feature New feature or request label Dec 11, 2024
@fredcarle fredcarle requested a review from a team December 11, 2024 18:47
@fredcarle fredcarle self-assigned this Dec 11, 2024
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 69.52381% with 96 lines in your changes missing coverage. Please review.

Project coverage is 78.22%. Comparing base (442bc57) to head (99be9d1).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
net/server.go 57.14% 40 Missing and 17 partials ⚠️
net/grpc.go 45.45% 11 Missing and 1 partial ⚠️
net/client.go 52.63% 7 Missing and 2 partials ⚠️
acp/identity/identity.go 63.64% 6 Missing and 2 partials ⚠️
internal/db/db.go 82.61% 4 Missing ⚠️
net/errors.go 0.00% 2 Missing ⚠️
internal/db/p2p_replicator.go 91.67% 1 Missing ⚠️
internal/db/request.go 50.00% 1 Missing ⚠️
net/sync_dag.go 80.00% 0 Missing and 1 partial ⚠️
node/node.go 92.86% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3317      +/-   ##
===========================================
- Coverage    78.41%   78.22%   -0.19%     
===========================================
  Files          392      392              
  Lines        35716    35905     +189     
===========================================
+ Hits         28006    28086      +80     
- Misses        6072     6150      +78     
- Partials      1638     1669      +31     
Flag Coverage Δ
all-tests 78.22% <69.52%> (-0.19%) ⬇️

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

Files with missing lines Coverage Δ
http/auth.go 57.89% <100.00%> (-7.73%) ⬇️
internal/db/backup.go 59.43% <100.00%> (ø)
internal/db/collection.go 69.87% <100.00%> (ø)
internal/db/collection_define.go 72.24% <ø> (ø)
internal/db/collection_id.go 79.17% <100.00%> (ø)
internal/db/collection_index.go 87.50% <ø> (ø)
internal/db/definition_validation.go 94.77% <ø> (ø)
internal/db/lens.go 70.80% <100.00%> (ø)
internal/db/merge.go 75.99% <100.00%> (-0.79%) ⬇️
internal/db/messages.go 100.00% <100.00%> (ø)
... and 18 more

... and 11 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 442bc57...99be9d1. Read the comment docs.

@fredcarle fredcarle force-pushed the fredcarle/feat/3179-p2p-acp branch from 25d14f1 to 3de2aaf Compare December 11, 2024 20:40
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.

Look good overall. Good job, Fred!

I left some comments and suggestions.

In general I think it would be also nice to have it written down somewhere how the new bitswap-level ACP works together with the pubsub KMS. Otherwise it's not clear when to use what.

@fredcarle fredcarle force-pushed the fredcarle/feat/3179-p2p-acp branch 3 times, most recently from d35d257 to eae46e0 Compare December 13, 2024 02:36
@@ -339,13 +339,20 @@ func (db *db) DeleteDocActorRelationship(
return client.DeleteDocActorRelationshipResult{RecordFound: recordFound}, nil
}

func (db *db) GetNodeIdentity(context.Context) (immutable.Option[identity.PublicRawIdentity], error) {
func (db *db) GetNodeIdentity(_ context.Context) (immutable.Option[identity.PublicRawIdentity], error) {
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 is with the underscore _? Why was this added?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because just context.Context seems like a mistake. The underscore says that the function parameters are this way because we're following some interface pattern or something like that but we aren't using this parameter within the function.

Copy link
Member

Choose a reason for hiding this comment

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

This is a known go idiom?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is the same as the other areas we use _ to ignore a returned argument. https://go.dev/ref/spec#Blank_identifier

The only reason why just using context.Context worked is because it was the only parameter in the method. If there was more than one, it would be a syntax error.

Unused function parameters are allowed in Go and that's why we often have ctx context.Context as parameter with ctx never being used. I feel that's misleading. Doing _ context.Context at least tells the reader that this parameter needed to be there but we aren't using it.

Comment on lines 349 to 355
func (db *db) GetIdentityToken(_ context.Context, audience immutable.Option[string]) ([]byte, error) {
if db.nodeIdentity.HasValue() {
return db.nodeIdentity.Value().NewToken(time.Hour*24, audience, immutable.None[string]())
}
return nil, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: Remove the context.Context arg? doesn't seem to be needed anywhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a pattern we decided to keep after a discussion we had several months back about removing context. Happy to bring that up for discussion but for now leaving as is.

// - Document is public (unregistered), whether signatured request or not doesn't matter.
func CheckDocAccessWithIdentityFunc(
ctx context.Context,
identityFunc func() immutable.Option[acpIdentity.Identity],
Copy link
Member

Choose a reason for hiding this comment

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

question: Why did we need to do this function thing? instead of just immutable.Option[acpIdentity.Identity]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because in some cases in doesn't make sense to do an extra network call for the identity before knowing if the document is even registered.

Copy link
Member

Choose a reason for hiding this comment

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

Can you explain a bit more? Which document is registered check are we talking about? and which network call for identity?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the net package, when we want to check if a peer has access to a doc we have to request the identity from the node requesting. That's a network call. If we request it before checking that the document is registered, then we might have done that network call for nothing. So the order of priority should be checking that the doc is registered and then requesting the identity to check if it has access.

Copy link
Member

Choose a reason for hiding this comment

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

Is the identity not included from the node requesting from the get go? Maybe I am missing something, why does it need to be requested again?

Copy link
Member

Choose a reason for hiding this comment

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

I'd also like clarification here :)

@fredcarle fredcarle force-pushed the fredcarle/feat/3179-p2p-acp branch from eae46e0 to 137e97e Compare December 20, 2024 20:33
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.

Implementation looks solid. One blocking issue to resolve.

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.

LGTM, thanks for answering all the questions, just left some minor suggestions. Please do resolve the on going discussions before merge from others.

todo: Please make the PR title more descriptive right now it only says P2P ACP which is quite vague for example it can be confused with the initial P2P acp work that has been done for #2366

@fredcarle fredcarle force-pushed the fredcarle/feat/3179-p2p-acp branch from 137e97e to 242ba5e Compare January 17, 2025 21:00
@fredcarle fredcarle force-pushed the fredcarle/feat/3179-p2p-acp branch from 242ba5e to 196ce95 Compare January 17, 2025 21:03
@fredcarle fredcarle requested a review from nasdf January 20, 2025 16:42
@fredcarle fredcarle merged commit bcf91d3 into sourcenetwork:develop Jan 20, 2025
41 of 43 checks passed
@fredcarle fredcarle deleted the fredcarle/feat/3179-p2p-acp branch January 20, 2025 17:58
@fredcarle fredcarle added this to the DefraDB v0.16 milestone Feb 18, 2025
@AndrewSisley
Copy link
Contributor

Bug bash result: No bugs found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blockservice ACP
6 participants