rpc: Do not accept command while executing another one #123

pull hebasto wants to merge 4 commits into bitcoin-core:master from hebasto:201028-prompt changing 3 files +64 −43
  1. hebasto commented at 7:43 pm on October 28, 2020: member

    On master (3f512f3d563954547061ee743648b57a900cbe04) it is possible to enter another command while the current command is still being executed. That makes a mess in the output.

    With this PR: Screenshot from 2020-10-29 20-48-55

    Some previous context: #59 (comment)


    It is still possible to enter and execute the stop command any time.

  2. jonasschnelli commented at 10:34 am on October 29, 2020: contributor

    Tested ACK 0b8b65392a590dc0ac04818b4933676e3f2c5a7c - works as intended.

    A follow up would be to add a cancel/abort button. Especially for things like “waitforblock 99999999” (would even be useful for gettxoutsetinfo).

  3. hebasto commented at 10:56 am on October 29, 2020: member

    A follow up would be to add a cancel/abort button. Especially for things like “waitforblock 99999999” (would even be useful for gettxoutsetinfo).

    Combine cancel/abort functionality into already present Clear button?

  4. in src/qt/rpcconsole.cpp:892 in 0b8b65392a outdated
    887@@ -890,8 +888,10 @@ void RPCConsole::on_lineEdit_returnPressed()
    888 {
    889     QString cmd = ui->lineEdit->text();
    890 
    891-    if(!cmd.isEmpty())
    892-    {
    893+    if (!cmd.isEmpty()) {
    894+        ui->lineEdit->setEnabled(false);
    


    promag commented at 11:54 am on October 29, 2020:
    I think it’s nice to be able to write the next command.

    jonasschnelli commented at 12:22 pm on October 29, 2020:
    Good point. What about allowing input but disallow executing (enter won’t clear the line, etc.). The executing... text would need to be somewhere else though…

    promag commented at 12:32 pm on October 29, 2020:
    @jonasschnelli and this #123#pullrequestreview-519587704?

    hebasto commented at 6:57 pm on October 29, 2020:
    Updated.
  5. promag commented at 11:55 am on October 29, 2020: contributor
    One way to abort running command is to run quitstop. With this change this is not possible.
  6. hebasto commented at 2:33 pm on October 29, 2020: member

    One way to abort running command is to run quit.

    When did the quit command become a thing in the GUI console? Or is it a suggestion?

  7. promag commented at 3:00 pm on October 29, 2020: contributor
    I just mean it won’t work anymore. I happen to use it, but can quit from the GUI.
  8. hebasto commented at 3:03 pm on October 29, 2020: member

    I just mean it won’t work anymore.

    I’m going to address your concerns.

    I happen to use it, but can quit from the GUI.

    I cannot find the quit command now.

  9. promag commented at 3:20 pm on October 29, 2020: contributor
    s/quit/stop 🤦 updated above.
  10. jonasschnelli commented at 6:16 pm on October 29, 2020: contributor

    @promag

    One way to abort running command is to run stop. With this change this is not possible.

    This would shutdown bitcoin-qt. Right? I don’t think this is an adequate action for stopping a single RPC call. It’s already possible with Ctrl-Q.

    Why not just emulate the shell (bitcoin-cli usage) as good as possible?

    • No parallel commands are possible in a single shell window
    • Ctrl-C abort the call
    • Clear visual sign that something is “working..” (no prompt visible)
    • Allow entering a next command (but impossible to execute before old has been finished)

    This would translate that into our Qt world with:

    • Once a command has been started, forbid executing a new one until the old has “returned” (done in this PR)
    • Have a specific “abort” button or support something like Ctrl-C if it looks silly (should be added)
      • If the “abort” button looks bad (quick show/hide) for commands taking only a few milliseconds, maybe only show the abort button after 1s of execution time
    • Show that a command is executed (done in this PR, but maybe should be done differently to allow entering a next command).
    • Allow entering a followup command but can’t execute (should be added)
  11. hebasto force-pushed on Oct 29, 2020
  12. hebasto commented at 6:54 pm on October 29, 2020: member
    @jonasschnelli Spotted your comment too late, so, probably, the last commit in the latest push should be dropped, right?
  13. in src/qt/rpcconsole.cpp:893 in 0254e281df outdated
    891@@ -892,53 +892,53 @@ void RPCConsole::on_lineEdit_returnPressed()
    892 {
    893     QString cmd = ui->lineEdit->text();
    


    promag commented at 9:16 am on November 4, 2020:
    nit, could trim.

    hebasto commented at 11:49 am on November 15, 2020:
  14. promag commented at 9:59 am on November 4, 2020: contributor
    Another sensible approach would be to disable the line edit while keep the 2nd command there and execute it when the 1st ends.
  15. hebasto commented at 10:06 am on November 4, 2020: member

    Another sensible approach would be to disable the line edit while keep the 2nd command there and execute it when the 1st ends.

    This deprives the user of the ability to change his mind when the 1st command output is arrived.

  16. jonasschnelli added this to the milestone 0.22.0 on Nov 11, 2020
  17. in src/qt/rpcconsole.cpp:844 in 980b8e9684 outdated
    841+    } else {
    842         out += GUIUtil::HtmlEscape(message, false);
    843+    }
    844     out += "</td></tr></table>";
    845     ui->messagesWidget->append(out);
    846+    scrollToEnd();
    


    luke-jr commented at 7:01 pm on November 13, 2020:
    If the user has scrolled up, we shouldn’t ignore that and reset scroll to the bottom…

    hebasto commented at 11:49 am on November 15, 2020:
  18. luke-jr changes_requested
  19. hebasto force-pushed on Nov 15, 2020
  20. hebasto commented at 11:48 am on November 15, 2020: member

    Updated 980b8e968459f6fa7e16e5c79eaad782da9e89c0 -> e8753bf07bc2cb9c4023e771f7e10e65ba7571dd (pr123.02 -> pr123.03, diff):

    nit, could trim.

    If the user has scrolled up, we shouldn’t ignore that and reset scroll to the bottom…

  21. hebasto force-pushed on Nov 15, 2020
  22. jarolrod commented at 9:38 pm on January 19, 2021: member

    ACK 08d599e4f3b2e3a1143863d3cf1e64a8215a59b1, Tested on macOS 11.1 with Qt 5.15.2

    Master: Allowed to input several commands at once which will lead to messy output

    PR: Can only execute one command at a time

    Additional Thoughts (for a followup pr) As others have stated, it would be nice to have a cancel button on the command. This should be done in a follow up PR. An example of when this is useful:

    • I want to enter the gettxout command
    • I mistakingly autocomplete to the gettxoutsetinfo which takes some time to run
    • It would be nice to be able to cancel the gettxoutsetinfo command ran by accident, and not have to wait until it is finished to accomplish what I set out to accomplish -> run gettxout

    Perhaps something like this: (rough mockup) cancel-mockup

  23. in src/qt/rpcconsole.cpp:909 in 08d599e4f3 outdated
    917+    } catch (const std::exception& e) {
    918+        QMessageBox::critical(this, "Error", QString("Error: ") + QString::fromStdString(e.what()));
    919+        return;
    920+    }
    921+
    922+    if (cmd.startsWith("stop")) {
    


    Talkless commented at 7:13 pm on March 18, 2021:

    nit: QString::startsWith() has overload taking QLatin1String which is recommended to use if exists. It will not allocate new QString, and comparing to latin1 instead of utf-16 is cheaper memory-bandwith-wise.

    Also, maybe startsWith is not needed at all as the cmd string was trimmed beforehand? i.e. cmd == QLatin1String("stop") would suffice?


    hebasto commented at 3:19 am on March 20, 2021:
    Thanks! Updated.
  24. in src/qt/rpcconsole.cpp:935 in 08d599e4f3 outdated
    958+    }
    959+#endif // ENABLE_WALLET
    960 
    961-        cmd = QString::fromStdString(strFilteredCmd);
    962+    message(CMD_REQUEST, QString::fromStdString(strFilteredCmd));
    963+    message(CMD_REPLY, "Executing...");
    


    Talkless commented at 7:14 pm on March 18, 2021:
    nit: QStringLiteral("Executing...")

    hebasto commented at 3:19 am on March 20, 2021:
    This string is translated now.
  25. Talkless approved
  26. Talkless commented at 7:17 pm on March 18, 2021: none

    tACK 08d599e4f, tested on Debian Sid with Qt 5.15.2.

    I’ve generated bunch of transactions on regtest using generatetoaddress and later used listunspent as long-running command to reproduce issue on master, invoking multiple commands while first one is still running, and I see that PR code works as expecting afterwards.

  27. hebasto force-pushed on Mar 20, 2021
  28. hebasto commented at 3:18 am on March 20, 2021: member

    Updated 08d599e4f3b2e3a1143863d3cf1e64a8215a59b1 -> b87a4cd6bb58a6458dea7527a19433ead0ea848d (pr123.04 -> pr123.05, diff):

  29. hebasto added the label Feature on Mar 22, 2021
  30. Talkless approved
  31. Talkless commented at 6:34 pm on March 22, 2021: none
    re-ACK b87a4cd6bb58a6458dea7527a19433ead0ea848d after tweaks.
  32. leonardojobim commented at 2:24 pm on March 23, 2021: none

    Tested https://github.com/bitcoin-core/gui/pull/123/commits/b87a4cd6bb58a6458dea7527a19433ead0ea848d on Ubuntu 20.04 Qt 5.12.8.

    When executing commands enough to fill the entire result dialog, instead of scrolling down, it scrolls up to the top (“Welcome to the Bitcoin Core RPC console.” line). On the master branch, the scrolling apparently works OK.

    Edit: I commented the line ui->messagesWidget->undo(); and the scrolling has returned to working normally.

    0connect(executor, &RPCExecutor::reply, this, [this](int category, const QString& command) {
    1    //  ui->messagesWidget->undo();
    2    message(category, command);
    3    m_is_executing = false;
    4});
    
  33. hebasto closed this on Apr 3, 2021

  34. hebasto reopened this on Apr 3, 2021

  35. hebasto closed this on Apr 4, 2021

  36. hebasto reopened this on Apr 4, 2021

  37. in src/qt/rpcconsole.cpp:946 in b87a4cd6bb outdated
    905@@ -906,6 +906,16 @@ void RPCConsole::on_lineEdit_returnPressed()
    906         return;
    907     }
    908 
    909+    if (cmd == QLatin1String("stop")) {
    


    promag commented at 10:19 pm on April 20, 2021:

    b87a4cd6bb58a6458dea7527a19433ead0ea848d

    Could add a comment explaining this case.


    hebasto commented at 9:16 pm on May 3, 2021:
  38. promag commented at 10:23 pm on April 20, 2021: contributor

    Tested ACK b87a4cd6bb58a6458dea7527a19433ead0ea848d.

    if new output is appended and its not visible (user scrolled) then it could show some feedback/alert so user knows command finished and can scroll down.

    nit, could make “qt, rpc: Accept stop RPC even another command is executing” before “qt, rpc: Do not accept command while executing another one” to avoid adding || m_is_executing and then removing.

    Note: I’ve originally ACK https://github.com/promag/bitcoin/commit/328efdcb69eedbd3bce6d6de865cca0e3ee38374 which is b87a4cd6bb58a6458dea7527a19433ead0ea848d rebased on f385ad765174afb02e60900581612a19c143cf83.

  39. hebasto force-pushed on May 3, 2021
  40. hebasto commented at 9:16 pm on May 3, 2021: member

    @leonardojobim @Talkless @jarolrod @luke-jr @promag @jonasschnelli

    Thanks you for your reviewing and testing!

    Updated b87a4cd6bb58a6458dea7527a19433ead0ea848d -> 716139584ddf7ef554962e0188ae8b8a74e310e4 (pr123.05 -> pr123.06, diff):

    • reordered commits (@promag)
    • added comment for special case for stop command (@promag)
    • fixed scrolling (@leonardojobim)
    • added translator comment
  41. Talkless commented at 5:29 pm on May 6, 2021: none
    re-tACK 716139584ddf7ef554962e0188ae8b8a74e310e4, tested on same setup as previously.
  42. DrahtBot added the label Needs rebase on May 10, 2021
  43. hebasto force-pushed on May 11, 2021
  44. hebasto commented at 7:44 am on May 11, 2021: member
    Rebased 716139584ddf7ef554962e0188ae8b8a74e310e4 -> cb48c5964c901bccf5d2ffcd9f3f3e4552ae2fb1 (pr123.06 -> pr123.07) due to the conflict with #257.
  45. DrahtBot removed the label Needs rebase on May 11, 2021
  46. Talkless commented at 5:43 pm on May 13, 2021: none
    re-utACK 716139584ddf7ef554962e0188ae8b8a74e310e4, range-diff does not show anything to actually review or test.
  47. Talkless commented at 5:45 pm on May 13, 2021: none
    Wait @hebasto, a bit off topic, should I have had to make actual GitHub review in this interface, or comment is enough? Maybe sticking to always checking all files and producing GitHub review would be “better”?
  48. hebasto commented at 5:54 pm on May 13, 2021: member

    @Talkless

    Wait @hebasto, a bit off topic, should I have had to make actual GitHub review in this interface, or comment is enough? Maybe sticking to always checking all files and producing GitHub review would be “better”?

    Not sure if I understand your question in part “producing GitHub review”…

    Anyway, your #123 (comment) is straightforward. While reviewing pulls after rebasing I do the same locally git range-diff master pr-before-rebase pr-after-rebase. If rebasing is not trivial it could be valuable re-check all changes.

  49. Talkless commented at 7:12 pm on May 13, 2021: none

    Not sure if I understand your question in part “producing GitHub review”…

    In Github web interface, we can go to “Files changed” tab, check “Viewed” checkboxes on the files, and click “Review changes” -> “Submit review”, which produces sort of “special” kind of “comment”. Maybe it’s “better” for maintainers to check for these kind of “reviews”, instead of “just” a comment?

  50. hebasto commented at 7:18 pm on May 13, 2021: member

    Not sure if I understand your question in part “producing GitHub review”…

    In Github web interface, we can go to “Files changed” tab, check “Viewed” checkboxes on the files, and click “Review changes” -> “Submit review”, which produces sort of “special” kind of “comment”. Maybe it’s “better” for maintainers to check for these kind of “reviews”, instead of “just” a comment?

    In this project we strive to rely on GitHub as little as possible :) Ofc, a reviewer could use any GitHub feature he like. Features you mentioned make no difference for maintainers.

  51. hebasto commented at 12:17 pm on May 15, 2021: member

    @Talkless

    In #123 (comment)

    re-utACK 7161395, range-diff does not show anything to actually review or test.

    Did you mean the old top 716139584ddf7ef554962e0188ae8b8a74e310e4 or the new cb48c5964c901bccf5d2ffcd9f3f3e4552ae2fb1?

  52. Talkless commented at 5:34 pm on May 19, 2021: none

    @Talkless

    In #123 (comment)

    re-utACK 7161395, range-diff does not show anything to actually review or test.

    Did you mean the old top 7161395 or the new cb48c59?

    Ugh, not again… I did range-diff for review, but forgot to actually switch to new tip before copying latest commit hash..

    re-ACK cb48c5964c901bccf5d2ffcd9f3f3e4552ae2fb1

  53. hebasto commented at 12:40 pm on May 29, 2021: member

    @jarolrod @promag @leonardojobim

    Do you mind having another (final?) look into at this PR?

  54. hebasto requested review from promag on May 29, 2021
  55. promag commented at 1:52 pm on May 31, 2021: contributor
    Tested ACK cb48c5964c901bccf5d2ffcd9f3f3e4552ae2fb1.
  56. in src/qt/rpcconsole.cpp:945 in cb48c5964c outdated
    981+#endif // ENABLE_WALLET
    982 
    983-        // Scroll console view to end
    984-        scrollToEnd();
    985+    message(CMD_REQUEST, QString::fromStdString(strFilteredCmd));
    986+    //: A message in the GUI console while an entered command being executed.
    


    jarolrod commented at 4:21 pm on May 31, 2021:

    nit

    0    //: A console message indicating an entered command is currently being executed.
    

    hebasto commented at 4:44 pm on May 31, 2021:
    This could be addressed in a follow up.

    hebasto commented at 8:38 pm on May 31, 2021:
    Thanks! Updated.
  57. in src/qt/rpcconsole.cpp:927 in cb48c5964c outdated
    896@@ -897,57 +897,71 @@ void RPCConsole::setMempoolSize(long numberOfTxs, size_t dynUsage)
    897 
    898 void RPCConsole::on_lineEdit_returnPressed()
    899 {
    900-    QString cmd = ui->lineEdit->text();
    901+    QString cmd = ui->lineEdit->text().trimmed();
    


    jarolrod commented at 4:31 pm on May 31, 2021:

    nit

    we should document that we are using this function in the commit message for proper documentation


    hebasto commented at 4:45 pm on May 31, 2021:
    This could be addressed in a follow up.

    hebasto commented at 8:39 pm on May 31, 2021:
  58. jarolrod commented at 4:38 pm on May 31, 2021: member

    ACK cb48c5964c901bccf5d2ffcd9f3f3e4552ae2fb1

    Edit: Retracting ACK because of a silent merge conflict with #335. The signal count which is expected has changed with this PR, this signal count should be adjusted in the tests to reflect the introduction of the "Executing..." message.

    Tested functionality on Arch Linux Qt 5.15.2 and macOS 11.3 Qt 5.15.2. Tested each commit individually, cherry-picking each on top of master. This is a nice patch. A couple of nits, no need to address unless you absolutely have to retouch. 🥃

    Notes on commits:

    • 9d9f7f1158323e77d6c7ec59f1ca375d6d87a9ea
      • Tested that “Executing…” message is displayed and removed upon response
    • 614cc38fa94567c90b567514cc5db785be658841
      • Concept ACK on refactoring the logic here to return early if the command is empty
    • d4e7fcc2a8b36e7bf1450edeb67bb468aac8d602
      • Tested that we can call stop, although true testing of this commit can only be done with the next commit applied. I think we should have kept this commit after qt, rpc: Do not accept command while executing another one
      • ACK on using the trimmed Qstring function % nit
    • cb48c5964c901bccf5d2ffcd9f3f3e4552ae2fb1
      • Tested that we cannot input another command while another is being executed
      • Tested that we can still call the stop command
        • It’s annoying that this command just quits the application. It would be nice to change this in a followup.

    Screenshots: Below are screenshots showing the behavior of master vs pr. Note that one can continue to input commands on master, but cannot with this pr:

    Master Description
    master pr
  59. qt, rpc: Add "Executing…" message 5b9c8c9cdd
  60. qt, rpc, refactor: Return early in RPCConsole::on_lineEdit_returnPressed ccf790287c
  61. qt, rpc: Accept stop RPC even another command is executing
    While here, clean up the command input by calling the trimmed function
    on the input from the command prompt.
    0c32b9c527
  62. qt, rpc: Do not accept command while executing another one 38eb37c0bd
  63. hebasto force-pushed on May 31, 2021
  64. hebasto commented at 8:37 pm on May 31, 2021: member

    Updated cb48c5964c901bccf5d2ffcd9f3f3e4552ae2fb1 -> 38eb37c0bd29b4cb825de905e8eec87636a5221b (pr123.07 -> pr123.08):

    • rebased to fix the silent merge conflict with #335
    • addressed the recent @jarolrod’s comments
  65. jarolrod commented at 9:14 pm on May 31, 2021: member

    ACK 38eb37c

    re-tested functionality. Ran tests to confirm this fixes the silent merge conflict with #335.

    Rebased pr123.07 on top of the commit pr123.08 is based on, 933c6466c2bda3a06d3c5da0de0d8f05111c9f4c, and got the following diff which shows the only changes from my last review are; changes to translator comment to address my review comment and update to apptests to reflect the expected signal count:

     0$ git diff pr123.07 pr123.08
     1diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp
     2index 803946dcf..c762f2b9c 100644
     3--- a/src/qt/rpcconsole.cpp
     4+++ b/src/qt/rpcconsole.cpp
     5@@ -969,7 +969,7 @@ void RPCConsole::on_lineEdit_returnPressed()
     6 #endif // ENABLE_WALLET
     7 
     8     message(CMD_REQUEST, QString::fromStdString(strFilteredCmd));
     9-    //: A message in the GUI console while an entered command being executed.
    10+    //: A console message indicating an entered command is currently being executed.
    11     message(CMD_REPLY, tr("Executing…"));
    12     m_is_executing = true;
    13     Q_EMIT cmdRequest(cmd, m_last_wallet_model);
    14diff --git a/src/qt/test/apptests.cpp b/src/qt/test/apptests.cpp
    15index c1d5f84be..cb3dbd226 100644
    16--- a/src/qt/test/apptests.cpp
    17+++ b/src/qt/test/apptests.cpp
    18@@ -40,7 +40,7 @@ void TestRpcCommand(RPCConsole* console)
    19     QTest::keyClicks(lineEdit, "getblockchaininfo");
    20     QTest::keyClick(lineEdit, Qt::Key_Return);
    21     QVERIFY(mw_spy.wait(1000));
    22-    QCOMPARE(mw_spy.count(), 2);
    23+    QCOMPARE(mw_spy.count(), 4);
    24     QString output = messagesWidget->toPlainText();
    25     UniValue value;
    26     value.read(output.right(output.size() - output.lastIndexOf(QChar::ObjectReplacementCharacter) - 1).toStdString());
    
  66. hebasto commented at 9:18 pm on May 31, 2021: member

    @Talkless @promag

    Hoping on your re-reviewing.

  67. promag commented at 10:31 pm on May 31, 2021: contributor

    Tested ACK 38eb37c0bd29b4cb825de905e8eec87636a5221b.

    Added a dummy sleep in some call just to simplify testing.

  68. hebasto merged this on Jun 1, 2021
  69. hebasto closed this on Jun 1, 2021

  70. hebasto deleted the branch on Jun 1, 2021
  71. sidhujag referenced this in commit f42b4dd719 on Jun 1, 2021
  72. gwillen referenced this in commit c2b9c35879 on Jun 1, 2022
  73. bitcoin-core locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/gui. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-23 00:20 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me