Skip to main content
Version: 🚀 Next

Panorama

Motivation: Consider a node with an out-degree of 100, where each of its neighbors also has a similar out-degree. If the goal is to sample 10 nodes from the neighborhood within 3 hops, a breadth-first search (BFS) traversal will likely return 10 direct neighbors of the root node, and a depth-first search (DFS) search will likely return the first neighbor found and 9 of that neighbor's neighbors. Therefore, neither of these methods will effectively sample nodes up to 3 hops away, nor will the sampled subgraph be representative of the broader 3-hop neighborhood structure.

Therefore, to sample representative neighborhoods in the Bitcoin graph, we developed a method that randomly selects a subset of neighbors for a root node. Then, for each of those selected nodes, it chooses a subset of their immediate neighbors, and continues this process until a termination criterion is met.

You may set the sample method to use the Panorama algorithm and adjust the algorithm's parameters as follows.

Example:

.\aab.eba.exe bitcoin sample `
--count 1000 `
--method panorama `
--method-options '{\"maxHops\": 6, \"nodeCountAtRoot\": 10, \"reductionFactor\": 2, \"queryLimit\": 1000}'

This command sets the method to sample, aiming for 100 communities using the ffs (Panorama sampling) strategy at a maximum depth of 6 hops from the root nodes.

Alternatively, you may set the options using a JSON file as the following.

> cat inputs.json
{
"Bitcoin": {
"GraphSample": {
"Count": 2,
"TraversalAlgorithm": 0,
"MinNodeCount": 200,
"MaxNodeCount": 10000,
"MinEdgeCount": 199,
"MaxEdgeCount": 100000,
"MaxAttempts": 25,
"RootNodeSelectProb": 0.3,
"PanoramaOptions": {
"maxHops": 2,
"queryLimit": 100000,
"reductionFactor": 4,
"nodeCountAtRoot": 100,
"maxOriginalInDegree": 1000,
"maxOriginalOutDegree": 1000,
"includeBlockTxEdges": true
}
}
}
}

> .\aab.eba.exe bitcoin sample --status-filename inputs.json

Provide root nodes from a TSV file​

Use --root-nodes-filename instead of randomly selected Script roots:

.\aab.eba.exe bitcoin sample --count 4 --method panorama --root-nodes-filename roots.tsv

Each TSV row contains node kind, then its identifying value (not the property name). Kind names are case-insensitive; numeric values are also accepted:

KindIdentifying value
Coinbase / 1Coinbase
Script / 2Address
Block / 3Height
Tx / 4Txid

Blank lines, # comments, and a first-line NodeKind or Kind header are skipped. Duplicate kind/value pairs are removed; Undefined (0), invalid kinds, and missing values are rejected.

--root-node-select-prob is ignored; --count still limits successfully serialized graphs. Each retry starts at the file's beginning, so rejected and successful roots may be sampled again, up to MaxAttempts.

For JSON configuration, set Bitcoin.GraphSample.RootNodesFilename (outside PanoramaOptions).

Panorama options​

FFS-specific arguments are documented below.

OptionTypeDefaultDescription
maxHopsint2Maximum traversal depth (hops) away from the root node.
queryLimitint1000Maximum number of neighbors to query from the database before sampling.
nodeCountAtRootint100Maximum number of neighbors to sample from the root node.
reductionFactordouble4.0Factor controlling the reduction of sampled neighbors as hop depth increases.
deterministicSamplingboolfalseUse a fixed seed for neighbor sampling.
ensureTxSendersAndReceiversbooltrueKeep a sender and a receiver of every expanded Tx, and reject communities whose root Script has no counterparty.

deterministicSampling​

By default, neighbor sampling is non-deterministic (false), which is useful in production for exploring multiple sampled versions of the neighborhood around the same important transaction. Provide that transaction as a Tx root in a root nodes file and sample it repeatedly; individual samples can still coincide.

Set "deterministicSampling": true in PanoramaOptions (or in the JSON passed to --method-options) to use a fixed seed for each neighbor shuffle. This is primarily useful during development and debugging: the same ordered candidates produce the same selection. For example:

.\aab.eba.exe bitcoin sample --count 1 --method panorama --root-nodes-filename roots.tsv `
--method-options '{\"deterministicSampling\": true}'

This option does not seed Neo4j's random root selection. Use a root nodes file to choose a specific root. Even then, results can differ if the database changes or returns candidates or relationships in a different order, including when queryLimit restricts the candidate pool.

ensureTxSendersAndReceivers​

A Tx links two Scripts only when the community holds a Script that the Tx spends from (a sender) and a Script that the Tx pays more than 0 and that is not also a sender (a receiver). The random selection of neighbors does not look at the direction of an edge, so without this option a Tx can end up with Scripts on one side only, or with none at all. A community whose root has only such Tx is of no use to a script-to-script model, because no Script sends to the root or receives from it.

With this option on (the default), Panorama does two things:

  1. When it expands a Tx and the community holds no sender of that Tx, it also keeps the first sender in the shuffled candidate order, and the same for the receivers. So the choice stays random, and each expanded Tx gains at most two Scripts. When activity windows are set, the added Script must satisfy them.
  2. After the walk, it rejects a community whose root Script has no counterparty: no Tx of the community links the root to another Script as sender and receiver. The rejection works like the rejection of a community that is too small.

The edge activity window applies first, so a Tx whose senders all lie outside it still has one side only. Set "ensureTxSendersAndReceivers": false to get the selection of earlier versions.

