Defer the GUI coin control instancing so that argument processing is taken into account for the default coin control values.
Fixes #12312
Note to reviewers, I would like to refactor the code, specially to remove these (or some) static values, but I though maybe we should fix the problem first.
utACK https://github.com/bitcoin/bitcoin/pull/12327/commits/b3e74d626e6c2109492f490a4c8271b4b0bd52c2
This should fix both g_change_type; and signalRbf being set at instance time to variables not yet set globally. Other settings are set per-usage of CCoinControl or are simply not used when not explicitly set, such as m_feerate.
Note to reviewers, I would like to refactor the code, specially to remove there (or some) static values,
Yes, we should get rid of the global coincontrol object and just pass it around and store it where necessary. But indeed, not a priority for fixing this.
598 | @@ -600,6 +599,13 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) 599 | label->setVisible(nChange < 0); 600 | } 601 | 602 | +CCoinControl* CoinControlDialog::coinControl() 603 | +{ 604 | + static CCoinControl* coin_control = nullptr; 605 | + if (!coin_control) coin_control = new CCoinControl();
I think we leak this pointer?
If you'd make this a smart pointer, it'd get freed at shutdown at least.
It was leaking already.
But wouldn't that be a one-line change, to use static unique_ptr<CCoinControl> coin_control;? Or am I missing something?
Do a Meyer's singleton
CCoinControl& CoinControlDialog::coinControl() { static CCoinControl coin_control; return coin_control; }
No pointers, no leaks.
In that case when is coin_control instanced? I think the problem remains, but please correct me if I'm wrong.
Thanks!
I think @kekimusmaximus's solution also works, static within a function is initialized on first use.
That's new to me, I'll change to that instead.
377 | @@ -379,11 +378,11 @@ void CoinControlDialog::viewItemChanged(QTreeWidgetItem* item, int column) 378 | COutPoint outpt(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt()); 379 | 380 | if (item->checkState(COLUMN_CHECKBOX) == Qt::Unchecked) 381 | - coinControl->UnSelect(outpt); 382 | + CoinControlDialog::coinControl()->UnSelect(outpt);
No need to prefix with CoinControlDialog:: here, this is still in the class.
I know, but this way it's clear it's a static member.
Let's not do that, we intend to make it non-static field later anyway, so this seems moving the wrong direction.
I think ideally we'd instantiate the CCoinControl at a defined time during the GUI initialization process (when we're sure the options have been parsed), instead at first use. But this works I guess...
utACK 29e7f9f7a2afa6836fbbe7371000805dfb8ec638 , please squash.
Defer the GUI coin control instancing so that argument processing
is taken into account for the default coin control values.
Done @jonasschnelli @MeshCollider.
Tested 6558f8a. Enabling coin control now honors -changetype for me, and also uses a native segwit change address when sending to a bech32 address.
Milestone
0.16.0