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

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
Copy link
Member

antiochp commented Dec 7, 2019

Nice.

@magp3wd912
Copy link

@@ -1,6 +1,6 @@
[package]
name = "grin"
-version = "3.0.0-alpha.1"
+version = "3.0.0-beta.1"
authors = ["Grin Developers [email protected]"]
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
Copy link
Member

antiochp commented Dec 9, 2019

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

Copy link
Member

@antiochp antiochp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants