kwilteam / kwil-db

Kwil DB, the database for web3
https://www.kwil.com/
Other
33 stars 12 forks source link

mempool needs more acceptance checks #329

Closed jchappelow closed 12 months ago

jchappelow commented 1 year ago

CheckTx is the "Guardian of the mempool" (comet docs). This is the most likely attack vector on the p2p interface. Our current implementation of CheckTx is very minimal, and it will need more sophistication to prevent malicious users or peer node from flooding a node's mempool, causing resource exhaustion.

Mempool policy is unlike consensus in that node operators are free to accept or relay transactions however they see fit. We need to craft a more thorough mempool policy with DoS mitigation in mind.

CheckTx is also used to re-check all transactions that remain in mempool after a block is mined. It is critical to evict transactions that may become invalid. For instance, if a user submits a transaction with certain nonce, and then replaces it with another that gets mined, the first one should be evicted from mempool.

Related to https://github.com/kwilteam/kwil-db/issues/328.

A "mempool module" will likely be required to facilitate some or all of the checks. For instance, basic checks on an account's standing will be needed, particularly if gas may be disabled, since we do not simply want blocks to be filled by failed transactions at no cost to the attacker.

jchappelow commented 1 year ago

@charithabandi I made some comments on CheckTx in the branch where I'm working on https://github.com/kwilteam/kwil-db/issues/330

https://github.com/kwilteam/kwil-db/commit/5e44cea7011bd8eef3ed55b7c8c525a1e549cbc7

The PrepareProposal changes are completely WIP there, but wanted to link to thoughts on CheckTx.

jchappelow commented 1 year ago

Mempool module possible requirements

charithabandi commented 1 year ago

I think cometbft already handles the mempool size and purges or rejects transactions based on that. We probably don't need to handle it on the abci side. what do you think?

One other thing I can think of is, checking the block size constraints in the processProposal, especially if a proposer is adding its own transactions.

jchappelow commented 1 year ago

I think cometbft already handles the mempool size and purges or rejects transactions based on that. We probably don't need to handle it on the abci side. what do you think? Pretty sure we can punt on it for now, but how would it know what to purge? It doesn't know about gas or nonces, so it must be... oldest or newest? It might do something undesirable.

Yeah, I checked the code, it just ensures that each tx is within the configured limit, but not the block size. So it's on app to decide