Skip to content

Commit

Permalink
Implement spec update: vote search edge cases
Browse files Browse the repository at this point in the history
A vote of zero in either B or EB is distinct from garbage.
  • Loading branch information
dgenr8 committed May 2, 2017
1 parent 1a571fb commit f4d66fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/maxblocksize.cpp
Expand Up @@ -62,7 +62,8 @@ uint64_t GetNextMaxBlockSize(const CBlockIndex* pindexLast, const Consensus::Par

static uint32_t FindVote(const std::string& coinbase) {

uint32_t eb_vote = 0;
bool eb_vote = false;
uint32_t ebVoteMB = 0;
std::vector<char> curr;
bool bip100vote = false;
bool started = false;
Expand Down Expand Up @@ -100,8 +101,9 @@ static uint32_t FindVote(const std::string& coinbase) {
// Look for a EB vote. Keep it, but continue to look for a BIP100/B vote.
if (!eb_vote && curr.size() > 2 && curr[0] == 'E' && curr[1] == 'B') {
try {
eb_vote = boost::lexical_cast<uint32_t>(std::string(
ebVoteMB = boost::lexical_cast<uint32_t>(std::string(
curr.begin() + 2, curr.end()));
eb_vote = true;
}
catch (const std::exception& e) {
LogPrintf("Invalid coinbase EB-vote: %s\n", e.what());
Expand All @@ -117,7 +119,7 @@ static uint32_t FindVote(const std::string& coinbase) {
else
curr.push_back(s);
}
return eb_vote;
return ebVoteMB;
}

uint64_t GetMaxBlockSizeVote(const CScript &coinbase, int32_t nHeight)
Expand Down
8 changes: 7 additions & 1 deletion src/test/maxblocksize_tests.cpp
Expand Up @@ -183,9 +183,15 @@ BOOST_AUTO_TEST_CASE(get_max_blocksize_vote_no_vote) {

// missing BIP100 prefix
BOOST_CHECK_EQUAL(0, GetMaxBlockSizeVote(CScript() << to_uchar("/B2/"), height));

BOOST_CHECK_EQUAL(0, GetMaxBlockSizeVote(CScript() << to_uchar("/BIP100/B/B8/"), height));

//Explicit zeros and garbage
BOOST_CHECK_EQUAL(0, GetMaxBlockSizeVote(CScript() << to_uchar("/BIP100/B0/BIP100/B2"), height));
BOOST_CHECK_EQUAL(0, GetMaxBlockSizeVote(CScript() << to_uchar("/EB0/EB2/"), height));
BOOST_CHECK_EQUAL(0, GetMaxBlockSizeVote(CScript() << to_uchar("/BIP100/Bgarbage/B2/"), height));
BOOST_CHECK_EQUAL(2000000, GetMaxBlockSizeVote(CScript() << to_uchar("/EBgarbage/EB2/"), height));


// Test that height is not a part of the vote string.
// Encoded height in this test ends with /.
// Should not be interpreted as /BIP100/B8/
Expand Down

0 comments on commit f4d66fd

Please sign in to comment.