Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: predicate chaining #571

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft

Conversation

MicaiahReid
Copy link
Contributor

@MicaiahReid MicaiahReid commented Apr 27, 2024

This PR introduces the concept of predicate chaining - one predicate can create subsequent predicates.

The first example of this is the bitcoin input predicate. It now has the "follow_inputs" field:

"if_this": {
  "scope": "inputs",
  "txid": {
    "txid": "0x32ed7f5c82d51d3ffdb8544190704e6b11e06d6d675fc527633adbde6a468e0f",
    "follow_inputs": true
  }
}

Consider the following chain of transactions:

block1 - tx1
block2 - tx2 (with input.previous_output == tx1)
block3 - tx3 (with input.previous_output == tx2)
...

Previously, this predicate would just allow you to find any bitcoin transactions that have a transaction input with previous_output.txid equal to the provided txid. So for the example, we could put the txid for tx1, and the predicate would match tx2, since it has an input that uses tx1 for its prevout.

Now, by setting the follow_inputs field to true, you can get all transactions that use txid as input, and all transactions that use those subsequent transaction's id's as inputs. So for our example, providing a txid of tx1 for the predicate would match for tx2 (because it's prevout has tx1) and tx3 (because it's output has a prevout of tx2) and so on.


Notes

Here are some notes on where this PR is, since it doesn't look like I'll be able to finish this during my tenure at Hiro 😞

As this PR currently is, predicate chaining works in that we have a predicate that can create more downstream predicates. The part that is not yet working, and will probably get kind of messy is handling reorgs.

Reorgs will not only have to check against predicates to see if the user needs to be notified of blocks to roll back, but it also needs to actually delete predicates that were generated from reorged blocks.

Maybe the new predicates that can create other predicates have some metadata with them when they're created, such as the identifier of the block that created the predicate? As this is done, we should also implement a more general interface for this new type of predicate.

rafaelcr and others added 8 commits April 23, 2024 09:17
Also separate `StacksPayload` and `BitcoinPayload` into separate types
for easier client-side inference.
Bump version to 1.8.0
When a Chainhook is triggered and we send a payload to a user, we filter
some values based on user settings (`include_proof`, `include_inputs`,
etc). This helps to reduce the payload size that is sent over the wire.

However, when we created this payload, we were omitting these fields
completely even though the corresponding type does not have those fields
as optional. This makes using our SDK types for deserialization
impossible.

This PR adds in those fields in all cases and sets them to empty values
if filtered out.
@MicaiahReid MicaiahReid marked this pull request as draft April 27, 2024 01:27
@MicaiahReid MicaiahReid force-pushed the develop branch 2 times, most recently from 913d3d9 to f0bdfc5 Compare May 9, 2024 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

2 participants