Browse Source

write v3-status-votes file earlier in consensus voting

Make directory authorities write the v3-status-votes file out
to disk earlier in the consensus process, so we have the votes
even if we abort the consensus process later on.

Resolves ticket 19036.
Roger Dingledine 10 years ago
parent
commit
694f1fe808
2 changed files with 24 additions and 18 deletions
  1. 4 0
      changes/feature19036
  2. 20 18
      src/or/dirvote.c

+ 4 - 0
changes/feature19036

@@ -0,0 +1,4 @@
+  o Minor features:
+    - Make directory authorities write the v3-status-votes file out
+      to disk earlier in the consensus process, so we have the votes
+      even if we abort the consensus process below. Resolves ticket 19036.

+ 20 - 18
src/or/dirvote.c

@@ -3040,6 +3040,26 @@ dirvote_compute_consensuses(void)
   if (!pending_vote_list)
   if (!pending_vote_list)
     pending_vote_list = smartlist_new();
     pending_vote_list = smartlist_new();
 
 
+  /* write the votes out to disk early, so we have them even if we abort
+   * the consensus process below. */
+  votes = smartlist_new();
+  votestrings = smartlist_new();
+  SMARTLIST_FOREACH(pending_vote_list, pending_vote_t *, v,
+    {
+      sized_chunk_t *c = tor_malloc(sizeof(sized_chunk_t));
+      c->bytes = v->vote_body->dir;
+      c->len = v->vote_body->dir_len;
+      smartlist_add(votestrings, c); /* collect strings to write to disk */
+
+      smartlist_add(votes, v->vote); /* collect votes to compute consensus */
+    });
+
+  votefile = get_datadir_fname("v3-status-votes");
+  write_chunks_to_file(votefile, votestrings, 0, 0);
+  tor_free(votefile);
+  SMARTLIST_FOREACH(votestrings, sized_chunk_t *, c, tor_free(c));
+  smartlist_free(votestrings);
+
   n_voters = get_n_authorities(V3_DIRINFO);
   n_voters = get_n_authorities(V3_DIRINFO);
   n_votes = smartlist_len(pending_vote_list);
   n_votes = smartlist_len(pending_vote_list);
   if (n_votes <= n_voters/2) {
   if (n_votes <= n_voters/2) {
@@ -3066,24 +3086,6 @@ dirvote_compute_consensuses(void)
     goto err;
     goto err;
   }
   }
 
 
-  votes = smartlist_new();
-  votestrings = smartlist_new();
-  SMARTLIST_FOREACH(pending_vote_list, pending_vote_t *, v,
-    {
-      sized_chunk_t *c = tor_malloc(sizeof(sized_chunk_t));
-      c->bytes = v->vote_body->dir;
-      c->len = v->vote_body->dir_len;
-      smartlist_add(votestrings, c); /* collect strings to write to disk */
-
-      smartlist_add(votes, v->vote); /* collect votes to compute consensus */
-    });
-
-  votefile = get_datadir_fname("v3-status-votes");
-  write_chunks_to_file(votefile, votestrings, 0, 0);
-  tor_free(votefile);
-  SMARTLIST_FOREACH(votestrings, sized_chunk_t *, c, tor_free(c));
-  smartlist_free(votestrings);
-
   {
   {
     char legacy_dbuf[DIGEST_LEN];
     char legacy_dbuf[DIGEST_LEN];
     crypto_pk_t *legacy_sign=NULL;
     crypto_pk_t *legacy_sign=NULL;