Let us call these pending transactions 'slots.' That has a maximum buffer or 'head' of pending transactions per 'from' address that matches or is less than the maximum number of transactions that the peer can have in its transaction pool queue per from address.I haven't yet got to the point where I can test any of these things, but my gut feel is that the Singleton Nonce Manager would be the way to go, with a few enhancements: Either way, it adds disproportional bulkiness to user applications. It forces user applications to either handle low-level protocol details, or to introduce dependency on a node (Geth/Parity). It appears to me the account nonce is not the best design in Ethereum. Again, the complexity (and potential vulnerability) doesn't appear justifiable if it's only for dealing with the nonce. The most obvious issue is the extra dependency doesn't seem to be justifiable, if it's merely for the nonce field.Īlso, if the user application already manages private keys, this introduces extra complexity: the private keys will need to be co-managed (or copied) by the Geth or Parity node. Candidate 4: delegate to a local Geth/Parity node In general, it's a poor solution that introduces more complexity and problems than trying to solve. doesn't even get sent out to the network), the rest of the transactions will become stuck indefinitely. Not only this introduces a singleton (arguable an anti-pattern), but also it doesn't sound easy to get it right: if a low nonce transaction fails somehow (e.g.
This exploits the behaviour discussed here.
The singleton "nonce manager" can have some smart logic to hand out ascending nonce numbers. Candidate 3: a singleton 'nonce manager'Įach transaction construction involves "applying for" a nonce from a global "nonce manager". As a result, the detection doesn't work reliably. In practice, I seem to have noticed Geth sometimes does not even return the above string, but silently drops the other transactions (not confirmed as I haven't found a reliable way to reproduce). This solution is not portable: different clients return different strings for the same error. Geth would return 'replacement transaction underpriced'), re-try with a new nonce. If the return result indicates duplicate nonce (e.g. This makes a loop that checks transaction sending result. Furthermore, given that Hierachical Deterministic wallet is not native in Ethereum (I am aware there is the LightWallet), this doesn't sound like an easy solution. Plus, it's not too scalable: consider if tens or hundreds of concurrent transactions are needed. However, it introduces extra complexity in the user application. My question is: what are some good patterns to handle this situation? Candidate 1: multiple keys/accounts per user As a result, when transactions are signed in parallel, unless we manipulate the count in a smart way, only one of them will succeed. "" returns confirmed transaction counts only (see this question). The transaction sequentialisation becomes a responsibility of the user application. However, consider an end-user that has to sign multiple transactions in parallel. This works fine when no concurrency is involved. through ).Ĭonstructing the raw transaction requires obtaining an account's nonce, which can be done by, as explained in this question. not Geth or Parity), before sent over to a node (e.g. This is not the case when transactions are created and signed by a user application (i.e. The sequentialisation is done internally by the node, and thus is transparent to the end-user. Geth, Parity), which then does the signing. This usually doesn't cause problems when transactions are submitted through the web3 interface to an Ethereum node (e.g. It essentially forces sequentialisation of an account's tranctions. The account nonce is the only element in the transaction structure that prevents replay attack (as explained in this very good answer).