aboutsummaryrefslogtreecommitdiffstats
path: root/accounts
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-01-30 18:21:39 +0800
committerPéter Szilágyi <peterke@gmail.com>2017-02-13 20:00:07 +0800
commitb3c0e9d3ccb0bb326646aea47dda391a9552b122 (patch)
tree72ca91f5897760c7fefe7d5fc52d5163cccfca99 /accounts
parent470b79385bcde3b4c999daf6a8debb00072ad967 (diff)
downloadgo-tangerine-b3c0e9d3ccb0bb326646aea47dda391a9552b122.tar.gz
go-tangerine-b3c0e9d3ccb0bb326646aea47dda391a9552b122.tar.zst
go-tangerine-b3c0e9d3ccb0bb326646aea47dda391a9552b122.zip
accounts/usbwallet: two phase Ledger refreshes to avoid Windows bug
Diffstat (limited to 'accounts')
-rw-r--r--accounts/usbwallet/ledger.go49
1 files changed, 24 insertions, 25 deletions
diff --git a/accounts/usbwallet/ledger.go b/accounts/usbwallet/ledger.go
index cc64ccb42..9917d0d70 100644
--- a/accounts/usbwallet/ledger.go
+++ b/accounts/usbwallet/ledger.go
@@ -234,32 +234,11 @@ func (hub *LedgerHub) rescan() {
hub.lock.Lock()
defer hub.lock.Unlock()
- // Iterate over all attached devices and fetch those seemingly Ledger
- present := make(map[uint16]bool)
- devices, _ := hub.ctx.ListDevices(func(desc *usb.Descriptor) bool {
- // Discard all devices not advertizing as Ledger
- ledger := false
- for _, id := range ledgerDeviceIDs {
- if desc.Vendor == id.Vendor && desc.Product == id.Product {
- ledger = true
- }
- }
- if !ledger {
- return false
- }
- // If we have a Ledger, mark as still present, or open as new
- id := uint16(desc.Bus)<<8 + uint16(desc.Address)
- if _, known := hub.wallets[id]; known {
- // Track it's presence, but don't open again
- present[id] = true
- return false
- }
- // New Ledger device, open it for communication
- return true
- })
- // Drop any tracker wallet which disconnected
+ // Iterate over all connected Ledger devices and do a heartbeat test
for id, wallet := range hub.wallets {
- if !present[id] {
+ // If the device doesn't respond (io error on Windows, no device on Linux), drop
+ if err := wallet.resolveVersion(); err == usb.ERROR_IO || err == usb.ERROR_NO_DEVICE {
+ // Wallet disconnected or at least in a useless state
if wallet.address == (common.Address{}) {
glog.V(logger.Info).Infof("ledger wallet [%03d.%03d] disconnected", wallet.device.Bus, wallet.device.Address)
} else {
@@ -279,6 +258,26 @@ func (hub *LedgerHub) rescan() {
wallet.device.Close()
}
}
+ // Iterate over all attached devices and fetch those seemingly Ledger
+ devices, _ := hub.ctx.ListDevices(func(desc *usb.Descriptor) bool {
+ // Discard all devices not advertizing as Ledger
+ ledger := false
+ for _, id := range ledgerDeviceIDs {
+ if desc.Vendor == id.Vendor && desc.Product == id.Product {
+ ledger = true
+ }
+ }
+ if !ledger {
+ return false
+ }
+ // If we have an already known Ledger, skip opening it
+ id := uint16(desc.Bus)<<8 + uint16(desc.Address)
+ if _, known := hub.wallets[id]; known {
+ return false
+ }
+ // New Ledger device, open it for communication
+ return true
+ })
// Start tracking all wallets which newly appeared
var err error
for _, device := range devices {