blockfilterindex Extensibility Proposal #18221

issue nopara73 openend this issue on February 28, 2020
  1. nopara73 commented at 11:58 am on February 28, 2020: none

    #14121 implemented blockfilterindex in a way that it is extensible to different filter types, however there is only one single filter type so far, which is the default one, and combinations of these filter types aren’t possible. In this proposal I describe how it is possible to add other filter types in a way that it is (1) backwards compatible and (2) all possible combinations of different filter types are possible.

    Having Different Filters In Parallel

    As far as I understand the code it is already prepared and adding a new filter type does not require refactoring to achieve this. So one would be able to define

    0blockfilterindex=basic
    1blockfilterindex=p2wpkh
    

    and the software will create both of those filters in parallel.

    Combinations of Filters

    blockfilterindex=basic’s value maps to uint8_t values: 0 and 1. We can also represent uint8_t with a byte array that holds 8 octets. In case of basic it would be 00000000 (0) or 00000001 (1).

    image

    The idea is to use the bytes to denote the next filter types. For example we can assign 00000010 (2) to p2wpkh and 00000100 (4) to p2wsh. Further as the need arises we can use a larger type uint32_t or something like that to be able to define larger number of types.

    image

    But why not just go 1,2,3,4,5... instead? Because this would enable us to also specify filter combinations. For example if I specify 6 (00000110) then I see that the p2wpkh and p2wsh octets are both flipped to true, so the software would add both to the filter:

    image

     0// If blockfilterindex  is turned on.
     1foreach (var script in scripts) {
     2
     3    if (no higher octets are flipped to true other than the basic filter type's) {
     4        filter.Add(script);
     5        continue;
     6    }
     7    // However for backwards compatibility if a higher octet is true then disregard the basic filter type's octet since currently both 0 and 1 are defined to be the basic octet type. This will result two numbers evaluating to the same combination (Alternatively config parsing can throw an error or whatever to disable one of the number.)
     8
     9    if (p2wpkh octet is true AND script is p2wpkh) {
    10        filter.Add(script);
    11        continue;
    12    }
    13
    14    if (p2wsh octet is true AND script is p2wsh) {
    15        filter.Add(script);
    16        continue;
    17    }
    18
    19    // Add other types
    20}
    

    Not In a Hurry

    Luckily whoever would add the next filter type wouldn’t need to consider this proposal at all, because the next filter type would be 2 anyway, which lets us delay the decision until the 3rd filter type is added, of which according to this proposal should hold the value of 4 instead of 3 in order to facilitate the combinations of filter types.

  2. nopara73 added the label Feature on Feb 28, 2020
  3. MarcoFalke commented at 1:43 pm on February 28, 2020: member
    As I read this, this is a BIP modification, which should go here: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki#filter-types (after discussion on the mailing list)
  4. nopara73 commented at 2:37 pm on February 28, 2020: none
    Thank you! I submitted it to the mailing list (needs mod approval.) Will progress forward of creating a PR for the BIP if consensus is reached.
  5. nopara73 closed this on Feb 28, 2020

  6. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-31 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me