chore(wallet)_: proper release of locked nonce (unlock function call)

This commit is contained in:
Sale Djenic 2023-11-17 12:38:12 +01:00 committed by saledjenic
parent 03cdb49c4c
commit e9f11f70dd
4 changed files with 26 additions and 13 deletions

View File

@ -1 +1 @@
0.171.13
0.171.14

View File

@ -400,9 +400,11 @@ func (tm *TransactionManager) ProceedWithTransactionsSignatures(ctx context.Cont
hashes := make(map[uint64][]types.Hash)
for _, desc := range tm.transactionsForKeycardSingning {
hash, err := tm.transactor.SendBuiltTransactionWithSignature(desc.chainID, desc.builtTx, desc.signature)
defer func() {
desc.unlock(err == nil, desc.builtTx.Nonce())
}()
if desc.unlock != nil {
defer func() {
desc.unlock(err == nil, desc.builtTx.Nonce())
}()
}
if err != nil {
return nil, err
}

View File

@ -25,6 +25,10 @@ func NewNonce() *Nonce {
func (n *Nonce) Next(rpcWrapper *rpcWrapper, from types.Address) (uint64, UnlockNonceFunc, error) {
n.addrLock.LockAddr(from)
current, err := n.GetCurrent(rpcWrapper, from)
if err != nil {
return 0, nil, err
}
unlock := func(inc bool, nonce uint64) {
if inc {
if _, ok := n.localNonce[rpcWrapper.chainID]; !ok {
@ -36,7 +40,7 @@ func (n *Nonce) Next(rpcWrapper *rpcWrapper, from types.Address) (uint64, Unlock
n.addrLock.UnlockAddr(from)
}
return current, unlock, err
return current, unlock, nil
}
func (n *Nonce) GetCurrent(rpcWrapper *rpcWrapper, from types.Address) (uint64, error) {

View File

@ -157,9 +157,11 @@ func (t *Transactor) SendTransactionWithSignature(chainID uint64, args SendTxArg
if err != nil {
return hash, err
}
defer func() {
unlock(err == nil, expectedNonce)
}()
if unlock != nil {
defer func() {
unlock(err == nil, expectedNonce)
}()
}
if tx.Nonce() != expectedNonce {
return hash, &ErrBadNonce{tx.Nonce(), expectedNonce}
@ -179,7 +181,9 @@ func (t *Transactor) HashTransaction(args SendTxArgs) (validatedArgs SendTxArgs,
if err != nil {
return validatedArgs, hash, err
}
defer unlock(false, 0)
if unlock != nil {
defer unlock(false, 0)
}
gasPrice := (*big.Int)(args.GasPrice)
gasFeeCap := (*big.Int)(args.MaxFeePerGas)
@ -273,13 +277,16 @@ func (t *Transactor) validateAndBuildTransaction(rpcWrapper *rpcWrapper, args Se
return tx, nil, ErrInvalidSendTxArgs
}
nonce, unlock, err := t.nonce.Next(rpcWrapper, args.From)
if err != nil {
return tx, nil, err
}
var nonce uint64
if args.Nonce != nil {
nonce = uint64(*args.Nonce)
} else {
nonce, unlock, err = t.nonce.Next(rpcWrapper, args.From)
if err != nil {
return tx, nil, err
}
}
ctx, cancel := context.WithTimeout(context.Background(), t.rpcCallTimeout)
defer cancel()