Skip to content

Commit

Permalink
Change m_additional_fields serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Jul 3, 2022
1 parent 6ba7d33 commit daadb04
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
7 changes: 7 additions & 0 deletions src/gridcoin/voting/payloads.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ class PollPayload : public IContractPayload
{
READWRITE(m_version);
READWRITE(m_poll);

// The poll m_addditional_fields is serialized here rather than in the poll class, because it depends on the
// payload version.
if (m_version >= 3) {
READWRITE(m_poll.m_additional_fields);
}

READWRITE(m_claim);
}
}; // PollPayload
Expand Down
10 changes: 1 addition & 9 deletions src/gridcoin/voting/poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,7 @@ const std::vector<Poll::PollTypeRules> Poll::POLL_TYPE_RULES = {
// These must be kept in the order that corresponds to the PollType enum.
// { min duration, min vote percent AVW, { vector of required additional fieldnames } }
{ 0, 0, {} }, // PollType::UNKNOWN
// Note there is NO payload version protection on the vector of required additional fieldnames
// and all payloads less than v3 only allowed PollType::SURVEY. Furthermore, the serialization
// of the poll class additional fields depends only on whether the poll type is SURVEY. The net
// of this is that the required additional fieldnames need to remain an empty vector for SURVEY.
//
// If a new SURVEY type is needed in the future with additional fields, a new enum entry should
// be created for it.
//
// In addition note that any poll type that has a min vote percent AVW requirement must
// Note that any poll type that has a min vote percent AVW requirement must
// also require the weight type of BALANCE_AND_MAGNITUDE, so therefore the
// only poll type that can actually use BALANCE is SURVEY. All other WeightTypes are deprecated.
{ 7, 0, {} }, // PollType::SURVEY
Expand Down
14 changes: 0 additions & 14 deletions src/gridcoin/voting/poll.h
Original file line number Diff line number Diff line change
Expand Up @@ -557,20 +557,6 @@ class Poll
if (m_response_type != PollResponseType::YES_NO_ABSTAIN) {
READWRITE(m_choices);
}

// Note: this is a little dirty but works, because all polls prior to v3 are SURVEY, and the
// additional fields for survey is an empty vector. Therefore this serialization will only
// be operative if a poll type other than survey is used, and this cannot occur until v3+.
// Refer to the comments in POLL_TYPE_RULES. This is necessary because the only other solution would be
// to pass the poll payload version into the poll object, which would be problematic.
//
// TODO: Remove COMMUNITY after finishing isolated fork testing. (Community was used to test v3 polls
// before the introduction of additional fields, and therefore the community polls on the isolated
// testing fork do not have the m_additional_fields serialization and removal of the COMMUNITY below
// will result in an serialization I/O error.
if (m_type != PollType::SURVEY && m_type != PollType::COMMUNITY) {
READWRITE(m_additional_fields);
}
}
}; // Poll
} // namespace GRC
Expand Down

0 comments on commit daadb04

Please sign in to comment.