elements
elements copied to clipboard
Long unconfirmed transaction chain doesn't get mined in regtest
Steps to reproduce (with 0.21.0.1):
elementsd -chain=elementsregtest -initialfreecoins=2100000000000000 -anyonecanspendaremine=1 -validatepegin=0 -datadir=/tmp/elements-test
alias cli='elements-cli -chain=elementsregtest -datadir=/tmp/elements-test'
cli createwallet default
cli rescanblockchain # pick up anyonecanspend
addr=$(cli getnewaddress)
for i in {1..26}; do cli sendtoaddress $addr 1; done
# the 26th transaction results in the following log message:
# [default] CommitTransaction(): Transaction cannot be broadcast immediately, too-long-mempool-chain, too many unconfirmed ancestors [limit: 25]
# (but `sendtoaddress` still replies successfully with its txid)
cli getmempoolinfo | jq .size
# prints 25 (the 26th transaction was ignored)
cli generatetoaddress 1 $addr
cli getmempoolinfo | jq .size
# still prints 25 -- all the transactions seem to be stuck in the mempool and don't get selected into mined blocks
#206 reported a similar issue (but possibly due to a different cause?).
I ran some more testing and it appears that a chain of 7 transactions is sufficient to trigger this behavior:
# Works as expected with a chain of 6 transactions
$ for i in {1..6}; do cli sendtoaddress $addr 1; done > /dev/null && echo mempool entries: $(cli getmempoolinfo | jq .size) && cli generatetoaddress 1 $addr && echo mempool entries: $(cli getmempoolinfo | jq .size)
mempool entries: 6
[
"46f4e4b84e7e2e1a1057a16750721ab7710e71c23df37c92a6ca594184e676dc"
]
mempool entries: 0
# Breaks with 7 transactions, the mempool doesn't clear
$ for i in {1..7}; do cli sendtoaddress $addr 1; done > /dev/null && echo mempool entries: $(cli getmempoolinfo | jq .size) && cli generatetoaddress 1 $addr && echo mempool entries: $(cli getmempoolinfo | jq .size)
mempool entries: 7
[
"fe086ec23bf1b6d81dbbe8e04936c2c04b1f836c7e30e314408a2512ca378d19"
]
mempool entries: 7
Note that you need to reset the regtest chain between the tests. Initially there's only one coin (the initialfreecoin
) which ensures that every transaction chains off the previous one, but after some transactions are sent successfully there will be more coins that can interfere with the test.