Skip to content

Add ability to produce a request ID from a request #74

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

Merged
merged 12 commits into from
Oct 11, 2019

Conversation

paulyoung
Copy link
Contributor

Extracted from #56, with some changes.

This adds some minimal type information for requests for now.

@paulyoung paulyoung requested a review from a team as a code owner October 11, 2019 02:14
@paulyoung
Copy link
Contributor Author

Hydra is now somehow failing with an evaluation error:

hydra-eval-jobs returned exit code 1:
error: illegal name: '.drv'

@paulyoung
Copy link
Contributor Author

But only on darwin...

@paulyoung
Copy link
Contributor Author

I'm now able to reproduce this locally:

error: while evaluating the attribute 'buildPhase' of the derivation 'dfinity-sdk-js-user-library' at /Users/paulyoung/projects/dfinity-lab/sdk/paulyoung/js-user-library-prs/js-user-library/package.nix:11:3:
while evaluating the attribute 'text' of the derivation 'npm-snapshot' at /nix/store/ga5ijbb5q9b5hknm2q5f3jvhsmfz0gn9-nixpkgs-patched/pkgs/build-support/trivial-builders.nix:7:14:
illegal name: '.drv'

We're using napalm (by @nmattia), and it looks like it's having trouble naming or producing a derivation from the package-lock.json file: https://github.com/nmattia/napalm/blob/e4da955b155e8d1bd1858a8479abe9ba9d846fe8/default.nix#L109-L110

I have no idea what triggered this.

@eftychis
Copy link
Contributor

Is this possibly related to any upstream changes @paulyoung ?

@paulyoung
Copy link
Contributor Author

Shouldn't be – everything is pinned 😕

@paulyoung
Copy link
Contributor Author

paulyoung commented Oct 11, 2019

Perhaps master is using a newer version of nixpkgs (via dfinity/common dfinity-lab/common) and that is somehow problematic for napalm

@paulyoung
Copy link
Contributor Author

I seem to have fixed the issue by regenerating the lock file 😑

return new Uint8Array(Buffer.from(hex, "hex").buffer);
// Named `BinaryBlob` as opposed to `Blob` so not to conflict with
// https://developer.mozilla.org/en-US/docs/Web/API/Blob
export type BinaryBlob = Uint8Array & { __blob__: void };
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting -- thanks Paul!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is where I first read about this approach: microsoft/TypeScript#25709 (comment)

@@ -19,7 +19,7 @@
"mkdirp": "^0.5.1",
"output-file-sync": "^2.0.0",
"slash": "^2.0.0",
"source-map": "^0.6.1"
"source-map": "^0.5.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Downgrading?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why but this is a generated file anyway.

// NOTE: `nonce` is optional in the spec, but we provide it so that requests
// are unique and we avoid a bug in the client when the same request is
// submitted more than once: https://dfinity.atlassian.net/browse/DFN-895
nonce?: BinaryBlob;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

sender_sig: new Uint8Array(64) as BinaryBlob,
};

const requestId = await requestIdOf(request);
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self (and anyone interested): I was hoping we have a way to call the client inside the tests and extend this test to incorporate the handler. However, after talking with @paulyoung it seems there is no easy and not time-consuming way to do this: deferred. 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To clarify, I was specifically talking about browser-based end-to-end tests. A Node.js version should be easier to get to sooner.

};

export const requestIdOf = async (request: Request): Promise<RequestId> => {
const { sender_pubkey, sender_sig, ...rest } = request;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would rename the rest -- usually with rest you get the impression that it is left out dropped. It is the other way around here though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The remaining properties are called rest properties and I couldn't think of a better name at the time 😄

I'll rename it to fields.


const traversed: Array<[BinaryBlob, BinaryBlob]> = await Promise.all(hashed);

const sorted: Array<[BinaryBlob, BinaryBlob]> = traversed
Copy link
Contributor

@eftychis eftychis Oct 11, 2019

Choose a reason for hiding this comment

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

Do we need the sorting here? (I am missing the reason here.)

Copy link
Contributor

Choose a reason for hiding this comment

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

determinism.

Edit: Apparently it is in the spec -- tt @paulyoung

Copy link
Contributor

@eftychis eftychis left a comment

Choose a reason for hiding this comment

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

LGTM -- I have 1 question, 1 comment, and a really nit one (feel free to ignore it).

@paulyoung paulyoung merged commit 815942a into master Oct 11, 2019
@paulyoung paulyoung deleted the paulyoung/js-user-library-request-id branch October 11, 2019 21:31
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.

2 participants