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

General vaults review and fixes #720

Merged
merged 9 commits into from
May 20, 2024
Merged

General vaults review and fixes #720

merged 9 commits into from
May 20, 2024

Conversation

tegefaulkes
Copy link
Contributor

@tegefaulkes tegefaulkes commented May 14, 2024

Description

This PR handles a general review of the vaults domain. General optimisations if they can be applied. Minor fixes for vault related issues and some touch ups to the vaults tests.

NOTE: this branches off from the git refactoring PR and is targeting that for now. But once the git refactoring is merged then this needs to rebase and target staging.

Issues Fixed

Tasks

Final checklist

  • Domain specific tests
  • Full tests
  • Updated inline-comment documentation
  • Lint fixed
  • Squash and rebased
  • Sanity check the final build

@tegefaulkes tegefaulkes self-assigned this May 14, 2024
Copy link

linear bot commented May 14, 2024

@tegefaulkes tegefaulkes changed the base branch from staging to feature-eng-68-review-and-refactor-of-gitutilsts-for-serving-vault-git May 14, 2024 09:27
@CMCDragonkai
Copy link
Member

What's the order of merging in relation to #709?

@tegefaulkes
Copy link
Contributor Author

#709 merges first and then this one.

@tegefaulkes tegefaulkes force-pushed the feature-vaults-review branch from 291bad1 to 46ff0bb Compare May 15, 2024 03:49
@tegefaulkes tegefaulkes force-pushed the feature-vaults-review branch from 46ff0bb to 22775a7 Compare May 15, 2024 03:55
@tegefaulkes tegefaulkes changed the base branch from feature-eng-68-review-and-refactor-of-gitutilsts-for-serving-vault-git to staging May 15, 2024 03:55
@tegefaulkes
Copy link
Contributor Author

Switched base over staging now that git refactoring has been merged.

@tegefaulkes
Copy link
Contributor Author

In the pullVault function in VaultInternal. There is an let error variable that is never set or modified but it affects some logic. I need to dig into this since it can't be intended as it is.

@tegefaulkes
Copy link
Contributor Author

tegefaulkes commented May 15, 2024

One of the vaults test for pulling was failing randomly. With some testing I found that it's random network traffic with the mainnet.

image

I'll need to make sure any tests using a node connection don't actually try to join the mainnet when testing. In this case we have a NodeConnectionManager for testing but give it an empty manifest. On the same note, it's very odd that the test is failing for failing to handle incoming RPC requests. This shouldn't crash us so maybe I need to look deeper into that.

So yeah, there are two problems here.

  1. I have a minimal NodeConnectionManager needed to start forward connections but it's receiving reverse connections from the mainnet. Likely from trying to join it itself. We shouldn't be starting or receiving external connections unless the test explicitly wants to do this.
  2. There is an RPC error for a missing handler propagating outwards causing the test to fail. By design this should only bubble through the stream back through the RPC. This isn't a critical error that should ever leave the RPC. Something is wrong here.

@tegefaulkes
Copy link
Contributor Author

I may need to add #461 to this to address the intermittent failure mentioned above. Though at the same time, I feel like this PR is getting too large in scope? I'll think about it.

@tegefaulkes
Copy link
Contributor Author

One of the vaults test for pulling was failing randomly. With some testing I found that it's random network traffic with the mainnet.

image

I'll need to make sure any tests using a node connection don't actually try to join the mainnet when testing. In this case we have a NodeConnectionManager for testing but give it an empty manifest. On the same note, it's very odd that the test is failing for failing to handle incoming RPC requests. This shouldn't crash us so maybe I need to look deeper into that.

So yeah, there are two problems here.

  1. I have a minimal NodeConnectionManager needed to start forward connections but it's receiving reverse connections from the mainnet. Likely from trying to join it itself. We shouldn't be starting or receiving external connections unless the test explicitly wants to do this.
  2. There is an RPC error for a missing handler propagating outwards causing the test to fail. By design this should only bubble through the stream back through the RPC. This isn't a critical error that should ever leave the RPC. Something is wrong here.

I made a new issue #722 And it will be addressed later, outside this PR.

@tegefaulkes
Copy link
Contributor Author

vaultOps.addSecretDirectory is a weird case. All other vaultOps operate purely within the EFS with an secret contents passed directly into it. but addSecretDirectory seems to access the fs directly reading from it to copy a directory into a vault.

I don't like this. It makes it the only secret command that functions against the node's filesystem and not the Polykey-CLI's file system. We need to review this and work out what we want to do with it.

@tegefaulkes
Copy link
Contributor Author

So addSecretDirectory needs to be refactored in how it works. currently it accesses the fs to read the directory when copying it to the vault. However, as mentioned in all other vaultOps that write data, the data is passed into the function. From the CLI perspective, the files are sent over the RPC when adding to the vault.

The problem here is addSecretDirectory is the odd duck out. The data isn't sent over the RPC, it's read directly from the fs. So we need to refactor it. There are two options

  1. We refactor it so the directory and all it's contents are sent over the RPC to the addSecretDirectory command. A bit of a hassle but do-able. We'd have to encode directory and file contents in a binary stream. I'd rather handle this in a separate PR.
  2. We remove the addSecretDirectory and it's CLI command. Seems like a QOL function.

@tegefaulkes
Copy link
Contributor Author

I'm working on #714 right now. It's a pretty simple fix. However I found that we don't test the case where you pull a vault that deviated from the original history.

I modified a test to check this and isomorphic-git doesn't actually support handling that.

