Closed Naviabheeman closed 11 months ago
This was a false alarm. The reason for the duplicate entries in trace logs looks like multiple levels of caching.
These logs were collected with additional debugging for this
and base
pointers in CCoinsViewCache
. It can be seen that the pointers are different. i.e. one entry is added to two different caches. There is one level of cache in memory and the base cache with mempool and leveldb interface. I'll confirm this.
debug.log
2023-11-30T15:26:06.708398Z CreateNewBlock(): block size: 202 txs: 0 fees: 0 sigops 100
2023-11-30T15:26:06.708457Z - Sanity checks: 0.01ms [0.00s (0.01ms/blk)]
2023-11-30T15:26:06.708471Z - Fork checks: 0.02ms [0.00s (0.02ms/blk)]
2023-11-30T15:26:06.708486Z [0x7f89b9ff99a0 - 0x564190031610] FetchCoin [98e7dbf08131787013fd91344aad772922462c03f55bde21c5adcc0f6e9196b7-0]
2023-11-30T15:26:06.708497Z [0x564190031610 - 0x56419001bac0] FetchCoin [98e7dbf08131787013fd91344aad772922462c03f55bde21c5adcc0f6e9196b7-0]
2023-11-30T15:26:06.708527Z [0x7f89b9ff99a0 - 0x564190031610] AddCoin utxocache_add [98e7dbf08131787013fd91344aad772922462c03f55bde21c5adcc0f6e9196b7-0] fresh: [1] flags [3] inserted [1] possible_overwrite[0] cachedCoinsUsage[64]
2023-11-30T15:26:06.708700Z - Connect 1 transactions: 0.22ms (0.223ms/tx, 0.000ms/txin) [0.00s (0.22ms/blk)]
2023-11-30T15:26:06.708729Z - Verify 0 txins: 0.26ms (0.000ms/txin) [0.00s (0.26ms/blk)]
2023-11-30T15:26:06.708744Z CreateNewBlock() packages: 0.01ms (0 packages, 0 updated descendants), validity: 0.35ms (total 0.36ms)
2023-11-30T15:26:06.709527Z - Load block from disk: 0.00ms [0.00s]
2023-11-30T15:26:06.709580Z - Sanity checks: 0.01ms [0.00s (0.01ms/blk)]
2023-11-30T15:26:06.709594Z - Fork checks: 0.02ms [0.00s (0.02ms/blk)]
2023-11-30T15:26:06.709609Z [0x7f89b9ff9830 - 0x564190031610] FetchCoin [98e7dbf08131787013fd91344aad772922462c03f55bde21c5adcc0f6e9196b7-0]
2023-11-30T15:26:06.709619Z [0x564190031610 - 0x56419001bac0] FetchCoin [98e7dbf08131787013fd91344aad772922462c03f55bde21c5adcc0f6e9196b7-0]
2023-11-30T15:26:06.709643Z [0x7f89b9ff9830 - 0x564190031610] AddCoin utxocache_add [98e7dbf08131787013fd91344aad772922462c03f55bde21c5adcc0f6e9196b7-0] fresh: [1] flags [3] inserted [1] possible_overwrite[0] cachedCoinsUsage[64]
trace log
# contrib/tracing/log_utxos.bt
Attaching 4 probes...
OP Outpoint Token Value Height Coinbase
Spent :eb1a46fcddd76911fef927947b61c04f5a4dd9aeb8e24a58cf439d34f246c6f 0 TPC 5000000000 100 Yes
Spent :5f2140dedbe800ae75b5a6045c3882d3d098179ac5627da2d21578f6bdaa131 0 TPC 5000000000 99 Yes
Spent :8721da6706af76c8602dc4be9ac7e6e4d3a77d193c6fd299ca172834f6f97c0 0 TPC 5000000000 98 Yes
Spent :4969251b7a14e9ec7b316ee754443a4941b286e0064c5a168cd96302cb79604 0 TPC 5000000000 97 Yes
Spent :de987dc7ebe9098a952455f62e841250512b20ec642ebcb4ad046775e1107c1 0 TPC 5000000000 96 Yes
Spent :55bf9031729c922e94c3534568c918f17709d0f0a124e7f6b15b69e549714d8 0 TPC 5000000000 95 Yes
Added :98e7dbf08131787013fd91344aad772922462c03f55bde21c5adcc0f6e9196b 0 TPC 5000000000 101 Yes
Added :98e7dbf08131787013fd91344aad772922462c03f55bde21c5adcc0f6e9196b 0 TPC 5000000000 101 Yes
Bitcoin trace must be filtering out the mempool cache entries. I'll confirm this.
I confirmed that Bitcoin generates similar add events too. Its not a bug in tapyrus.
Bitcoin:
# bpftrace contrib/tracing/log_utxos.bt
Attaching 4 probes...
OP Outpoint Value Height Coinbase
Spent 18191a1b1c1d1e1f202122232425262728292a2b:0 2500000000 199 Yes
Spent 18191a1b1c1d1e1f202122232425262728292a2b:0 2500000000 198 Yes
Spent 18191a1b1c1d1e1f202122232425262728292a2b:0 2500000000 197 Yes
Spent 18191a1b1c1d1e1f202122232425262728292a2b:0 2500000000 196 Yes
Spent 18191a1b1c1d1e1f202122232425262728292a2b:0 2500000000 195 Yes
Spent 18191a1b1c1d1e1f202122232425262728292a2b:0 2500000000 194 Yes
Added 02030405060708090a0b0c0d0e0fbc1112131415:0 2500000000 200 Yes
Added 02030405060708090a0b0c0d0e0fbc1112131415:0 2500000000 200 Yes
Spent 18191a1b1c1d1e1f202122232425262728292a2b:0 2500000000 200 Yes
Spent 18191a1b1c1d1e1f202122232425262728292a2b:0 2500000000 199 Yes
Spent 18191a1b1c1d1e1f202122232425262728292a2b:0 5000000000 99 Yes
(Transaction id in these events is not accurate. bitcoin log_utxos.bt script does not succeed due to errors in the transaction id unroll. So it was edited to generate these outputs. The number of events generated is the same)
The same test case in tapyrus generates:
Tapyrus:
Spent :eb1a46fcddd76911fef927947b61c04f5a4dd9aeb8e24a58cf439d34f246c6f 0 TPC 5000000000 100 Yes
Spent :5f2140dedbe800ae75b5a6045c3882d3d098179ac5627da2d21578f6bdaa131 0 TPC 5000000000 99 Yes
Spent :8721da6706af76c8602dc4be9ac7e6e4d3a77d193c6fd299ca172834f6f97c0 0 TPC 5000000000 98 Yes
Spent :4969251b7a14e9ec7b316ee754443a4941b286e0064c5a168cd96302cb79604 0 TPC 5000000000 97 Yes
Spent :de987dc7ebe9098a952455f62e841250512b20ec642ebcb4ad046775e1107c1 0 TPC 5000000000 96 Yes
Spent :55bf9031729c922e94c3534568c918f17709d0f0a124e7f6b15b69e549714d8 0 TPC 5000000000 95 Yes
Added :73776da2bcc8b5be584ad162e011562253d3f6643f2f0bfaf2d06ed33a0e47f 0 TPC 5001000000 101 Yes
Spent :9c51c4798826f13bc24230b912e7bd626f58946ad77fbeba0795365122c8af0 0 TPC 5000000000 1 Yes
Added :a5feded9562eaf7c27029c04f88d4c19abd79567a520527a22ad24be96fc105 0 TPC 4999000000 101 Yes
Added :73776da2bcc8b5be584ad162e011562253d3f6643f2f0bfaf2d06ed33a0e47f 0 TPC 5001000000 101 Yes
Spent :9c51c4798826f13bc24230b912e7bd626f58946ad77fbeba0795365122c8af0 0 TPC 5000000000 1 Yes
Added :a5feded9562eaf7c27029c04f88d4c19abd79567a520527a22ad24be96fc105 0 TPC 4999000000 101 Yes
Utxo cache tracepoint execution shows add events duplicated. All new utxos seem to be added twice. When we compare the expected number of entries in the cache between tapyrus and bitcoin, our cache entries are very high. This could be a bug in tapyrus coin cache. It might have been fixed in bitcoin. We need to investigate this thoroughly.
logs from
python bcc
script:logs from
bpftrace
scriptsIn both these logs the same utxo is logged twice.