I'm trying to build an Ethereum exchange service, so concurrent schedule is needed and nonce management is the most problem (another topic discussed about it). At specificed moment, I have large request of transactions (txs), so I'm using redis and physical database to storage current nonce and update it +1 while ending (often get nonce from redis, if redis is dead, switch to physical db).
When testing, nonce from redis occasionally is higher than current valid nonce (getTransactionCount
), it will be marked as successful transaction (tx) with a valid hash is returned:
Example current nonce is 50, create list txs with higher nonce such as 51, 52,... is all valid and return valid hashes.
The problem at there is if nonce 50 is not filled by a specificed tx, list txs with higher nonce than 50 will wait for a period time and I don't know when it will be expired. I've test a half day to full day but they're not expired. When I create a tx with nonce 50, after a short time, list txs higher none +50 will be broadcasted automatically and become successfull too. I know that I can cancel these txs by creating a self transaction with higher gas but it's not the problem I'm facing.
So, I have 2 question, where can I find list txs higher nonce than current valid nonce eg etherscan.io or my node though I've storaged them on physical DB. And 2nd question is if I don't fill a missing nonce to chain, will list txs be expired for a period time (how long) or they're storaged forever, if I wanna cancel them I must create self transaction with higher gas? Thanks for hearing me so much and have a nice day.
//I'm creating a schedule, which check nonce from node and redis if they're diffrent, create a self transaction with nonce from node but I think this is not a good resolve...
-
for context question also here: github.com/ethereum/go-ethereum/issues/20193– ligiOct 23, 2019 at 0:49
-
@ligi, thanks for your notice. I've updated more clearly...– mmo2112Oct 23, 2019 at 4:05
1 Answer
So, I have 2 question, where can I find list txs higher nonce than current valid nonce eg etherscan.io or my node though I've storaged them on physical DB.
This is an issue that many people have, and many people have provided answers for. In general, you have two main options here.
Keep track of your pending transactions yourself. As you are broadcasting transactions, you can just save them including their nonce. Then you can just look up transactions with
nonce
>=current valid nonce
.Query a full node with eth_pendingTransactions. You can then sort through these transactions to look for ones coming from your wallet. This is not foolproof, as the node may be missing some pending transactions, as its pending tx pool may be full, or it just has not seen all of your transactions yet.
if I don't fill a missing nonce to chain, will list txs be expired for a period time (how long) or they're storaged forever, if I wanna cancel them I must create self transaction with higher gas?
ETH transactions do not expire based on time. As long as they are valid in normal ways (i.e. nonce is valid, sender has enough ETH for gas), the transaction will continue to be valid. If you want to speed the transaction up, you can always create a new one with the same parameters but a higher gas price.
-
Thanks for your reply. So, my option is creating a schedule, which check nonce from node and redis, if they're diffrent, create a self transaction with nonce from node... is temporarily a suitable option at current time bro? I hope in the near future, Ethereum may have a feature to fix that soon and I'm very excited to wait. Thanks again and have a nice day.– mmo2112Oct 25, 2019 at 6:40