maxHops​

Sets the maximum number of hops away from the root node that the algorithm is allowed to traverse.

queryLimit​

Sets the maximum number of neighbors to query from the database for a given node. These queried nodes become the candidate pool for the Panorama algorithm (i.e., the algorithm will select a subset from these).

nodeCountAtRoot​

Sets the maximum number of neighbors to sample from the root node's queried set (the size of which is limited by queryLimit).

reductionFactor​

As the algorithm traverses deeper from the root node, it randomly selects fewer neighbors. This reduction is controlled by the reduction factor. The number of nodes sampled at a specific hop is calculated as:

floor(nodeCountAtRoot - (hop * reductionFactor))

Sample Scripts by their activity in a block-height window​

A Script node can be active over many years of the chain. You may want a sample that only holds Scripts that were active in a given period, for example the blocks of one year. The activity window options let you set that period as a range of block heights, and set how much of a Script's activity must fall inside that range.

Each edge of a Script is one activity, and each activity has a block height:

  • An incoming edge (Credits) is active at its CreationHeight, which is the height of the block that created the output.
  • An outgoing edge (Redeems) is active at its SpentHeight, which is the height of the block that spent the output.

Panorama applies the windows only to Script nodes. Tx, Block and Coinbase nodes always pass, because each of them belongs to a single block height.

OptionTypeDefaultDescription
incomingActivityWindowobjectnot setWindow that the incoming edges of a Script must satisfy.
outgoingActivityWindowobjectnot setWindow that the outgoing edges of a Script must satisfy.
totalActivityWindowobjectnot setWindow that all edges of a Script, incoming and outgoing together, must satisfy.
activityScanLimitint50000Maximum number of edges of a Script that Panorama reads to check the windows.

You may set any of the three windows, or several of them. When you set more than one window, a Script must satisfy every window that you set. When you set no window, Panorama does not check the activity of Scripts.

Example:

"PanoramaOptions": {
"maxHops": 2,
"queryLimit": 100000,
"nodeCountAtRoot": 100,
"reductionFactor": 4,
"totalActivityWindow": {
"minHeight": 700000,
"maxHeight": 750000,
"minPercentage": 80,
"minActivityCount": 5
},
"activityScanLimit": 50000
}

With these options, Panorama includes a Script only if the Script has at least 5 edges, and at least 80 percent of those edges are active between block heights 700000 and 750000.

Window fields​

Each of the three windows is an object with the following fields.

FieldTypeDefaultDescription
minHeightint0Lowest block height of the window. The window includes this height.
maxHeightint2147483647Highest block height of the window. The window includes this height.
minPercentagedouble0Minimum percentage, from 0 to 100, of the Script's edges that must be active inside the window.
minActivityCountint1Minimum number of edges that the Script must have in the direction that the window checks.

Panorama counts minActivityCount over the whole history of the Script, not only inside the window. This field protects minPercentage from Scripts with very few edges. For example, with minPercentage set to 50, a Script with only 2 edges passes when 1 of them is inside the window. If you set minActivityCount to 3, that Script no longer passes.

A Script that has no edge in the direction that the window checks never satisfies the window. So with the default minPercentage of 0, a window still removes Scripts that have no activity in that direction.

incomingActivityWindow​

Panorama checks this window against the incoming edges (Credits) of a Script, and uses the CreationHeight of each edge. Use it to sample Scripts that received most of their funds in the given period.

outgoingActivityWindow​

Panorama checks this window against the outgoing edges (Redeems) of a Script, and uses the SpentHeight of each edge. Use it to sample Scripts that spent most of their funds in the given period.

totalActivityWindow​

Panorama checks this window against all edges of a Script, incoming and outgoing together. Use it to sample Scripts that were mostly active in the given period, whatever the direction of the activity.

activityScanLimit​

Some Scripts, such as the addresses of exchanges, have millions of edges. Reading all of these edges would take minutes for each Script, so Panorama reads at most activityScanLimit edges of a Script to check the windows.

  • When a Script has at most activityScanLimit edges, Panorama reads all of them, so the check is exact.
  • When a Script has more edges, Panorama computes the percentage over the edges that it read. The result is then an estimate. The database usually returns the most recently added edges first, but it does not promise this order.
  • Panorama always checks minActivityCount against the exact number of edges of the Script, because the database stores that number and does not need to read the edges.

Raise this limit when you need exact results for large Scripts, and accept that sampling becomes slower. The value must be a positive integer.

How the windows change the sampling​

Panorama checks the windows at two points of the walk.

  • At the root node. If the root node is a Script that does not satisfy the windows, Panorama stops this sample and starts again from another root node.
  • At each hop. Panorama shuffles the neighbors of a node as usual. It then goes through the shuffled neighbors and keeps the first ones that satisfy the windows, until it reaches the number of neighbors that the hop allows. This gives the same result as removing every Script that fails the windows and then picking neighbors at random, but it only checks the Scripts that it looks at.

Panorama remembers the result of each check while it builds one sample, so it checks each Script at most once per sample.

The windows filter the candidates that queryLimit returns. They do not change which neighbors the database returns. So, if you set a narrow window, a node may have few neighbors that pass. In that case, raise queryLimit so that Panorama has more candidates to choose from.

At the end of each sample, Panorama logs how many Scripts it checked, how many of them failed the windows, and how many it judged on only part of their edges.