diff --git a/src/maxblocksize.cpp b/src/maxblocksize.cpp index 425dea06a7a1a..64af2dda8959d 100644 --- a/src/maxblocksize.cpp +++ b/src/maxblocksize.cpp @@ -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 curr; bool bip100vote = false; bool started = false; @@ -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(std::string( + ebVoteMB = boost::lexical_cast(std::string( curr.begin() + 2, curr.end())); + eb_vote = true; } catch (const std::exception& e) { LogPrintf("Invalid coinbase EB-vote: %s\n", e.what()); @@ -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) diff --git a/src/test/maxblocksize_tests.cpp b/src/test/maxblocksize_tests.cpp index 6970ad39cf1c7..e294952d48c06 100644 --- a/src/test/maxblocksize_tests.cpp +++ b/src/test/maxblocksize_tests.cpp @@ -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/