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

Allow Porter Operational timeout parameters for /decrypt #53

Merged
merged 10 commits into from
Dec 12, 2023

Conversation

derekpierre
Copy link
Member

@derekpierre derekpierre commented Nov 10, 2023

Type of PR:

  • Bugfix
  • Feature
  • Documentation
  • Other

Required reviews:

  • 1
  • 2
  • 3

What this does:
Allow Porter to accept optional timeout values for performing TACo decrypt operation.

While this will be provided, In order for web apps to actually use it, nucypher-ts/taco-api will need to be updated to allow timeout to optionally specified.

Issues fixed/closed:

  • Fixes #...

Fixes #49 .

Depends on nucypher PR - nucypher/nucypher#3337

Follow-up for /reencrypt filed in #54 .

Why it's needed:

Explain how this PR fits in the greater context of the NuCypher Network.
E.g., if this PR addresses a nucypher/productdev issue, let reviewers know!

Notes for reviewers:

What should reviewers focus on?
Is there a particular commit/function/section of your PR that requires more attention from reviewers?

@derekpierre derekpierre changed the title [WIP] Allow Porter Operational timeout parameters for /decrypt and /reencrypt [WIP] Allow Porter Operational timeout parameters for /decrypt Nov 10, 2023
@derekpierre derekpierre self-assigned this Nov 10, 2023
@derekpierre derekpierre changed the title [WIP] Allow Porter Operational timeout parameters for /decrypt Allow Porter Operational timeout parameters for /decrypt Nov 10, 2023
@derekpierre derekpierre marked this pull request as ready for review November 10, 2023 20:45
@cygnusv
Copy link
Member

cygnusv commented Nov 15, 2023

Looks good in general, but I'm wondering about potential DoS vectors if we allow timeouts to be defined as input parameters.

@derekpierre
Copy link
Member Author

derekpierre commented Nov 15, 2023

Looks good in general, but I'm wondering about potential DoS vectors if we allow timeouts to be defined as input parameters.

Great point - we could put a max cap on the timeout? Perhaps that cap can have a default value, but be overridden by an env variable? That way the Porter operator can make adjustments to the timeout ... open to other ideas ...

Is that something we want to apply to other endpoints eg. /get_ursulas?

The biggest concern is us simply hardcoding a timeout in the code that is potentially insufficient.

@cygnusv
Copy link
Member

cygnusv commented Nov 16, 2023

Looks good in general, but I'm wondering about potential DoS vectors if we allow timeouts to be defined as input parameters.

Great point - we could put a max cap on the timeout? Perhaps that cap can have a default value, but be overridden by an env variable? That way the Porter operator can make adjustments to the timeout ... open to other ideas ...

Is that something we want to apply to other endpoints eg. /get_ursulas?

The biggest concern is us simply hardcoding a timeout in the code that is potentially insufficient.

Configuration via environment variables or some config file are good. We wouldn't want to make a release just to increment a default timeout.

@derekpierre derekpierre changed the title Allow Porter Operational timeout parameters for /decrypt [DON'T MERGE UNTIL NUCYPHER PR MERGED] Allow Porter Operational timeout parameters for /decrypt Nov 16, 2023
@derekpierre derekpierre changed the title [DON'T MERGE UNTIL NUCYPHER PR MERGED] Allow Porter Operational timeout parameters for /decrypt Allow Porter Operational timeout parameters for /decrypt Dec 1, 2023
Pipfile Outdated
nucypher-core = "==0.13.0" # must be the same as nucypher
flask-cors = "*"
prometheus-flask-exporter = "*"

[dev-packages]
nucypher = {git = "https://github.com/nucypher/nucypher.git", editable = true, ref = "v7.0.0-rc.10", extras = ["dev"]} # needed for testerchain, and must be editable
nucypher = {git = "https://github.com/nucypher/nucypher.git", editable = true, ref = "v7.0.0", extras = ["dev"]} # needed for testerchain, and must be editable
Copy link
Member

Choose a reason for hiding this comment

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

Should these values be updated to latest version (v7.0.3)?

DEFAULT_PORT = 9155

MAX_GET_URSULAS_TIMEOUT = os.getenv("PORTER_GET_URSULAS_TIMEOUT", default=15)
MAX_DECRYPTION_TIMEOUT = os.getenv(
"PORTER_MAX_DECRYPTION_TIMEOUT",
Copy link
Member

Choose a reason for hiding this comment

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

Can envvars be documented somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 I was thinking the threshold docs, and the repos readme.

Those will be done separately.

value_factory=value_factory,
target_successes=quantity,
timeout=timeout,
stagger_timeout=1,
Copy link
Member

Choose a reason for hiding this comment

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

What's this timeout?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the timeout between obtaining batches of values for processing - https://github.com/nucypher/nucypher/blob/main/nucypher/utilities/concurrency.py#L322.

In this case batches of staking provider addresses.

Copy link
Member

@manumonti manumonti 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 just left a suggestion

Comment on lines +155 to +163
if timeout and timeout > self.MAX_GET_URSULAS_TIMEOUT:
self.log.warn(
f"Provided sampling timeout ({timeout}s) exceeds "
f"maximum ({self.MAX_GET_URSULAS_TIMEOUT}s); "
f"using {self.MAX_GET_URSULAS_TIMEOUT}s instead"
)
timeout = self.MAX_GET_URSULAS_TIMEOUT
else:
timeout = timeout or self.MAX_GET_URSULAS_TIMEOUT
Copy link
Member

@manumonti manumonti Dec 12, 2023

Choose a reason for hiding this comment

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

Not a blocker, but something we can address in the future: if I understand well, we are not checking in the tests that if the provided timeout > MAX_GET_URSULAS_TIMEOUT, the timeout must be MAX_GET_URSULAS_TIMEOUT.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. I'll look into testing that separately. #56

@derekpierre derekpierre merged commit 8254bf3 into nucypher:development Dec 12, 2023
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

Consider increasing learning timeout
4 participants