-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3667 from Agoric/3458-unmetered-liveslots
exclude liveslots deserialization code from metering
- Loading branch information
Showing
12 changed files
with
265 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// @ts-check | ||
import { assert } from '@agoric/assert'; | ||
|
||
export function makeDummyMeterControl() { | ||
let meteringDisabled = 0; | ||
|
||
function isMeteringDisabled() { | ||
return !!meteringDisabled; | ||
} | ||
|
||
function assertIsMetered(msg) { | ||
assert(!meteringDisabled, msg); | ||
} | ||
|
||
function assertNotMetered(msg) { | ||
assert(!!meteringDisabled, msg); | ||
} | ||
|
||
function runWithoutMetering(thunk) { | ||
meteringDisabled += 1; | ||
try { | ||
return thunk(); | ||
} finally { | ||
meteringDisabled -= 1; | ||
} | ||
} | ||
|
||
async function runWithoutMeteringAsync(thunk) { | ||
meteringDisabled += 1; | ||
return Promise.resolve() | ||
.then(() => thunk()) | ||
.finally(() => { | ||
meteringDisabled -= 1; | ||
}); | ||
} | ||
|
||
// return a version of f that runs outside metering | ||
function unmetered(f) { | ||
function wrapped(...args) { | ||
return runWithoutMetering(() => f(...args)); | ||
} | ||
return harden(wrapped); | ||
} | ||
|
||
/** @type { MeterControl } */ | ||
const meterControl = { | ||
isMeteringDisabled, | ||
assertIsMetered, | ||
assertNotMetered, | ||
runWithoutMetering, | ||
runWithoutMeteringAsync, | ||
unmetered, | ||
}; | ||
return harden(meterControl); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.