Commit 4a29640
committed
feat(tbc): store tx byte location in tx index, bump DB to v6
Store TxLoc (offset + length within raw block) in the t entry value
instead of nil. This allows callers to jump directly to a tx's bytes
in the raw block without scanning — O(1) instead of O(txs_in_block).
BlockHashByTxId now returns (*chainhash.Hash, wire.TxLoc, error).
All callers updated. No separate method needed — callers that only
need the hash use bh, _, err := BlockHashByTxId(...).
processTxs calls block.TxLoc() and stores the location via
NewTxMappingWithLoc. Errors from TxLoc() are logged at Errorf
and the indexer falls back to nil values (legacy format).
BlockTxUpdate uses stack-allocated reusable buffers instead of
slicing loop variables. The previous code sliced the range variable
and passed the slice to leveldb.Batch.Put. appendRec copies
immediately, but the interaction between range variable reuse,
map deletion, and GC is not guaranteed safe. Stack buffers are
zero-alloc and independent per iteration.
DB version 5 -> 6. Upgrade path wipes the transactions index for
rebuild with TxLoc values. The index is fully derived from block data.
Ref: #10501 parent 99d768f commit 4a29640
12 files changed
Lines changed: 510 additions & 56 deletions
File tree
- cmd/hemictl
- database/tbcd
- level
- service/tbc
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| |||
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
| |||
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
63 | 73 | | |
64 | 74 | | |
65 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
619 | 619 | | |
620 | 620 | | |
621 | 621 | | |
622 | | - | |
| 622 | + | |
623 | 623 | | |
624 | 624 | | |
625 | 625 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| |||
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
484 | 498 | | |
485 | 499 | | |
486 | 500 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
312 | 312 | | |
313 | 313 | | |
314 | 314 | | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
315 | 319 | | |
316 | 320 | | |
317 | 321 | | |
| |||
1642 | 1646 | | |
1643 | 1647 | | |
1644 | 1648 | | |
1645 | | - | |
| 1649 | + | |
1646 | 1650 | | |
1647 | 1651 | | |
1648 | 1652 | | |
1649 | | - | |
1650 | 1653 | | |
1651 | | - | |
1652 | | - | |
1653 | | - | |
1654 | | - | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
1655 | 1658 | | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
1656 | 1663 | | |
1657 | | - | |
1658 | | - | |
1659 | | - | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
1660 | 1671 | | |
1661 | | - | |
| 1672 | + | |
1662 | 1673 | | |
1663 | 1674 | | |
1664 | | - | |
| 1675 | + | |
1665 | 1676 | | |
1666 | | - | |
1667 | | - | |
1668 | | - | |
1669 | | - | |
1670 | | - | |
1671 | | - | |
1672 | | - | |
1673 | | - | |
| 1677 | + | |
| 1678 | + | |
1674 | 1679 | | |
| 1680 | + | |
1675 | 1681 | | |
1676 | 1682 | | |
1677 | 1683 | | |
| |||
1917 | 1923 | | |
1918 | 1924 | | |
1919 | 1925 | | |
1920 | | - | |
1921 | | - | |
1922 | 1926 | | |
1923 | 1927 | | |
1924 | 1928 | | |
1925 | 1929 | | |
1926 | 1930 | | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
1927 | 1935 | | |
1928 | | - | |
1929 | 1936 | | |
1930 | 1937 | | |
1931 | 1938 | | |
1932 | | - | |
1933 | | - | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
1934 | 1945 | | |
1935 | 1946 | | |
1936 | 1947 | | |
1937 | 1948 | | |
1938 | | - | |
1939 | | - | |
| 1949 | + | |
| 1950 | + | |
1940 | 1951 | | |
1941 | 1952 | | |
1942 | 1953 | | |
1943 | 1954 | | |
1944 | | - | |
1945 | | - | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
1946 | 1959 | | |
1947 | 1960 | | |
1948 | 1961 | | |
| |||
0 commit comments