Skip to content

Commit 529816b

Browse files
committed
chaincheck: Fix staleness check
1 parent f6591d2 commit 529816b

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

Diff for: script/chaincheck/IScribeChaincheck.sol

+12-10
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
* "wat": "ETH/USD",
3737
* "bar": 13,
3838
* "decimals": 18,
39-
* "maxAllowedAge": <time in seconds>,
39+
* "stalenessThreshold": <time in seconds>,
4040
* "feeds": [
4141
* "<Ethereum address>",
4242
* ...
@@ -117,7 +117,7 @@ contract IScribeChaincheck is Chaincheck {
117117
check_decimals();
118118

119119
// Liveness:
120-
check_beingPoked();
120+
check_stalenessThreshold();
121121

122122
// Configurations:
123123
check_bar();
@@ -226,8 +226,8 @@ contract IScribeChaincheck is Chaincheck {
226226

227227
// -- Liveness --
228228

229-
function check_beingPoked() internal {
230-
uint maxAllowedAge = config.readUint(".IScribe.maxAllowedAge");
229+
function check_stalenessThreshold() internal {
230+
uint stalenessThreshold = config.readUint(".IScribe.stalenessThreshold");
231231

232232
// Note to make sure address(this) is tolled.
233233
// Do not forget to diss after afterwards again!
@@ -241,18 +241,20 @@ contract IScribeChaincheck is Chaincheck {
241241
uint age;
242242
(ok, val, age) = self.tryReadWithAge();
243243

244+
// Check whether value is provided at all.
244245
if (!ok) {
245246
logs.push(StdStyle.red("Read failed"));
246247
}
247248

248-
if (age > maxAllowedAge) {
249+
// Check whether value's age is older than allowed.
250+
if (block.timestamp - age > stalenessThreshold) {
249251
logs.push(
250252
string.concat(
251-
StdStyle.red("Has stale value:"),
252-
" maxAllowedAge=",
253-
vm.toString(maxAllowedAge),
254-
", current age=",
255-
vm.toString(age)
253+
StdStyle.red("Stale value:"),
254+
" stalenessThreshold=",
255+
vm.toString(stalenessThreshold),
256+
", age=",
257+
vm.toString(block.timestamp - age)
256258
)
257259
);
258260
}

Diff for: script/chaincheck/IScribeOptimisticChaincheck.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {IScribeChaincheck} from "./IScribeChaincheck.sol";
3030
* "wat": "ETH/USD",
3131
* "bar": 13,
3232
* "decimals": 18,
33-
* "maxAllowedAge": <time in seconds>,
33+
* "stalenessThreshold": <time in seconds>,
3434
* "feeds": [
3535
* "<Ethereum address>",
3636
* ...

0 commit comments

Comments
 (0)