diff --git a/src/maxblocksize.cpp b/src/maxblocksize.cpp index 672b1e0392775..425dea06a7a1a 100644 --- a/src/maxblocksize.cpp +++ b/src/maxblocksize.cpp @@ -65,10 +65,11 @@ static uint32_t FindVote(const std::string& coinbase) { uint32_t eb_vote = 0; std::vector curr; bool bip100vote = false; + bool started = false; BOOST_FOREACH (char s, coinbase) { - if (s == '/') { + started = true; // End (or beginning) of a potential vote string. if (curr.size() < 2) // Minimum vote string length is 2 @@ -111,8 +112,10 @@ static uint32_t FindVote(const std::string& coinbase) { curr.clear(); continue; } - - curr.push_back(s); + else if (!started) + continue; + else + curr.push_back(s); } return eb_vote; } diff --git a/src/test/maxblocksize_tests.cpp b/src/test/maxblocksize_tests.cpp index 7212e9e51ba0f..6970ad39cf1c7 100644 --- a/src/test/maxblocksize_tests.cpp +++ b/src/test/maxblocksize_tests.cpp @@ -155,8 +155,7 @@ BOOST_AUTO_TEST_CASE(get_max_blocksize_vote_eb) { BOOST_AUTO_TEST_CASE(get_max_blocksize_vote_no_vote) { int32_t height = 600000; - CScript coinbase = CScript() << height << OP_0; - BOOST_CHECK_EQUAL(0, GetMaxBlockSizeVote(coinbase, height)); + BOOST_CHECK_EQUAL(0, GetMaxBlockSizeVote(CScript() << height << OP_0, height)); // votes must begin and end with / BOOST_CHECK_EQUAL(0, GetMaxBlockSizeVote(CScript() << height << to_uchar("/EB2"), height)); @@ -186,6 +185,15 @@ BOOST_AUTO_TEST_CASE(get_max_blocksize_vote_no_vote) { BOOST_CHECK_EQUAL(0, GetMaxBlockSizeVote(CScript() << to_uchar("/B2/"), height)); BOOST_CHECK_EQUAL(0, GetMaxBlockSizeVote(CScript() << to_uchar("/BIP100/B/B8/"), 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/ + CScript coinbase = CScript() << 47; + BOOST_CHECK_EQUAL('/', coinbase.back()); + std::vector vote = to_uchar("BIP100/B8/"); + coinbase.insert(coinbase.end(), vote.begin(), vote.end()); // insert instead of << to avoid size being prepended + BOOST_CHECK_EQUAL(0, GetMaxBlockSizeVote(coinbase, 47)); } BOOST_AUTO_TEST_SUITE_END();