[FEATURE] Prevent `SendMsgTx` from gossiping invalid transactions
Describe the feature you'd like
Currently SendTxMsg in controller/p2p.go doesn't do a mempool validation before sending out the transaction (called directly from the rpc server)
func (c *Controller) SendTxMsg(tx []byte) lib.ErrorI {
// create a transaction message object using the tx bytes and the chain id
msg := &lib.TxMessage{ChainId: c.Config.ChainId, Tx: tx}
// send it to self for de-duplication and awareness of self originated transactions
if err := c.P2P.SelfSend(c.PublicKey, Tx, msg); err != nil {
return err
}
// gossip to all the peers for the chain
return c.P2P.SendToPeers(Tx, msg)
}
The expected behavior is for invalid transactions originating from this node to be stopped before gossipped.
Motivation
- Unnecessary P2P bloat and CPU cycles used to stop invalid transactions
- Attacker could potentially used open RPCs to 'blast' transactions
Additional context
Invalid transactions are already stopped when the node is not the originator
Possible implementation
Instead of 'self sending' the transaction, call HandleTransaction directoy
Required Tags
- Priority: Medium
- Module: Controller
After a review of controller/p2p.go, transactions sent though P2P.SelfSend(Tx) are processed in ListenForTx which contains the required logic to prevent gossips on invalid transactions.
It appears though we need to remove the call to P2P.SendToPeers() here as it is already present in the above linked function.
Ah yes - that's a good and clean solution