ziesha-network / bazuka

Rust implementation of Ziesha protocol

Home Page:https://ziesha.network

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow tx-sender to try his transaction before putting it in the mempool

keyvank opened this issue · comments

Currently, when you send a tx with bazuka wallet ... command, the transaction is sent and propagated through the network even if the tx is obviously invalid (Balance insufficiency/Invalid nonces/etc) and cannot be applied. The network will not process any transactions (Even if valid) coming after the faulty transactions because of the invalid nonces.
The problem can be partially solved if we query the server regarding validity of the transaction before actually putting it in the mempool. We will need a new API endpoint: GET /bincode/transact/check

These message types:

struct CheckTransactionRequest {
  pub tx_delta: TransactionAndDelta
}
struct CheckTransactionResponse {
  pub error: Option<String>
}

A new function fn check_tx(&self, tx: Transaction) -> Result<(), BlockchainError>; should be added to Blockchain trait, which will just apply_tx(&tx)? in an isolated environment and will propagate error if there is any.

All CLI commands that create txs (bazuka wallet send, bazuka wallet new-token, bazuka wallet register-validator, ...), should first check validity of tx through this API call and send the transaction only if there is no error.