From https://github.com/ethereum/go-ethereum/blob/master/rpc/api/personal.go#L120-L139https://github.com/ethereum/go-ethereum/blob/master/internal/ethapi/api.go#L239-L254 :
// UnlockAccount will unlock the account associated with the given address with
// the given password for duration seconds. If duration is nil it will use a
// default of 300 seconds. It returns an indication if the account was unlocked.
func (selfs *personalApi*PrivateAccountAPI) UnlockAccount(reqaddr *sharedcommon.RequestAddress, password string, duration *uint64) (interface{}bool, error) {
argsconst :max = newuint64(UnlockAccountArgstime.Duration(math.MaxInt64) / time.Second)
var d time.Duration
if duration == nil {
d = 300 * time.Second
} else if *duration > max {
return false, errors.New("unlock duration too large")
} else {
d = time.Duration(*duration) * time.Second
}
err := s.am.TimedUnlock(accounts.Account{Address: addr}, *args.Passphrasepassword, time.Duration(args.Duration)*time.Secondd)
return err == nil, err
}
And from https://github.com/ethereum/go-ethereum/blob/master/accounts/account_manager.go#L95-L125https://github.com/ethereum/go-ethereum/blob/master/accounts/account_manager.go#L181-L216 where you can see the comment A timeout of 0 unlocks the account until the program exits
:
// TimedUnlock unlocks the given account with the given addresspassphrase. The account
// stays unlocked for the duration of timeout. A timeout of 0 unlocks the account
// until the program exits. The account must match a unique key file.
//
// If the accoutaccount address is already unlocked for a duration, TimedUnlock extends or shortens
// shortens the active unlock timeout. If the address was previously unlocked
// indefinitely the timeout is not altered.
func (am *Manager) TimedUnlock(addra common.AddressAccount, keyAuthpassphrase string, timeout time.Duration) error {
a, key, err := am.keyStore.GetKeygetDecryptedKey(addra, keyAuthpassphrase)
if err != nil {
return err
}
var u *unlocked
am.mutexmu.Lock()
defer am.mutexmu.Unlock()
varu, found bool:= am.unlocked[a.Address]
u,if found = am.unlocked[addr]{
if foundu.abort == nil {
// terminateThe dropLateraddress forwas thisunlocked keyindefinitely, toso avoidunlocking
unexpected drops // it with a timeout would be confusing.
if u zeroKey(key.abortPrivateKey)
!= return nil
} else {
// Terminate the expire goroutine and replace it below.
close(u.abort)
}
}
if timeout > 0 {
u = &unlocked{Key: key, abort: make(chan struct{})}
go am.expire(addra.Address, u, timeout)
} else {
u = &unlocked{Key: key}
}
am.unlocked[addr]unlocked[a.Address] = u
return nil
}