lightninglabs / taproot-assets

A layer 1 daemon, for the Taproot Assets Protocol specification, written in Go (golang)
MIT License
439 stars 106 forks source link

[bug]: unable to import proofs: postgres throws deadlock error #961

Closed gijswijs closed 6 days ago

gijswijs commented 1 week ago

Background

When running the itest make flakehunter dbbackend=postgres icase=multi_address the test sometimes runs into a deadlock when importing proofs. Not always tho. This is a a test where we send to multiple addresses (from the same receiver) at once, so it does require tapd to import multiple proofs at once.

Steps to reproduce

run make flakehunter dbbackend=postgres icase=multi_address

Expected behavior

No deadlock. Multiple proofs should be imported gracefully.

Actual behavior

Failure

2024-06-20 15:33:54.477 [TRC] GRDN: New proof received from notifier
2024-06-20 15:33:54.477 [INF] GRDN: Received new proof file for asset ID 406077e30da19be2ad66f285235425858d587078bf6e115fc560d03bb12bb054, version=0,num_proofs=3
2024-06-20 15:33:55.170 [ERR] GRDN: Unable to receive proof: unable to import proofs script_key=02e6ec5981616fff475b78a7157bd61ebe40283e758d35c0469f200f4e641d7efe, asset_id=406077e30da19be2ad66f285235425858d587078bf6e115fc560d03bb12bb054: unable to import proofs: unknown postgres error: ERROR: deadlock detected (SQLSTATE 40P01)
2024-06-20 15:33:55.172 [TRC] GRDN: New proof received from notifier
2024-06-20 15:33:55.172 [TRC] TADB: Retrying transaction due to tx serialization error, attempt_number=0, delay=57.288516ms
2024-06-20 15:33:55.172 [INF] GRDN: Received new proof file for asset ID 406077e30da19be2ad66f285235425858d587078bf6e115fc560d03bb12bb054, version=0,num_proofs=3
2024-06-20 15:33:55.172 [TRC] GRDN: New proof received from notifier
2024-06-20 15:33:55.173 [INF] GRDN: Received new proof file for asset ID 406077e30da19be2ad66f285235425858d587078bf6e115fc560d03bb12bb054, version=0,num_proofs=3
2024-06-20 15:33:55.173 [INF] GRDN: Watching new proof anchor TX 43557ca77411f0608485dc8e6cc2bad08bd818ed522d4e63b182e671e0bdef3a for 1 assets until it reaches 6 confirmations
2024-06-20 15:33:55.174 [INF] GRDN: Watching new proof anchor TX 834a33dd4226b11eeb7f920b97e16804cdfd0bd0bc4bc1effbd5588edc406ee3 for 1 assets until it reaches 6 confirmations
2024-06-20 15:33:55.174 [INF] GRDN: Watching new proof anchor TX 4ac8537ffa7135718969a12e5e65e2ae8a6f4cdd80087e4f33f54c440e2881df for 1 assets until it reaches 6 confirmations
2024-06-20 15:33:55.179 [TRC] GRDN: New proof received from notifier
2024-06-20 15:33:55.180 [INF] GRDN: Received new proof file for asset ID 406077e30da19be2ad66f285235425858d587078bf6e115fc560d03bb12bb054, version=0,num_proofs=3
2024-06-20 15:33:55.180 [INF] GRDN: Watching new proof anchor TX 43557ca77411f0608485dc8e6cc2bad08bd818ed522d4e63b182e671e0bdef3a for 1 assets until it reaches 6 confirmations
2024-06-20 15:33:55.181 [INF] GRDN: Watching new proof anchor TX 834a33dd4226b11eeb7f920b97e16804cdfd0bd0bc4bc1effbd5588edc406ee3 for 1 assets until it reaches 6 confirmations
2024-06-20 15:33:55.181 [INF] GRDN: Watching new proof anchor TX 4ac8537ffa7135718969a12e5e65e2ae8a6f4cdd80087e4f33f54c440e2881df for 1 assets until it reaches 6 confirmations
2024-06-20 15:33:55.186 [TRC] GRDN: New proof received from notifier
2024-06-20 15:33:55.186 [INF] GRDN: Received new proof file for asset ID 3e27358127bf0dde33bcc3b83ea8faecb6898c0c50be0a36cf01721091507f49, version=0,num_proofs=3
2024-06-20 15:33:55.243 [TRC] PROF: Importing proof file /tmp/itest-tapd554786784/data/regtest/proofs/406077e30da19be2ad66f285235425858d587078bf6e115fc560d03bb12bb054/02e861ebfc2d212ece01dfe4457a67d8ef08ce7487a9efa7f42adce7b5c2fa7778-43557ca77411f0608485dc8e6cc2bad0-4.assetproof (replace=false)
2024-06-20 15:33:55.243 [TRC] GRDN: New proof received from notifier
2024-06-20 15:33:55.243 [INF] GRDN: Received new proof file for asset ID 406077e30da19be2ad66f285235425858d587078bf6e115fc560d03bb12bb054, version=0,num_proofs=3
2024-06-20 15:33:55.243 [TRC] GRDN: New proof received from notifier
2024-06-20 15:33:55.244 [INF] GRDN: Received new proof file for asset ID 406077e30da19be2ad66f285235425858d587078bf6e115fc560d03bb12bb054, version=0,num_proofs=3
    assertions.go:832: 
                Error Trace:    /home/gijs/git/taproot-assets/itest/assertions.go:832
                                                        /home/gijs/git/taproot-assets/itest/addrs_test.go:613
                                                        /home/gijs/git/taproot-assets/itest/addrs_test.go:275
                                                        /home/gijs/git/taproot-assets/itest/test_harness.go:159
                                                        /home/gijs/git/taproot-assets/itest/integration_test.go:94
                Error:          Received unexpected error:
                                method did not return within the timeout
                Test:           TestTaprootAssetsDaemon/multi_address

0--Alice-028870de.log 1--Bob-03926004.log

gijswijs commented 6 days ago

Fixed with #954