libplanet icon indicating copy to clipboard operation
libplanet copied to clipboard

`IStore.GetTxNonce()` returns the next tx nonce candidate

Open greymistcube opened this issue 2 years ago • 1 comments

IStore being an interface for storing BlockChain<T>, Block<T>, and Transaction<T>s, I'd say the most intuitive expectation of IStore.GetTxNonce(Guid, Address)'s return value would be the highest nonce associated with the given Address stored in IStore.

However, the current implementation actually stores the nonce that is one higher than the highest Transaction<T> nonce included in a chain, and returns that value. This means, IStore.GetTxNonce() returns the next expected nonce that is allowed for a Transaction<T> to have to be included in the BlockChain<T>. In that sense, the name IStore.GetTxNonce() seems to be a red herring.

Personally, I see two problems:

  • IStore storing the "next expected nonce" for Addresses.
  • IStore.GetTxNonce()'s name (or its behavior)

The latter can be easily dealt with without changing the internal data by simply reducing the returned value to be less by value of $1$. On the other hand, if we also want to fix the former, some form of migration would be needed.

greymistcube avatar Feb 24 '23 06:02 greymistcube

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

stale[bot] avatar May 22 '23 00:05 stale[bot]