Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tx status in mempool #1287

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

ninabarbakadze
Copy link
Member

@ninabarbakadze ninabarbakadze commented Apr 5, 2024

Description

Fixes #1281

Opens #1381

@ninabarbakadze ninabarbakadze marked this pull request as ready for review June 6, 2024 15:55
@ninabarbakadze ninabarbakadze requested a review from a team as a code owner June 6, 2024 15:55
@ninabarbakadze ninabarbakadze requested review from ramin, evan-forbes and cmwaters and removed request for a team and ramin June 6, 2024 15:55
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Suggestions were mostly optional comment improvements

Comment on lines 19 to 20
// Push adds the given raw transaction to the cache and returns true if it was
// newly added. Otherwise, it returns false.
Copy link
Collaborator

@rootulp rootulp Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Push adds the given raw transaction to the cache and returns true if it was
// newly added. Otherwise, it returns false.
// Push adds the given tx key to the cache and returns true if it was
// newly added. Otherwise, it returns false.

@@ -18,14 +18,14 @@ type TxCache interface {

// Push adds the given raw transaction to the cache and returns true if it was
// newly added. Otherwise, it returns false.
Push(tx types.Tx) bool
Push(tx types.TxKey) bool

// Remove removes the given raw transaction from the cache.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Remove removes the given raw transaction from the cache.
// Remove removes the given tx key from the cache.

Comment on lines 26 to 27
// Has reports whether tx is present in the cache. Checking for presence is
// not treated as an access of the value.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Has reports whether tx is present in the cache. Checking for presence is
// not treated as an access of the value.
// Has reports whether tx key is present in the cache. Checking for presence is
// not treated as an access of the value.

Comment on lines -92 to 91
key := tx.Key()
func (c *LRUTxCache) Remove(key types.TxKey) {
c.RemoveTxByKey(key)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question] Remove is now redundant with RemoveTxByKey. Should we remove one of them?

wtx := txmp.store.get(txKey)
if wtx != nil {
return wtx.tx, true
}
return types.Tx{}, false
}

// GetTxEvicted returns a bool indicating whether the transaction with
// the specified key was recently evicted and is currently within the cache
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// the specified key was recently evicted and is currently within the cache
// the specified key was recently evicted and is currently within the cache.

@@ -183,6 +183,16 @@ func (mem *CListMempool) TxsFront() *clist.CElement {
return mem.txs.Front()
}

// GetTxByKey currently not enabled in v0 but it is required by the interface.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// GetTxByKey currently not enabled in v0 but it is required by the interface.
// GetTxByKey is not supported by the v0 mempool but it is required to satisfy the mempool interface.

return nil, false
}

// GetTxEvicted currently not enabled in v0 but it is required by the interface.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// GetTxEvicted currently not enabled in v0 but it is required by the interface.
// GetTxEvicted is not supported by the v0 mempool but it is required to satisfy the mempool interface.

}

// GetTxEvicted returns a bool indicating whether the transaction with
// the specified key was recently evicted and is currently within the cache
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// the specified key was recently evicted and is currently within the cache
// the specified key was recently evicted and is currently within the cache.


// TxStatus retrieves the status of a transaction given its hash. It returns a ResultTxStatus
// containing the height and index of the transaction within the block(if committed)
// or whether the transaction is pending, evicted in the mempool otherwise unknown.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// or whether the transaction is pending, evicted in the mempool otherwise unknown.
// or whether the transaction is pending, evicted from the mempool, or otherwise unknown.

Comment on lines +26 to +42
return &ctypes.ResultTxStatus{Status: "PENDING"}, nil
}

// Check if the tx is evicted
isEvicted := env.Mempool.GetTxEvicted(txKey)
if isEvicted {
return &ctypes.ResultTxStatus{Status: "EVICTED"}, nil
}

// Check if the tx has been committed
txInfo := env.BlockStore.LoadTxInfo(hash)
if txInfo != nil {
return &ctypes.ResultTxStatus{Height: txInfo.Height, Index: txInfo.Index, Status: "COMMITTED"}, nil
}

// If the tx is not in the mempool, evicted, or committed, return unknown
return &ctypes.ResultTxStatus{Status: "UNKNOWN"}, nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question] should we extract consts for PENDING, EVICTED, COMMITTED, and UNKNOWN?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide the current status of a transaction for clients
3 participants