aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/account_manager.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-07-22 19:00:09 +0800
committerFelix Lange <fjl@twurst.com>2015-07-22 19:00:09 +0800
commitd1d45aa8390731ad9d0422e6bbf2d451d11dab4d (patch)
treed562f038e25ce5f0fa0554db03f8b596bf4704a3 /accounts/account_manager.go
parented1d2f858e009477a67689dc31d3fd41921b261e (diff)
parent06d5898d6a0f1f99505e55454688dd67237a98f9 (diff)
downloaddexon-d1d45aa8390731ad9d0422e6bbf2d451d11dab4d.tar
dexon-d1d45aa8390731ad9d0422e6bbf2d451d11dab4d.tar.gz
dexon-d1d45aa8390731ad9d0422e6bbf2d451d11dab4d.tar.bz2
dexon-d1d45aa8390731ad9d0422e6bbf2d451d11dab4d.tar.lz
dexon-d1d45aa8390731ad9d0422e6bbf2d451d11dab4d.tar.xz
dexon-d1d45aa8390731ad9d0422e6bbf2d451d11dab4d.tar.zst
dexon-d1d45aa8390731ad9d0422e6bbf2d451d11dab4d.zip
Merge pull request #1503 from fjl/fix-accounts-race
accounts: fix data race when key is locked after the unlock timeout
Diffstat (limited to 'accounts/account_manager.go')
-rw-r--r--accounts/account_manager.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go
index 2a9d9b0ae..c6c2787dc 100644
--- a/accounts/account_manager.go
+++ b/accounts/account_manager.go
@@ -78,8 +78,8 @@ func (am *Manager) DeleteAccount(address common.Address, auth string) error {
func (am *Manager) Sign(a Account, toSign []byte) (signature []byte, err error) {
am.mutex.RLock()
+ defer am.mutex.RUnlock()
unlockedKey, found := am.unlocked[a.Address]
- am.mutex.RUnlock()
if !found {
return nil, ErrLocked
}
@@ -87,14 +87,17 @@ func (am *Manager) Sign(a Account, toSign []byte) (signature []byte, err error)
return signature, err
}
-// unlock indefinitely
+// Unlock unlocks the given account indefinitely.
func (am *Manager) Unlock(addr common.Address, keyAuth string) error {
return am.TimedUnlock(addr, keyAuth, 0)
}
-// Unlock unlocks the account with the given address. The account
-// stays unlocked for the duration of timeout
-// it timeout is 0 the account is unlocked for the entire session
+// TimedUnlock unlocks the account with the given address. The account
+// stays unlocked for the duration of timeout. A timeout of 0 unlocks the account
+// until the program exits.
+//
+// If the accout is already unlocked, TimedUnlock extends or shortens
+// the active unlock timeout.
func (am *Manager) TimedUnlock(addr common.Address, keyAuth string, timeout time.Duration) error {
key, err := am.keyStore.GetKey(addr, keyAuth)
if err != nil {