Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/blockfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ using util::Join;

static const std::map<BlockFilterType, std::string> g_filter_types = {
{BlockFilterType::BASIC, "basic"},
{BlockFilterType::TAPROOT, "taproot"},
};

uint64_t GCSFilter::HashToRange(const Element& element) const
Expand Down Expand Up @@ -208,6 +209,30 @@ static GCSFilter::ElementSet BasicFilterElements(const CBlock& block,
return elements;
}

static GCSFilter::ElementSet TaprootFilterElements(const CBlock& block,
const CBlockUndo& block_undo)
{
GCSFilter::ElementSet elements;

for (const CTransactionRef& tx : block.vtx) {
for (const CTxOut& txout : tx->vout) {
const CScript& script = txout.scriptPubKey;
if (!script.IsPayToTaproot() || script.empty()) continue;
elements.emplace(script.begin(), script.end());
}
}

for (const CTxUndo& tx_undo : block_undo.vtxundo) {
for (const Coin& prevout : tx_undo.vprevout) {
const CScript& script = prevout.out.scriptPubKey;
if (!script.IsPayToTaproot() || script.empty()) continue;
elements.emplace(script.begin(), script.end());
}
}

return elements;
}

BlockFilter::BlockFilter(BlockFilterType filter_type, const uint256& block_hash,
std::vector<unsigned char> filter, bool skip_decode_check)
: m_filter_type(filter_type), m_block_hash(block_hash)
Expand All @@ -226,7 +251,12 @@ BlockFilter::BlockFilter(BlockFilterType filter_type, const CBlock& block, const
if (!BuildParams(params)) {
throw std::invalid_argument("unknown filter_type");
}
m_filter = GCSFilter(params, BasicFilterElements(block, block_undo));
if (filter_type == BlockFilterType::BASIC) {
m_filter = GCSFilter(params, BasicFilterElements(block, block_undo));
}
if (filter_type == BlockFilterType::TAPROOT) {
m_filter = GCSFilter(params, TaprootFilterElements(block, block_undo));
}
}

bool BlockFilter::BuildParams(GCSFilter::Params& params) const
Expand All @@ -238,6 +268,12 @@ bool BlockFilter::BuildParams(GCSFilter::Params& params) const
params.m_P = BASIC_FILTER_P;
params.m_M = BASIC_FILTER_M;
return true;
case BlockFilterType::TAPROOT:
params.m_siphash_k0 = m_block_hash.GetUint64(0);
params.m_siphash_k1 = m_block_hash.GetUint64(1);
params.m_P = BASIC_FILTER_P;
params.m_M = BASIC_FILTER_M;
return true;
case BlockFilterType::INVALID:
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/blockfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ constexpr uint32_t BASIC_FILTER_M = 784931;
enum class BlockFilterType : uint8_t
{
BASIC = 0,
TAPROOT = 1,
INVALID = 255,
};

Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)

// Signal NODE_COMPACT_FILTERS if peerblockfilters and basic filters index are both enabled.
if (args.GetBoolArg("-peerblockfilters", DEFAULT_PEERBLOCKFILTERS)) {
if (!g_enabled_filter_types.contains(BlockFilterType::BASIC)) {
if (!g_enabled_filter_types.contains(BlockFilterType::BASIC) && !g_enabled_filter_types.contains(BlockFilterType::TAPROOT)) {
return InitError(_("Cannot set -peerblockfilters without -blockfilterindex."));
}

Expand Down
2 changes: 1 addition & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3237,7 +3237,7 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& node, Peer& peer,
BlockFilterIndex*& filter_index)
{
const bool supported_filter_type =
(filter_type == BlockFilterType::BASIC &&
((filter_type == BlockFilterType::BASIC || filter_type == BlockFilterType::TAPROOT) &&
(peer.m_our_services & NODE_COMPACT_FILTERS));
if (!supported_filter_type) {
LogDebug(BCLog::NET, "peer requested unsupported block filter type: %d, %s\n",
Expand Down