-
Notifications
You must be signed in to change notification settings - Fork 144
universe: add cursor-based delta sync to federation #2202
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
Open
jtobin
wants to merge
7
commits into
lightninglabs:main
Choose a base branch
from
jtobin:recursive-sync
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c3d5e20
tapdb+universe: add insertion-ordered universe leaf delta read path
jtobin 3a661a7
taprpc+rpcserver+universe: add SyncDelta RPC and delta engines
jtobin 3c73c69
tapdb+universe: add per-server delta sync cursor storage
jtobin 4c6c869
universe: implement cursor-based delta sync on SimpleSyncer
jtobin 26f7838
universe+tapcfg: wire delta sync into the federation envoy
jtobin 016a3fc
bench: add sync discovery benchmarks
jtobin 495de3f
docs: add release note
jtobin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| package fixture | ||
|
|
||
| import ( | ||
| "context" | ||
| "sync/atomic" | ||
| "testing" | ||
|
|
||
| "github.com/lightninglabs/taproot-assets/universe" | ||
| ) | ||
|
|
||
| const ( | ||
| // approxRootWireBytes approximates the wire size of one enumerated | ||
| // universe root: 32-byte asset ID (or group key hash), 1-byte proof | ||
| // type, 32-byte node hash, 8-byte sum. | ||
| approxRootWireBytes = 73 | ||
|
|
||
| // approxLeafKeyWireBytes approximates the wire size of one | ||
| // enumerated leaf key: 36-byte outpoint plus 33-byte script key. | ||
| approxLeafKeyWireBytes = 69 | ||
| ) | ||
|
|
||
| // DiscoveryMetrics counts the remote DiffEngine traffic generated by a | ||
| // sync run, split by discovery phase. The fixture is in-process, but in | ||
| // production every DiffEngine call is an RPC round trip (or one page | ||
| // thereof), so the call counters approximate round trips and the byte | ||
| // counters approximate wire bytes. | ||
| type DiscoveryMetrics struct { | ||
| // RootPages counts RootNodes calls (one per enumeration page). | ||
| RootPages atomic.Int64 | ||
|
|
||
| // RootsEnumerated counts roots returned across all RootNodes pages. | ||
| RootsEnumerated atomic.Int64 | ||
|
|
||
| // RootLookups counts RootNode point lookups. | ||
| RootLookups atomic.Int64 | ||
|
|
||
| // LeafKeyPages counts UniverseLeafKeys calls (one per page). | ||
| LeafKeyPages atomic.Int64 | ||
|
|
||
| // LeafKeysEnumerated counts leaf keys returned across all pages. | ||
| LeafKeysEnumerated atomic.Int64 | ||
|
|
||
| // ProofFetches counts FetchProofLeaf calls. | ||
| ProofFetches atomic.Int64 | ||
|
|
||
| // ProofBytes sums the raw proof blob sizes returned by | ||
| // FetchProofLeaf and by delta pages. A lower bound on proof wire | ||
| // bytes (inclusion proof overhead is excluded). | ||
| ProofBytes atomic.Int64 | ||
|
|
||
| // DeltaPages counts SyncDelta calls (one per page round trip). | ||
| DeltaPages atomic.Int64 | ||
|
|
||
| // DeltaItems counts leaves returned across all delta pages. | ||
| DeltaItems atomic.Int64 | ||
| } | ||
|
|
||
| // Report emits the counters, the derived per-phase byte estimates, and | ||
| // the discovery share of total bytes via b.ReportMetric. | ||
| func (m *DiscoveryMetrics) Report(b *testing.B) { | ||
| b.Helper() | ||
|
|
||
| rootBytes := m.RootsEnumerated.Load() * approxRootWireBytes | ||
| keyBytes := m.LeafKeysEnumerated.Load() * approxLeafKeyWireBytes | ||
| proofBytes := m.ProofBytes.Load() | ||
|
|
||
| discoveryBytes := rootBytes + keyBytes | ||
| share := float64(0) | ||
| if total := discoveryBytes + proofBytes; total > 0 { | ||
| share = float64(discoveryBytes) / float64(total) | ||
| } | ||
|
|
||
| b.ReportMetric(float64(m.RootPages.Load()), "root_pages") | ||
| b.ReportMetric(float64(m.RootsEnumerated.Load()), "roots_enum") | ||
| b.ReportMetric(float64(m.RootLookups.Load()), "root_lookups") | ||
| b.ReportMetric(float64(m.LeafKeyPages.Load()), "leafkey_pages") | ||
| b.ReportMetric(float64(m.LeafKeysEnumerated.Load()), "leafkeys_enum") | ||
| b.ReportMetric(float64(m.ProofFetches.Load()), "proof_fetches") | ||
| b.ReportMetric(float64(m.DeltaPages.Load()), "delta_pages") | ||
| b.ReportMetric(float64(m.DeltaItems.Load()), "delta_items") | ||
| b.ReportMetric(float64(rootBytes), "root_bytes") | ||
| b.ReportMetric(float64(keyBytes), "leafkey_bytes") | ||
| b.ReportMetric(float64(proofBytes), "proof_bytes") | ||
| b.ReportMetric(share, "discovery_share") | ||
| } | ||
|
|
||
| // countingDiffEngine wraps a universe.DiffEngine and tallies each call | ||
| // into a DiscoveryMetrics. It is installed around the fixture's remote | ||
| // archive so only remote-side (would-be wire) traffic is counted; the | ||
| // syncer's local enumeration is a DB scan, not a round trip. | ||
| type countingDiffEngine struct { | ||
| inner universe.DiffEngine | ||
| metrics *DiscoveryMetrics | ||
| } | ||
|
|
||
| var _ universe.DiffEngine = (*countingDiffEngine)(nil) | ||
|
|
||
| // RootNode delegates to the wrapped engine, counting the lookup. | ||
| // | ||
| // NOTE: part of the universe.DiffEngine interface. | ||
| func (c *countingDiffEngine) RootNode(ctx context.Context, | ||
| id universe.Identifier) (universe.Root, error) { | ||
|
|
||
| c.metrics.RootLookups.Add(1) | ||
| return c.inner.RootNode(ctx, id) | ||
| } | ||
|
|
||
| // RootNodes delegates to the wrapped engine, tallying the page and the | ||
| // roots it enumerates. | ||
| // | ||
| // NOTE: part of the universe.DiffEngine interface. | ||
| func (c *countingDiffEngine) RootNodes(ctx context.Context, | ||
| q universe.RootNodesQuery) ([]universe.Root, error) { | ||
|
|
||
| roots, err := c.inner.RootNodes(ctx, q) | ||
| c.metrics.RootPages.Add(1) | ||
| c.metrics.RootsEnumerated.Add(int64(len(roots))) | ||
| return roots, err | ||
| } | ||
|
|
||
| // UniverseLeafKeys delegates to the wrapped engine, tallying the page | ||
| // and the leaf entries it enumerates. | ||
| // | ||
| // NOTE: part of the universe.DiffEngine interface. | ||
| func (c *countingDiffEngine) UniverseLeafKeys(ctx context.Context, | ||
| q universe.UniverseLeafKeysQuery) ([]universe.LeafEntry, error) { | ||
|
|
||
| keys, err := c.inner.UniverseLeafKeys(ctx, q) | ||
| c.metrics.LeafKeyPages.Add(1) | ||
| c.metrics.LeafKeysEnumerated.Add(int64(len(keys))) | ||
| return keys, err | ||
| } | ||
|
|
||
| // FetchProofLeaf delegates to the wrapped engine, counting the fetch | ||
| // and the proof bytes it returns. | ||
| // | ||
| // NOTE: part of the universe.DiffEngine interface. | ||
| func (c *countingDiffEngine) FetchProofLeaf(ctx context.Context, | ||
| id universe.Identifier, | ||
| key universe.LeafKey) ([]*universe.Proof, error) { | ||
|
|
||
| proofs, err := c.inner.FetchProofLeaf(ctx, id, key) | ||
| c.metrics.ProofFetches.Add(1) | ||
| for _, p := range proofs { | ||
| if p.Leaf != nil { | ||
| c.metrics.ProofBytes.Add(int64(len(p.Leaf.RawProof))) | ||
| } | ||
| } | ||
| return proofs, err | ||
| } | ||
|
|
||
| // SyncDelta delegates to the wrapped engine's delta implementation, | ||
| // tallying pages, items, and payload bytes. | ||
| // | ||
| // NOTE: part of the universe.DeltaEngine interface. | ||
| func (c *countingDiffEngine) SyncDelta(ctx context.Context, | ||
| sinceSeq uint64, pageSize int32) (*universe.DeltaPage, error) { | ||
|
|
||
| deltaEngine, ok := c.inner.(universe.DeltaEngine) | ||
| if !ok { | ||
| return nil, universe.ErrDeltaUnsupported | ||
| } | ||
|
|
||
| page, err := deltaEngine.SyncDelta(ctx, sinceSeq, pageSize) | ||
| c.metrics.DeltaPages.Add(1) | ||
| if page != nil { | ||
| c.metrics.DeltaItems.Add(int64(len(page.Items))) | ||
| for _, item := range page.Items { | ||
| if item.Leaf != nil { | ||
| c.metrics.ProofBytes.Add( | ||
| int64(len(item.Leaf.RawProof)), | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| return page, err | ||
| } | ||
|
|
||
| // Close closes the wrapped engine. | ||
| // | ||
| // NOTE: part of the universe.DiffEngine interface. | ||
| func (c *countingDiffEngine) Close() error { | ||
| return c.inner.Close() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.