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

refactor: Remove misleading callback_id from register_callback() test function #497

Merged
merged 6 commits into from
Jul 24, 2024

Conversation

stiegerc
Copy link
Contributor

@stiegerc stiegerc commented Jul 21, 2024

The function register_callback() takes a CallbackId as an argument. This suggests that this CallbackId is registered in the CallContextManager such that a response using this CallbackId can later be inducted successfully by passing this sanity check.

This is false. The CallbackId handed to register_callback() is used to construct an update call, but the origin of a call is irrelevant for the sanity check because each message gets its own CallbackId. It is in general not possible to ask the CallContextManager to register a CallbackId, rather you must ask the CallContextManager to register a new Callback for your call and then the CallContextManager generates and registers this Callback with a new CallbackId and returns it to you. This is the CallbackId that must be used to generate the message to pass the sanity check.

Since the origin of the call is irrelevant for the intended purpose of this function, it makes sense to use a system task as the call origin (i.e. a heartbeat or a timer), since that does not require a CallbackId as an input and return the CallbackId that must be used to construct the message instead.

The changes in this PR are such that the misleading CallbackId argument is removed, but otherwise the code is intact. Further changes to improve consistency with how the CallContextManager should be used will be done in a different PR.

@stiegerc stiegerc requested review from a team as code owners July 21, 2024 20:48
@stiegerc stiegerc requested a review from a team as a code owner July 21, 2024 21:20
@dsarlis
Copy link
Member

dsarlis commented Jul 22, 2024

Is this supposed to be a draft PR or is it really ready for review?

@stiegerc
Copy link
Contributor Author

On Gitlab people didn't get a notification when you put Draft: in front. Apparently this works differently somehow on Github. There are some things I was going to do before it's ready. Sorry for the confusion.

@stiegerc
Copy link
Contributor Author

stiegerc commented Jul 22, 2024

This is where the sanity check is done when inducting responses (called from the system state here).

What it checks is the callback ID that is registered here, not what we passed into register_callback() before this change. IIUC CallOrigin::Update has to do with downstream calls so it's the callback ID above in the call tree, which is completely irrelevant for the sanity check AFAICT.
The first callback ID that register_callback() registers and returns is 1 because next_callback_id is initialized to 0.

So the reason tests using register_callback() appear to be working is that they use a callback ID of 1 as the default for test messages, e.g. here, here and here.

This is clearly not how it should be and quite misleading. It may also break on seemingly unrelated changes in the future.

@stiegerc stiegerc changed the title Draft: Refactor: Remove misleading callback_id from register_callback() test function Refactor: Remove misleading callback_id from register_callback() test function Jul 22, 2024
@stiegerc stiegerc changed the title Refactor: Remove misleading callback_id from register_callback() test function refactor: Remove misleading callback_id from register_callback() test function Jul 22, 2024
Copy link
Contributor

@derlerd-dfinity derlerd-dfinity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot. LGTM.

@stiegerc stiegerc added this pull request to the merge queue Jul 24, 2024
Merged via the queue into master with commit 61870cc Jul 24, 2024
21 checks passed
@stiegerc stiegerc deleted the refactor_register_callback_function branch July 24, 2024 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants