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

Run dirvote_act() as a scheduled event. #62

Closed
wants to merge 8 commits into from

Conversation

Labels
None yet
Projects
None yet
3 participants
@nmathewson
Copy link
Contributor

@nmathewson nmathewson commented Apr 27, 2018

No description provided.

nmathewson added 4 commits Apr 27, 2018
This change should have no behavioral effect: it just uses macros to
describe the current control flow.
This is remarkably simple, given the macros in the last commit.
@coveralls
Copy link

@coveralls coveralls commented Apr 27, 2018

Coverage Status

Coverage decreased (-0.02%) to 58.875% when pulling cf0818e on nmathewson:dirvote_act_refactor into 3a47dfe on torproject:master.

src/or/dirvote.c Outdated

#define IF_TIME_FOR_NEXT_ACTION(when_field, done_field) \
if (voting_schedule.when_field < now && !voting_schedule.done_field) do {
#define ENDIF } while(0);
Copy link
Contributor

@dgoulet-tor dgoulet-tor Apr 30, 2018

Our check-space might not like this while(0) here? Dunno, but my OCD eyes picked it up :P.

dirvote_act(const or_options_t *options, time_t now)
{
if (!authdir_mode_v3(options))
return;
return TIME_MAX;
Copy link
Contributor

@dgoulet-tor dgoulet-tor Apr 30, 2018

Shouldn't -1 be returned here? As in ultimately, this value will probably be used for rescheduling the callback and if not in v3 mode, the callback should just stop no?

Copy link
Contributor Author

@nmathewson nmathewson Apr 30, 2018

I don't think -1 means "stop forever"; it means "try again". TIME_MAX seemed like a reasonable way to say "never".

Copy link
Contributor

@dgoulet-tor dgoulet-tor Apr 30, 2018

True, sorry PERIODIC_EVENT_NO_UPDATE = -1 means don't update last timestamp and try again next period.

Copy link
Contributor

@dgoulet-tor dgoulet-tor Apr 30, 2018

But then we might trigger this BUG():

+  if (BUG(next == TIME_MAX)) {
+    return 3600;
+  }

... which in theory should never be triggered since the callback should never run if authdir_mode_v3() returns false so catching that BUG is good. And returning 3600 allows us to try again to vote in an hour if maybe tor state recovered? We should just add a comment there to explain why 3600 but also why the BUG() considering that dirvote_act() can legitimately return TIME_MAX.

Copy link
Contributor Author

@nmathewson nmathewson May 1, 2018

cd45c16 has some comments to try to explain this. Please let me know if that isn't what you had in mind.

src/or/dirvote.c Outdated
} ENDIF

tor_assert_nonfatal_unreached();
return now + 1;
Copy link
Contributor

@dgoulet-tor dgoulet-tor Apr 30, 2018

Again, shouldn't we stop the callback to be rescheduled here considering we should never get here?

src/or/main.c Outdated
return 3600;
}
if (BUG(next <= now)) {
return 1;
Copy link
Contributor

@dgoulet-tor dgoulet-tor Apr 30, 2018

Probably I would comment here mentionning that chances are the clock changed so then we rescheduled a second after the callback to update everything with the new clock?

Copy link
Contributor Author

@nmathewson nmathewson Apr 30, 2018

So, I think this is impossible for the same reason it couldn't happen in #25948 -- the "next" value here is based on the input time to dirvote_act(), so unless dirvote_act() is buggy, it can't be earlier than the input.

Copy link
Contributor

@dgoulet-tor dgoulet-tor Apr 30, 2018

Indeed.

src/or/main.c Outdated
time_t next = TIME_MAX;
if (authdir_mode_v3(options)) {
next = dirvote_act(options, now);
}
Copy link
Contributor

@dgoulet-tor dgoulet-tor Apr 30, 2018

With the refactoring of callbacks, we should never get in here (else{}) if we aren't a authdir_mode_v3() ... so should we hard assert() or unreached() and return NO_UPDATE so we stop the callback?

Copy link
Contributor Author

@nmathewson nmathewson Apr 30, 2018

okay. Will make that change.

Copy link
Contributor Author

@nmathewson nmathewson Apr 30, 2018

ad22010 tries to fix this.

Copy link
Contributor Author

@nmathewson nmathewson Apr 30, 2018

(and 1f01147 makes that one compile)

src/or/config.c Outdated
dirvote_recalculate_timing(options, time(NULL));
reschedule_dirvote(options);
}
Copy link
Contributor

@dgoulet-tor dgoulet-tor Apr 30, 2018

Hmmm... I'm not entirely sure this will work.

This code path is about when we are NOT a authority and we become one. Meaning that the dirvote event was not enabled before so the reschedule won't do anything.

And at the end of the code path, the periodic_events_on_new_options() is called which rescan the whole list and will the enable dirvote_act(). So all in all, we shouldn't do that here.

Copy link
Contributor Author

@nmathewson nmathewson Apr 30, 2018

Hm, I think you're right. I think I was wondering what we should do if some other option changes (like V3AuthVotingInterval or V3AuthVoteDelay or V3AuthDistDelay). In that case, we'd want to reschedule, right?

Copy link
Contributor Author

@nmathewson nmathewson Apr 30, 2018

cf0818e tries to dtrt here

@nmathewson
Copy link
Contributor Author

@nmathewson nmathewson commented May 7, 2018

We merged an updated and squashed version of this as afd4fc6

@nmathewson nmathewson closed this May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment