Skip to content

Commit

Permalink
Parser bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
dgenr8 committed Mar 21, 2017
1 parent 5947bd8 commit 4684ec6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/maxblocksize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ static uint32_t FindVote(const std::string& coinbase) {
uint32_t eb_vote = 0;
std::vector<char> curr;
bool bip100vote = false;
bool started = false;

for (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
Expand Down Expand Up @@ -109,8 +110,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;
}
Expand Down
12 changes: 10 additions & 2 deletions src/test/maxblocksize_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,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));
Expand Down Expand Up @@ -185,6 +184,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<unsigned char> 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();

0 comments on commit 4684ec6

Please sign in to comment.