0

I am running two nodes on two different machines and geth installed, and for educational purposes I would like to make both nodes work concurrently. I know that nonce management is quite pain in the *** by default on only one machine, but I am very keen into implementing this with concurrency. Challenge on max level.

Problem I am trying to resolve is how to keep nonces synchronized between different nodes for an address 0x123 for example.

So I have to follow nonce per address. Giving that we are using address 0x123 for this example.

Step 1:

  • before doing transaction, query both nodes via rpc api, and get latest nonce number, and store(update) higher into centralized db for that address 0x123

State: Largest nonce from both nodes is 4. Updates db with 4.

Step 2:

  • Pending transactions - I do transaction on node A, with nonce 5, this is now pending transaction. This is stored in centralized location for Node A for account with address 0x123. Node A goes down.

State: Account Nonce 4, Node A Pending transaction nonce 5, Node B Pending transaction nonce is lower than Node A

Step 3:

  • I check health status of Node A, if node A is down, I resend pending transaction with Node B, taking larger pending transaction nonce number from both nodes, which in this case is Node A. Update Node B pending transaction for account 0x123.

State: Account Nonce 4, Node A Pending transaction nonce 5, Node B Pending transaction nonce 5

Step 4:

  • Whatever nodes pending transaction with nonce 5 goes first is winner, second node with already confirmed transaction nonce 5, won't go through.

So pretty much idea is to keep a track for nonce between different nodes. Is this viable option, or is there better and more robust way to do this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.