Skip to content

Commit f951e23

Browse files
authored
Merge pull request #17887 from karalabe/warn-failed-account-access
internal/ethapi: warn on failed account accesses
2 parents 4e474c7 + aff421e commit f951e23

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

internal/ethapi/api.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ func (s *PrivateAccountAPI) UnlockAccount(addr common.Address, password string,
328328
d = time.Duration(*duration) * time.Second
329329
}
330330
err := fetchKeystore(s.am).TimedUnlock(accounts.Account{Address: addr}, password, d)
331+
if err != nil {
332+
log.Warn("Failed account unlock attempt", "address", addr, "err", err)
333+
}
331334
return err == nil, err
332335
}
333336

@@ -339,7 +342,7 @@ func (s *PrivateAccountAPI) LockAccount(addr common.Address) bool {
339342
// signTransactions sets defaults and signs the given transaction
340343
// NOTE: the caller needs to ensure that the nonceLock is held, if applicable,
341344
// and release it after the transaction has been submitted to the tx pool
342-
func (s *PrivateAccountAPI) signTransaction(ctx context.Context, args SendTxArgs, passwd string) (*types.Transaction, error) {
345+
func (s *PrivateAccountAPI) signTransaction(ctx context.Context, args *SendTxArgs, passwd string) (*types.Transaction, error) {
343346
// Look up the wallet containing the requested signer
344347
account := accounts.Account{Address: args.From}
345348
wallet, err := s.am.Find(account)
@@ -370,8 +373,9 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs
370373
s.nonceLock.LockAddr(args.From)
371374
defer s.nonceLock.UnlockAddr(args.From)
372375
}
373-
signed, err := s.signTransaction(ctx, args, passwd)
376+
signed, err := s.signTransaction(ctx, &args, passwd)
374377
if err != nil {
378+
log.Warn("Failed transaction send attempt", "from", args.From, "to", args.To, "value", args.Value.ToInt(), "err", err)
375379
return common.Hash{}, err
376380
}
377381
return submitTransaction(ctx, s.b, signed)
@@ -393,8 +397,9 @@ func (s *PrivateAccountAPI) SignTransaction(ctx context.Context, args SendTxArgs
393397
if args.Nonce == nil {
394398
return nil, fmt.Errorf("nonce not specified")
395399
}
396-
signed, err := s.signTransaction(ctx, args, passwd)
400+
signed, err := s.signTransaction(ctx, &args, passwd)
397401
if err != nil {
402+
log.Warn("Failed transaction sign attempt", "from", args.From, "to", args.To, "value", args.Value.ToInt(), "err", err)
398403
return nil, err
399404
}
400405
data, err := rlp.EncodeToBytes(signed)
@@ -436,6 +441,7 @@ func (s *PrivateAccountAPI) Sign(ctx context.Context, data hexutil.Bytes, addr c
436441
// Assemble sign the data with the wallet
437442
signature, err := wallet.SignHashWithPassphrase(account, passwd, signHash(data))
438443
if err != nil {
444+
log.Warn("Failed data sign attempt", "address", addr, "err", err)
439445
return nil, err
440446
}
441447
signature[64] += 27 // Transform V from 0/1 to 27/28 according to the yellow paper

0 commit comments

Comments
 (0)