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

Move time-related enabling conditions to p2p #254

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

akoptelov
Copy link
Contributor

@akoptelov akoptelov commented Mar 1, 2024

closes #253

@binier Note that now time passed to enabling condition is slightly differ from what is in the state.time(), but I think this is more consistent, as state.time() might jump back, and time that comes from redux is monotonous. See discussion below.

@akoptelov akoptelov requested a review from binier March 1, 2024 18:53
@binier
Copy link
Collaborator

binier commented Mar 1, 2024

state.time() can't jump back. Why do you think so? In fact it should always be equal to the time that you are passing now to the enabling condition, from what I checked briefly.

Because state.time() also gets the last dispatched action time seen by the reducer and it will match last_action_id in the Store. https://github.com/openmina/redux-rs/blob/0a85a1efb6c817f9714010b801efc7cd882cb947/src/store.rs#L175

@akoptelov
Copy link
Contributor Author

state.time() can't jump back. Why do you think so? In fact it should always be equal to the time that you are passing now to the enabling condition, from what I checked briefly.

Because state.time() also gets the last dispatched action time seen by the reducer and it will match last_action_id in the Store. https://github.com/openmina/redux-rs/blob/0a85a1efb6c817f9714010b801efc7cd882cb947/src/store.rs#L175

Yes, you're right, I've been looking at the reducer.rs while thinking that this an effect, for some reason...
In this case my replacement should be functionally identical for time used in enabling conditions.

I would also remove that state.last_action completely and instead add last_action_id to the ActionMeta, so it is available for reducer and effects.

@akoptelov akoptelov marked this pull request as draft March 2, 2024 15:02
@akoptelov
Copy link
Contributor Author

There are some issues still, probably I screwed up enabling conditions when merged them.

@akoptelov akoptelov force-pushed the feat/enabling-cond-with-time branch from 2db7edc to feacbc6 Compare March 4, 2024 09:35
@akoptelov akoptelov marked this pull request as ready for review March 4, 2024 16:25
@akoptelov akoptelov force-pushed the feat/enabling-cond-with-time branch from 35336b7 to a009fe2 Compare March 4, 2024 16:43
@akoptelov
Copy link
Contributor Author

@binier Zura, how about that? Having additional time-aware method proved to be error-prone, so I've just added the time parameter to is_enabled.

@tizoc
Copy link
Collaborator

tizoc commented Mar 4, 2024

Is this required because the substates don't have access to the top-level state time?

What about adding a new is_enabled_with_time method (which redux will call instead of is_enabled) to the trait that is defined as:

pub trait EnablingCondition<State> {
    /// Enabling condition for the Action.
    ///
    /// Checks if the given action is enabled for a given state.
    fn is_enabled(&self, state: &State) -> bool {
        true
    }

    /// Enabling condition for the Action (version with time).
    ///
    /// Checks if the given action is enabled for a given state and timestamp.
    fn is_enabled_with_time(&self, state: &State, _time: crate::Timestamp) -> bool {
        self.is_enabled(state)
    }
}

This allows for the current enabling conditions that do not require this workaround to keep their current definitions.

@akoptelov
Copy link
Contributor Author

akoptelov commented Mar 5, 2024

Is this required because the substates don't have access to the top-level state time?

Well, partially. On the other hand, keeping time in state is kind of a workaround.

What about adding a new is_enabled_with_time method (which redux will call instead of is_enabled) to the trait that is defined as:

That was my first idea, but with current impl we need to be super-careful implementing EnablingCondition for the global state. By default it calls is_enabled, and if it is is_enabled_with_time that is used for the substate, then it will be a mistake. With only one method we get rid of such errors.

@akoptelov
Copy link
Contributor Author

akoptelov commented Mar 5, 2024

@binier @tizoc If you're fine with this, I'd like to merge it. @binier also this one: openmina/redux-rs#1

@tizoc
Copy link
Collaborator

tizoc commented Mar 5, 2024

@akoptelov right now I cannot come up with a better alternative that solves the issue you mentioned above, so +1 from me

@akoptelov akoptelov force-pushed the feat/enabling-cond-with-time branch from a009fe2 to 804ed3c Compare March 5, 2024 15:11
@akoptelov akoptelov merged commit 64430f5 into develop Mar 5, 2024
3 checks passed
@akoptelov akoptelov deleted the feat/enabling-cond-with-time branch March 5, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants