Skip to content

Commit 04207b1

Browse files
committed
Improved docs about local nonce value no longer being valid
1 parent 1b978b7 commit 04207b1

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

pkg/chain/ethereum/ethutil/nonce.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import (
88
"github.com/ethereum/go-ethereum/common"
99
)
1010

11-
// The time for which the nonce value cached locally is valid. The local copy
12-
// is invalidated after the certain duration to let the nonce recover in case
13-
// the mempool crashed before propagating the last transaction sent.
11+
// The inactivity time after which the local nonce is refreshed with the value
12+
// from the chain. The local value is invalidated after the certain duration to
13+
// let the nonce recover in case the mempool crashed before propagating the last
14+
// transaction sent.
1415
const localNonceTrustDuration = 5 * time.Second
1516

1617
// NonceManager tracks the nonce for the account and allows to update it after
@@ -89,6 +90,14 @@ func (nm *NonceManager) CurrentNonce() (uint64, error) {
8990
}
9091
}
9192

93+
// After localNonceTrustDuration of inactivity (no CurrentNonce() calls),
94+
// the local copy is considered as no longer up-to-date and it's always
95+
// reset to the pending nonce value as seen by the chain.
96+
//
97+
// We do it to recover from potential mempool crashes.
98+
//
99+
// Keep in mind, the local copy is considered valid as long as transactions
100+
// are submitted one after another.
92101
nm.expirationDate = now.Add(localNonceTrustDuration)
93102

94103
if pendingNonce > nm.localNonce {

0 commit comments

Comments
 (0)