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

Fix record author bug #345

Merged
merged 4 commits into from
Dec 12, 2023
Merged

Fix record author bug #345

merged 4 commits into from
Dec 12, 2023

Conversation

frankhinek
Copy link
Contributor

@frankhinek frankhinek commented Dec 9, 2023

Summary

This PR primarily focuses on fixing a bug reported by community members on Discord that occurred when interacting with records retrieved from remote DWNs and subsequent attempts to consume the data payload.

Context

A number of community members and TBD developers had reported that errors were returned when attempting to read data from Record instances:

Uncaught Error: DwnManager: Signing key not found for author: 'did:ion:...'

Further troubleshooting revealed that when large (> DwnConstant.maxDataSizeAllowedToBeEncoded) records authored/signed by one party (Alice) were written to another party's DWN (Bob), the recipient (Bob) was unable to access the data payload with the aforementioned error being thrown. This bug only surfaces when accessing the data (record.data.*) of a record signed by a different entity a Record instance's data, which requires fetching the data from a remote DWN. Since the large (> DwnConstant.maxDataSizeAllowedToBeEncoded) data was not returned with the query as encodedData, the Record instance's data is not available and must be fetched from the remote DWN using a RecordsRead message.

What made this bug particularly difficult to track down is that the bug only surfaces when keys used to sign the record are different than the keys used to fetch the record AND both sets of keys are unavailable to the test Agent used by the entity that is attempting to fetch the record. In all of the other existing tests, the same test agent is used to store the keys for all entities (e.g., "Alice", "Bob", etc.) so the bug never surfaced.

Changes

@web5/api

  • Remove potentially confusing use of author and target in Record class that had been acting as a stand in for the connectedDid. This double-meaning has already introduced several bugs, so this PR removes the usage of the overloaded term and instead refers directly to the connectedDid, where applicable.
  • Improve Record class test structure/efficiency and add failing test for newly discovered bug.
  • Rename remoteTarget to remoteOrigin to improve intuitiveness of semantic meaning.

@web5/agent

  • Minor typo fix in error message.

@frankhinek frankhinek self-assigned this Dec 9, 2023
Copy link

codesandbox bot commented Dec 9, 2023

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@frankhinek frankhinek added the bug Something isn't working label Dec 9, 2023
@frankhinek frankhinek added this to the @web5/api 0.8.4 milestone Dec 9, 2023
Copy link
Contributor

github-actions bot commented Dec 9, 2023

TBDocs Report

✅ No errors or warnings

@web5/api

  • Project entry file: packages/api/src/index.ts

TBDocs Report Updated at 2023-12-09T21:16:42Z 33f666a

@frankhinek frankhinek force-pushed the fix-record-author-bug branch from abc8e20 to 33f666a Compare December 9, 2023 21:14
Copy link

codecov bot commented Dec 9, 2023

Codecov Report

Merging #345 (33f666a) into main (01ece16) will increase coverage by 0.01%.
The diff coverage is 98.30%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #345      +/-   ##
==========================================
+ Coverage   92.69%   92.71%   +0.01%     
==========================================
  Files          75       75              
  Lines       16838    16835       -3     
  Branches     1577     1578       +1     
==========================================
  Hits        15608    15608              
+ Misses       1204     1201       -3     
  Partials       26       26              
Components Coverage Δ
api 96.93% <100.00%> (+0.20%) ⬆️
common 97.78% <ø> (ø)
credentials 94.15% <ø> (ø)
crypto 100.00% <ø> (ø)
dids 91.80% <ø> (ø)
agent 88.08% <0.00%> (ø)
identity-agent 56.81% <ø> (ø)
proxy-agent 58.43% <ø> (ø)
user-agent 55.22% <ø> (ø)

@frankhinek frankhinek requested a review from LiranCohen December 9, 2023 21:50
Copy link
Member

@LiranCohen LiranCohen left a comment

Choose a reason for hiding this comment

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

Looks good! That last test case confused me a bit. Didn't look too much into it, but should we be able to send that?

/**
* 4. Validate that Bob is able to write the record to Alice's remote DWN.
*/
const { status: sendStatusToAlice } = await queryRecordsFrom[0]!.send(aliceDid.did);
Copy link
Member

Choose a reason for hiding this comment

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

This last part of the test is confusing. It says bob is supposed to be able to write, however expects a 401.

@frankhinek frankhinek merged commit 3b82fdb into main Dec 12, 2023
29 of 30 checks passed
@frankhinek frankhinek deleted the fix-record-author-bug branch December 12, 2023 19:01
finn-block pushed a commit that referenced this pull request Mar 19, 2024
* Improve Record class test structure and add failing test for newly discovered bug
* Rename remoteTarget to remoteOrigin
* Correct typo in error message
* Improve semantics of Record class

---------

Signed-off-by: Frank Hinek <[email protected]>
finn-block pushed a commit that referenced this pull request Mar 19, 2024
* Improve Record class test structure and add failing test for newly discovered bug
* Rename remoteTarget to remoteOrigin
* Correct typo in error message
* Improve semantics of Record class

---------

Signed-off-by: Frank Hinek <[email protected]>
finn-block pushed a commit that referenced this pull request Mar 19, 2024
* Improve Record class test structure and add failing test for newly discovered bug
* Rename remoteTarget to remoteOrigin
* Correct typo in error message
* Improve semantics of Record class

---------

Signed-off-by: Frank Hinek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants