Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TUI): Fixed panic when changing order of items in TableView #3160

Merged

Conversation

@JosephGoulden
Copy link
Contributor

JosephGoulden commented Dec 6, 2019

This is awkward to reproduce but can be done reliably if you get the timing right.

  • Remove peers database (rm -r .grin/main/chain_data/peer/), just to force us to go looking for more.
  • Select Peers tab in TUI and order peers by Address.
  • Whenever the list of peers updates reorder again straight away, so the row with focus should always be at the bottom of the list.
  • At some point the number of peers will go to a large number then back to 8 (if you have the default desired peers). It's at this point the panic occurs, because the focus might be on peer 15 but the new list only has 8 peers.

thread 'main' panicked at 'index out of bounds: the len is 8 but the index is 14':
...
6: grin::tui::table::TableView<T,H>::sort_by::haee3b0fe6388d824 (0x55986b9dd817)
7: grin::tui::table::TableView<T,H>::set_items::h6712930b43f95168 (0x55986b9de079)

Have changed it so that sort function does not try to set_selected_item if it is outside the range of the new peers list and the panic no longer occurs.

…e the number of items in the table is reduced
@antiochp

This comment has been minimized.

Copy link
Member

antiochp commented Dec 7, 2019

Nice.

@magp3wd912

This comment has been minimized.

Copy link

magp3wd912 commented Dec 7, 2019

@@ -1,6 +1,6 @@
[package]
name = "grin"
-version = "3.0.0-alpha.1"
+version = "3.0.0-beta.1"
authors = ["Grin Developers mimblewimble@lists.launchpad.net"]
description = "Simple, private and scalable cryptocurrency implementation based on the Mimblewimble chain format."
license = "Apache-2.0"

@@ -32,14 +32,14 @@ term = "0.5"
failure = "0.1"
failure_derive = "0.1"

-grin_api = { path = "./api", version = "3.0.0-alpha.1" } 
-grin_config = { path = "./config", version = "3.0.0-alpha.1" } 
-grin_chain = { path = "./chain", version = "3.0.0-alpha.1" } 
-grin_core = { path = "./core", version = "3.0.0-alpha.1" } 

-grin_keychain = { path = "./keychain", version = "3.0.0-alpha.1" }
-grin_p2p = { path = "./p2p", version = "3.0.0-alpha.1" }
-grin_servers = { path = "./servers", version = "3.0.0-alpha.1" }
-grin_util = { path = "./util", version = "3.0.0-alpha.1" }
+grin_api = { path = "./api", version = "3.0.0-beta.1" }
+grin_config = { path = "./config", version = "3.0.0-beta.1" }
+grin_chain = { path = "./chain", version = "3.0.0-beta.1" }
+grin_core = { path = "./core", version = "3.0.0-beta.1" }
+grin_keychain = { path = "./keychain", version = "3.0.0-beta.1" }
+grin_p2p = { path = "./p2p", version = "3.0.0-beta.1" }
+grin_servers = { path = "./servers", version = "3.0.0-beta.1" }
+grin_util = { path = "./util", version = "3.0.0-beta.1" }

[target.'cfg(windows)'.dependencies]
cursive = { version = "0.12", default-features = false, features = ["pancurses-backend"] }

@@ -53,5 +53,5 @@ cursive = "0.12"
built = "0.3"

[dev-dependencies] 

-grin_chain = { path = "./chain", version = "3.0.0-alpha.1" }
-grin_store = { path = "./store", version = "3.0.0-alpha.1" } +grin_chain = { path = "./chain", version = "3.0.0-beta.1" }
+grin_store = { path = "./store", version = "3.0.0-beta.1" }

@antiochp

This comment has been minimized.

Copy link
Member

antiochp commented Dec 9, 2019

I've definitely encountered this before - and always failed to investigate it...

Copy link
Member

antiochp left a comment

👍

@@ -616,7 +616,7 @@ impl<T: TableViewItem<H>, H: Eq + Hash + Copy + Clone + 'static> TableView<T, H>
});
self.rows_to_items = rows_to_items;

self.set_selected_item(old_item);
old_item.map(|o| self.set_selected_item(o));

This comment has been minimized.

Copy link
@antiochp

antiochp Dec 10, 2019

Member

Oh that's really nice - just using map() rather than an if let Some(x) = old_item { ... }.

@antiochp antiochp merged commit 39af7fa into mimblewimble:master Dec 10, 2019
10 checks passed
10 checks passed
mimblewimble.grin #20191206.8 succeeded
Details
mimblewimble.grin (linux api/util/store) linux api/util/store succeeded
Details
mimblewimble.grin (linux chain/core/keychain) linux chain/core/keychain succeeded
Details
mimblewimble.grin (linux pool/p2p/src) linux pool/p2p/src succeeded
Details
mimblewimble.grin (linux release) linux release succeeded
Details
mimblewimble.grin (linux servers) linux servers succeeded
Details
mimblewimble.grin (macos release) macos release succeeded
Details
mimblewimble.grin (macos test) macos test succeeded
Details
mimblewimble.grin (windows release) windows release succeeded
Details
mimblewimble.grin (windows test) windows test succeeded
Details
@antiochp antiochp added this to the 3.0.0 milestone Dec 11, 2019
@antiochp antiochp mentioned this pull request Dec 11, 2019
@@ -492,7 +492,7 @@ impl<T: TableViewItem<H>, H: Eq + Hash + Copy + Clone + 'static> TableView<T, H>
/// Returns the index of the currently selected item within the underlying
/// storage vector.
pub fn item(&self) -> Option<usize> {
if self.items.is_empty() {
if self.items.is_empty() || self.focus > self.rows_to_items.len() {

This comment has been minimized.

Copy link
@antiochp

antiochp Dec 12, 2019

Member

Should this actually be >=?

I just happened to see the following panic locally -

thread 'main' panicked at 'index out of bounds: the len is 15 but the index is 15': /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libcore/slice/mod.rs:2717stack backtrace:

This comment has been minimized.

Copy link
@JosephGoulden

JosephGoulden Dec 12, 2019

Author Contributor

Yes you're right I think it should. I can do a fix for that now.

This comment has been minimized.

Copy link
@antiochp

antiochp Dec 12, 2019

Member

If its just this one line change I think we can get it in for beta.2.
👍

garyyu added a commit to garyyu/grin that referenced this pull request Jan 14, 2020
…e the number of items in the table is reduced (mimblewimble#3160)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.