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

Remove SHOULD_GATE_ENTROPY flag #2848

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 5 additions & 36 deletions src/pyodide/internal/topLevelEntropy/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,8 @@
import { default as entropyPatches } from 'pyodide-internal:topLevelEntropy/entropy_patches.py';
import { default as entropyImportContext } from 'pyodide-internal:topLevelEntropy/entropy_import_context.py';
import { default as importPatchManager } from 'pyodide-internal:topLevelEntropy/import_patch_manager.py';
import { LOADED_SNAPSHOT_VERSION } from 'pyodide-internal:snapshot';
import { simpleRunPython } from 'pyodide-internal:util';

// Disable entropy gating when we've restored a snapshot of version 1. Version 1 snapshots were
// created without entropy gating and will crash if they are used with it. If we are creating a new
// snapshot or using one of version at least 2 we should gate.
// TODO: When we've updated all the snapshots, remove this.
const SHOULD_GATE_ENTROPY =
LOADED_SNAPSHOT_VERSION !== 0 && LOADED_SNAPSHOT_VERSION !== 1;

let allowed_entropy_calls_addr: number;

/**
Expand All @@ -40,9 +32,6 @@ function setupShouldAllowBadEntropy(Module: Module) {
}

function shouldAllowBadEntropy(Module: Module) {
if (!SHOULD_GATE_ENTROPY) {
return true;
}
const val = Module.HEAP8[allowed_entropy_calls_addr];
if (val) {
Module.HEAP8[allowed_entropy_calls_addr]--;
Expand Down Expand Up @@ -122,9 +111,6 @@ export function entropyAfterRuntimeInit(Module: Module) {
* so it doesn't need to be called when restoring from snapshot.
*/
export function entropyBeforeTopLevel(Module: Module) {
if (!SHOULD_GATE_ENTROPY) {
return;
}
simpleRunPython(
Module,
`
Expand All @@ -146,29 +132,12 @@ export function entropyBeforeRequest(Module: Module) {
}
IN_REQUEST_CONTEXT = true;
isReady = true;
if (SHOULD_GATE_ENTROPY) {
simpleRunPython(
Module,
`
simpleRunPython(
Module,
`
from _cloudflare.entropy_patches import before_first_request
before_first_request()
del before_first_request
`
);
} else {
// If we shouldn't gate entropy, we just need to reseed_rng. We first have
// to call invalidate_caches b/c the snapshot doesn't know about
// _cloudflare.entropy_patches.
simpleRunPython(
Module,
`
from importlib import invalidate_caches
invalidate_caches()
del invalidate_caches
from _cloudflare.entropy_patches import reseed_rng
reseed_rng()
del reseed_rng
`
);
}
`
);
}