Merges with conflicts are not supported yet.
ErrorVaultsMergeConflict: Merges with conflicts are not supported yet.
    at constructor_.pullVault (/home/brian/workspace/Polykey/src/vaults/VaultInternal.ts:651:15)
    at /home/brian/workspace/Polykey/src/vaults/VaultManager.ts:789:9
    at withF (/home/brian/workspace/Polykey/node_modules/@matrixai/resources/src/utils.ts:24:12)
    at constructor_.pullVault (/home/brian/workspace/Polykey/src/vaults/VaultManager.ts:784:5)
    at withF (/home/brian/workspace/Polykey/node_modules/@matrixai/resources/src/utils.ts:24:12)
    at Object.<anonymous> (/home/brian/workspace/Polykey/tests/vaults/VaultManager.test.ts:1138:9)

So I'm not actually sure it's possible to handle this case. We'd have to clone the vault from scratch to handle it really. Do we just throw an error urging the user to clone the vault fresh due to the deviating history?

@CMCDragonkai
Copy link
Member

When you a pull a vault into a deviated history. This is what supposed to happen:

  1. You are not allowed to do it.

At a higher level, the user upon editing a vault that is "pulled", should be doing a COW operation, the vault must be duplicated and separated from the old vault. The old vault maintains its ability to be pulled.

This means you cannot have a deviated history at all. It's not allowed by the constraints of the system.

@tegefaulkes
Copy link
Contributor Author

I'm aware that we restrict editing of a vault that has been cloned. But the remote vault we clone from can do a branching commit and completely change it's history. Do we apply the same restraint in this case? Where we disallow pulling a vault who's history no longer matches our cloned vault's history?

Different sides of the same coin really. Just want to be clear since the example you gave was the opposite side to the example I described.

@CMCDragonkai
Copy link
Member

I'm aware that we restrict editing of a vault that has been cloned. But the remote vault we clone from can do a branching commit and completely change it's history. Do we apply the same restraint in this case? Where we disallow pulling a vault who's history no longer matches our cloned vault's history?

Different sides of the same coin really. Just want to be clear since the example you gave was the opposite side to the example I described.

It must be disallowed on both sides.

Linear history must be maintained. If the other side corrupted the vault, you just decline the ability to pull. You indicate why.

@tegefaulkes tegefaulkes marked this pull request as ready for review May 17, 2024 07:32
@tegefaulkes
Copy link
Contributor Author

tegefaulkes commented May 17, 2024

I still need to do one last once-over, but it's ready for review. Doesn't need a deep review. Just so you are aware of changes and the more eyes on it the better. @CMCDragonkai @amydevs

I'll run through the checklist after review. No point doing most of the checklist if there are changes that need to be made still.

src/vaults/utils.ts Outdated Show resolved Hide resolved
@CMCDragonkai
Copy link
Member

How was #260 and #714 fixed? Can you describe the solution in the spec?

@CMCDragonkai
Copy link
Member

I'm aware that we restrict editing of a vault that has been cloned. But the remote vault we clone from can do a branching commit and completely change it's history. Do we apply the same restraint in this case? Where we disallow pulling a vault who's history no longer matches our cloned vault's history?
Different sides of the same coin really. Just want to be clear since the example you gave was the opposite side to the example I described.

It must be disallowed on both sides.

Linear history must be maintained. If the other side corrupted the vault, you just decline the ability to pull. You indicate why.

And do you have a corresponding exception for these cases now?

@tegefaulkes
Copy link
Contributor Author

I'm aware that we restrict editing of a vault that has been cloned. But the remote vault we clone from can do a branching commit and completely change it's history. Do we apply the same restraint in this case? Where we disallow pulling a vault who's history no longer matches our cloned vault's history?
Different sides of the same coin really. Just want to be clear since the example you gave was the opposite side to the example I described.

It must be disallowed on both sides.
Linear history must be maintained. If the other side corrupted the vault, you just decline the ability to pull. You indicate why.

And do you have a corresponding exception for these cases now?

Yes, there was an existing error for this called ErrorVaultsMergeConflict

@CMCDragonkai
Copy link
Member

Does ErrorVaultsMergeConflict work both ways? It generically means both conflict during a pull and any attempt to conflict it locally? Or are you just ensuring that one cannot corrupt one's own vault automatically?

Are you preventing the node from mutating its own (pulled/cloned) vault, and breaking history for a vault that has been pulled or cloned...? Or maybe the error only shows up on the pulling/cloning side?

@CMCDragonkai
Copy link
Member

You should update the spec of this PR describing any protocol changes - and how was the solution implemented in a human readable manner. Including in reference to the above comments.

@tegefaulkes
Copy link
Contributor Author

Does ErrorVaultsMergeConflict work both ways? It generically means both conflict during a pull and any attempt to conflict it locally? Or are you just ensuring that one cannot corrupt one's own vault automatically?

Are you preventing the node from mutating its own (pulled/cloned) vault, and breaking history for a vault that has been pulled or cloned...? Or maybe the error only shows up on the pulling/cloning side?

Yes, weather the local history diverged or the remove diverged, it looks like a disconnect in the history that requires a merge. So the same error in both cases.

We can't modify local history anyway since any attempt to do so will result in a ErrorVaultRemoteDefined: Vault is a clone of a remote vault and can not be mutated error. So cloned vaults are immutable.

@tegefaulkes tegefaulkes force-pushed the feature-vaults-review branch from 7df974f to d83760a Compare May 20, 2024 04:04
@tegefaulkes
Copy link
Contributor Author

Ready to merge. I'll write up the changes in a moment.

src/git/http.ts Outdated Show resolved Hide resolved
@CMCDragonkai
Copy link
Member

CMCDragonkai commented May 20, 2024 via email

@tegefaulkes tegefaulkes merged commit 92890f6 into staging May 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants