From 694f1fe80874b2280717908d10d40b45e9e2cc82 Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Wed, 11 May 2016 17:34:38 -0400 Subject: [PATCH 1/2] 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. --- changes/feature19036 | 4 ++++ src/or/dirvote.c | 38 ++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 changes/feature19036 diff --git a/changes/feature19036 b/changes/feature19036 new file mode 100644 index 0000000000..98bcfca515 --- /dev/null +++ b/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. diff --git a/src/or/dirvote.c b/src/or/dirvote.c index 9854af7d7f..11b4fd1583 100644 --- a/src/or/dirvote.c +++ b/src/or/dirvote.c @@ -3040,6 +3040,26 @@ dirvote_compute_consensuses(void) if (!pending_vote_list) 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_votes = smartlist_len(pending_vote_list); if (n_votes <= n_voters/2) { @@ -3066,24 +3086,6 @@ dirvote_compute_consensuses(void) 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]; crypto_pk_t *legacy_sign=NULL; From d875101e03680a372fe1ac91dfff0a9bde883dd3 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Thu, 26 May 2016 15:32:34 +0300 Subject: [PATCH 2/2] Functionify code that writes votes to disk. --- src/or/dirvote.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/or/dirvote.c b/src/or/dirvote.c index 11b4fd1583..ac32df99dc 100644 --- a/src/or/dirvote.c +++ b/src/or/dirvote.c @@ -3019,6 +3019,30 @@ dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out) return any_failed ? NULL : pending_vote; } +/* Write the votes in pending_vote_list to disk. */ +static void +write_v3_votes_to_disk(const smartlist_t *pending_vote_list) +{ + smartlist_t *votestrings = smartlist_new(); + char *votefile = NULL; + + 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 */ + }); + + votefile = get_datadir_fname("v3-status-votes"); + write_chunks_to_file(votefile, votestrings, 0, 0); + log_debug(LD_DIR, "Wrote votes to disk (%s)!", votefile); + + tor_free(votefile); + SMARTLIST_FOREACH(votestrings, sized_chunk_t *, c, tor_free(c)); + smartlist_free(votestrings); +} + /** Try to compute a v3 networkstatus consensus from the currently pending * votes. Return 0 on success, -1 on failure. Store the consensus in * pending_consensus: it won't be ready to be published until we have @@ -3028,8 +3052,8 @@ dirvote_compute_consensuses(void) { /* Have we got enough votes to try? */ int n_votes, n_voters, n_vote_running = 0; - smartlist_t *votes = NULL, *votestrings = NULL; - char *consensus_body = NULL, *signatures = NULL, *votefile; + smartlist_t *votes = NULL; + char *consensus_body = NULL, *signatures = NULL; networkstatus_t *consensus = NULL; authority_cert_t *my_cert; pending_consensus_t pending[N_CONSENSUS_FLAVORS]; @@ -3040,26 +3064,17 @@ dirvote_compute_consensuses(void) if (!pending_vote_list) pending_vote_list = smartlist_new(); - /* write the votes out to disk early, so we have them even if we abort - * the consensus process below. */ + /* Write votes to disk */ + write_v3_votes_to_disk(pending_vote_list); + + /* Setup votes smartlist */ 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); - + /* See if consensus managed to achieve majority */ n_voters = get_n_authorities(V3_DIRINFO); n_votes = smartlist_len(pending_vote_list); if (n_votes <= n_voters/2) {