diff --git a/scripts/resolver/README.md b/scripts/resolver/README.md index 99e0df4ae..f667f536d 100644 --- a/scripts/resolver/README.md +++ b/scripts/resolver/README.md @@ -310,10 +310,6 @@ per second, and charges a premium on a lapsed name that it does not expose. A quote from one is therefore only safe for a name that was never registered: an `expired` name gets no price rather than one below what the registrar charges. -The grace period, the oracle and its curve are cached for `CONSTANTS_TTL` -(5 minutes), so a retune shows up within that. Per-name values are read on -every query. - **Set `SNRC_CONTROLLER_` wherever `SNRC_REGISTRAR_` is.** Without a controller there is no oracle, so no name can be priced. diff --git a/scripts/resolver/service/snrc-resolve.py b/scripts/resolver/service/snrc-resolve.py index a409aaa72..5c3dc01f8 100755 --- a/scripts/resolver/service/snrc-resolve.py +++ b/scripts/resolver/service/snrc-resolve.py @@ -67,7 +67,6 @@ import json import os import sys -import time from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from urllib.parse import unquote, urlparse from urllib.request import Request, urlopen @@ -190,26 +189,9 @@ def chain_now() -> int: return decode_uint(block["timestamp"]) -# The grace period, the oracle and its curve change only when a contract is -# retuned, so they are read once per TTL rather than on every query. Per-name -# values are never cached. -CONSTANTS_TTL = 300 -_constants: dict = {} - - -def cached(key, read): - """`read()` at most once per CONSTANTS_TTL for `key`.""" - hit = _constants.get(key) - if hit and time.time() - hit[0] < CONSTANTS_TTL: - return hit[1] - value = read() - _constants[key] = (time.time(), value) - return value - - def grace_period(registrar: str) -> int: """A deployment can configure a different window, so it is read on chain.""" - return cached(("grace", registrar), lambda: decode_uint(eth_call(registrar, selector("GRACE_PERIOD()")))) + return decode_uint(eth_call(registrar, selector("GRACE_PERIOD()"))) def expiry_status(expires: int, grace: int, now: int) -> str: @@ -236,10 +218,6 @@ def reservation_reason(tld: str, token: int) -> int: def pricing_params(tld: str): """What it costs to register a name under this TLD, in US cents, or None when no controller or price oracle is configured.""" - return cached(("pricing", tld), lambda: read_pricing_params(tld)) - - -def read_pricing_params(tld: str): controller = CONTROLLERS.get(tld) if not controller: return None diff --git a/scripts/resolver/service/test_snrc_resolve.py b/scripts/resolver/service/test_snrc_resolve.py index fbc86d56f..d3ddf2951 100644 --- a/scripts/resolver/service/test_snrc_resolve.py +++ b/scripts/resolver/service/test_snrc_resolve.py @@ -97,7 +97,6 @@ def setUp(self): snrc.REGISTRARS = {"testing": self.REGISTRAR} snrc.CONTROLLERS = {"testing": ""} snrc.chain_now = lambda: int(time.time()) - snrc._constants.clear() def tearDown(self): snrc.REGISTRARS, snrc.CONTROLLERS, snrc.eth_call, snrc.chain_now = self._saved @@ -214,7 +213,6 @@ def setUp(self): # Expiry alone; ReservedTests covers a configured controller. snrc.CONTROLLERS = {"testing": ""} snrc.chain_now = lambda: int(time.time()) - snrc._constants.clear() def tearDown(self): ( @@ -246,20 +244,6 @@ def test_a_registrar_that_is_not_a_contract_is_an_error_not_a_free_name(self): with self.assertRaises(RuntimeError): snrc.name_status("alice.testing") - def test_the_grace_period_is_read_once_not_per_query(self): - seen = [] - - def eth_call(to, data): - seen.append(data[:10]) - if data.startswith(snrc.selector("GRACE_PERIOD()")): - return "0x" + snrc.encode_uint(self.GRACE) - return "0x" + snrc.encode_uint(int(time.time()) - 3600) - - snrc.eth_call = eth_call - snrc.name_status("alice.testing") - snrc.name_status("alice.testing") - self.assertEqual(seen.count(snrc.selector("GRACE_PERIOD()")), 1) - def test_zero_expiry_means_never_registered(self): snrc.eth_call = self._expiry(0) self.assertEqual( @@ -360,7 +344,6 @@ def setUp(self): snrc.REGISTRARS = {"testing": self.REGISTRAR} snrc.CONTROLLERS = {"testing": self.CONTROLLER} snrc.chain_now = lambda: int(time.time()) - snrc._constants.clear() def tearDown(self): snrc.REGISTRARS, snrc.CONTROLLERS, snrc.eth_call, snrc.chain_now = self._saved @@ -432,7 +415,6 @@ def setUp(self): snrc.REGISTRARS = {"testing": self.REGISTRAR} snrc.CONTROLLERS = {"testing": self.CONTROLLER} snrc.chain_now = lambda: int(time.time()) - snrc._constants.clear() def tearDown(self): ( @@ -555,7 +537,6 @@ def setUp(self): snrc.CONTROLLERS = {"testing": self.CONTROLLER} self.now = int(time.time()) snrc.chain_now = lambda: self.now - snrc._constants.clear() def tearDown(self): ( @@ -624,13 +605,6 @@ def test_a_name_in_grace_never_reaches_the_oracle(self): self.assertEqual(snrc.name_status("acme.testing")["status"], "grace") self.assertEqual(self.oracle_calls, []) - def test_the_oracle_curve_is_read_once_not_per_query(self): - snrc.eth_call = self._chain(self._lapsed(1)) - snrc.name_status("acme.testing") - seen_first = len(self.oracle_calls) - snrc.name_status("acme.testing") - self.assertEqual(self.oracle_calls[seen_first:], []) - def test_a_reserved_lapsed_name_keeps_its_reservation(self): snrc.eth_call = self._chain(self._lapsed(0), reserved=2) reg = snrc.name_status("acme.testing") @@ -671,7 +645,6 @@ def setUp(self): snrc.CONTROLLERS = {"testing": self.CONTROLLER} self.now = int(time.time()) snrc.chain_now = lambda: self.now - snrc._constants.clear() def tearDown(self): (snrc.REGISTRIES, snrc.REGISTRARS, snrc.CONTROLLERS, snrc.eth_call, snrc.chain_now) = self._saved @@ -732,7 +705,6 @@ def setUp(self): snrc.REGISTRARS = {"testing": self.REGISTRAR} snrc.CONTROLLERS = {"testing": ""} snrc.chain_now = lambda: int(time.time()) - snrc._constants.clear() def tearDown(self): ( @@ -838,7 +810,6 @@ def setUp(self): snrc.CONTROLLERS = {"testing": self.CONTROLLER} self.now = int(time.time()) snrc.chain_now = lambda: self.now - snrc._constants.clear() def tearDown(self): ( @@ -982,7 +953,6 @@ def test_each_answer_carries_exactly_its_own_fields(self): for expected_type, (chain, keys) in cases.items(): with self.subTest(type=expected_type): snrc.eth_call = chain - snrc._constants.clear() _, body = snrc.registration("acme.testing") self.assertEqual(body["type"], expected_type) self.assertEqual(set(body), keys)