-
-
Notifications
You must be signed in to change notification settings - Fork 665
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
Abstraction of cache and context #4357
base: main
Are you sure you want to change the base?
Conversation
|
|
dbaba59
to
9400f19
Compare
[no changelog]
545adf2
to
48f58b0
Compare
addd607
to
3411ee1
Compare
[no changelog]
[no changelog]
3411ee1
to
f51e6dc
Compare
@@ -557,6 +557,7 @@ if FROZEN: | |||
)) | |||
|
|||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/wire/*.py')) | |||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/wire/codec/*.py')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codec specific files are separated so that they can be easily ommited for THP prod builds. When the THP implementation is added, it could look like this:
if THP:
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/wire/thp/*.py'))
if not THP or PYOPT == '0':
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/wire/codec/*.py'))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: The condition or PYOPT == '0'
is in the snippet because the codec will be used on DebugLink
even with THP builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will continue tomorrow
…wnClass [no changelog]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core/src/storage/cache.py
Outdated
@@ -156,210 +12,33 @@ def __init__(self) -> None: | |||
# bytearrays, then later call `clear()` on all the existing objects, which resets them | |||
# to zero length. This is producing some trash - `b[:]` allocates a slice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment should go where the code below it went.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I thought about it previously. The problem with this "comment" is that it explains the process of allocation and the logic behind it.
- Allocation is two-step: first allocate, then clear.
- Note that using b[:] allocates a slice.
The allocation process actually happens just below where the commit is:
_SESSIONLESS_CACHE = ... # step 1
_PROTOCOL_CACHE.initialize() # step 1 and step 2
_SESSIONLESS_CACHE.clear() # step 2
The problem I see is that it is more abstract now - the "real" allocation (and use of slices) happens partly inside a _PROTOCOL_CACHE and SessionlessCache - that are in different files now.
I see a few solutions:
- keep it as it is now - it works as a general documentation
- remove the comment, move the implementation information into docs
- have the comment in each of the implementations (cache_codec, cache_thp)
- some mix of 2. and 3., divide the allocation notes and use relevant parts where necessary
@mmilata WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd go with 3., some duplication won't hurt. Feel free to extend the docs if it makes sense to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done here: 0a878b7
Filter = Callable[[int, Handler], Handler] | ||
|
||
# If set to False protobuf messages marked with "experimental_message" option are rejected. | ||
EXPERIMENTAL_ENABLED = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: shouldn't this also be somewhere under storage/cache
to avoid being wiped by a restart?
[no changelog]
@@ -58,9 +58,6 @@ async def read( | |||
|
|||
async def write(self, msg: protobuf.MessageType) -> None: ... | |||
|
|||
def write_force(self, msg: protobuf.MessageType) -> Awaitable[None]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Removed write_force
as it is not used by any code in main
or in the PR. @mmilata
Abstraction of cache and context so that the current codec_v1 implementation can be switched for THP version.