Skip to content

Commit

Permalink
remove the unordered_map for the elementSet
Browse files Browse the repository at this point in the history
just use a vector instead. this works for now, but i need to go back and figure out why the old way wasnt working
  • Loading branch information
josibake committed Jan 29, 2024
1 parent 81fcdbf commit b1c5af2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/blockfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ InputsFilter::InputsFilter(const ElementSet& elements)
return;
}
for (const Element& e: elements) {
stream << e;
stream.write(MakeByteSpan(e));
}
}

Expand Down Expand Up @@ -253,7 +253,6 @@ static InputsFilter::ElementSet SilentPaymentFilterElements(const CBlock& block,
{
InputsFilter::ElementSet elements;
if (block_undo.vtxundo.empty()) return elements;
if (block.vtx.size() == 1) return elements;
assert(block.vtx.size() - 1 == block_undo.vtxundo.size());
for (uint32_t i = 0; i < block.vtx.size(); ++i) {
const CTransactionRef& tx = block.vtx.at(i);
Expand All @@ -277,7 +276,7 @@ static InputsFilter::ElementSet SilentPaymentFilterElements(const CBlock& block,
inputs_hash.Set(tweak_data->first.begin(), tweak_data->first.end(), true);
CPubKey input_pubkeys_sum{tweak_data->second};
CPubKey final{inputs_hash.UnhashedECDH(input_pubkeys_sum)};
elements.emplace(*final.begin(), *final.end());
elements.push_back(final);
}
return elements;
}
Expand All @@ -290,7 +289,6 @@ BlockFilter::BlockFilter(BlockFilterType filter_type, const uint256& block_hash,
if (!BuildParams(params)) {
throw std::invalid_argument("unknown filter_type");
}
m_filter = GCSFilter(params, std::move(filter), skip_decode_check);
switch (m_filter_type) {
case BlockFilterType::BASIC:
m_filter = GCSFilter(params, std::move(filter), skip_decode_check);
Expand All @@ -315,7 +313,7 @@ BlockFilter::BlockFilter(BlockFilterType filter_type, const CBlock& block, const
m_filter = GCSFilter(params, BasicFilterElements(block, block_undo));
break;
case BlockFilterType::SILENT_PAYMENTS:
m_filter = SilentPaymentFilterElements(block, block_undo);
m_filter = InputsFilter(SilentPaymentFilterElements(block, block_undo));
break;
case BlockFilterType::INVALID:
throw std::invalid_argument("unknown filter_type");
Expand Down
16 changes: 13 additions & 3 deletions src/blockfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <attributes.h>
#include <uint256.h>
#include <util/bytevectorhash.h>
#include <pubkey.h>

class CBlock;
class CBlockUndo;
Expand Down Expand Up @@ -90,8 +91,8 @@ class GCSFilter

class InputsFilter {
public:
typedef std::vector<unsigned char> Element;
typedef std::unordered_set<Element, ByteVectorHash> ElementSet;
typedef CPubKey Element;
typedef std::vector<Element> ElementSet;

private:
uint32_t m_N; //!< Number of elements in the filter
Expand Down Expand Up @@ -197,7 +198,16 @@ class BlockFilter
if (!BuildParams(params)) {
throw std::ios_base::failure("unknown filter_type");
}
m_filter = GCSFilter(params, std::move(encoded_filter), /*skip_decode_check=*/false);
switch (m_filter_type) {
case BlockFilterType::BASIC:
m_filter = GCSFilter(params, std::move(encoded_filter), /*skip_decode_check=*/false);
break;
case BlockFilterType::SILENT_PAYMENTS:
m_filter = InputsFilter(std::move(encoded_filter), /*skip_decode_check=*/false);
break;
case BlockFilterType::INVALID:
throw std::ios_base::failure("unknown filter_type");
}
}
};

Expand Down

0 comments on commit b1c5af2

Please sign in to comment.