tx-q: enable basic verification of local transactions (#11332)
* tx-q: basic verification of local transactions * miner: basic test for local import * miner: info log when rejecting local txn * Hernandofmt Co-Authored-By: Hernando Castano <HCastano@users.noreply.github.com> * miner: assert in a test with the concrete error type * tx-q: info! -> warn! on local tx rejection
This commit is contained in:
parent
63535860bc
commit
fd29926a21
@ -1695,6 +1695,30 @@ mod tests {
|
|||||||
assert_eq!(miner.prepare_pending_block(&client), BlockPreparationStatus::NotPrepared);
|
assert_eq!(miner.prepare_pending_block(&client), BlockPreparationStatus::NotPrepared);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_reject_local_transaction_with_invalid_chain_id() {
|
||||||
|
let spec = spec::new_test();
|
||||||
|
let miner = Miner::new_for_tests(&spec, None);
|
||||||
|
let client = TestBlockChainClient::default();
|
||||||
|
let chain_id = spec.chain_id();
|
||||||
|
|
||||||
|
// chain_id + 100500 is invalid
|
||||||
|
let import = miner.import_claimed_local_transaction(
|
||||||
|
&client,
|
||||||
|
PendingTransaction::new(transaction_with_chain_id(chain_id + 10500), None),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
assert_eq!(import, Err(transaction::Error::InvalidChainId));
|
||||||
|
|
||||||
|
// chain_id is valid
|
||||||
|
let import = miner.import_claimed_local_transaction(
|
||||||
|
&client,
|
||||||
|
PendingTransaction::new(transaction_with_chain_id(chain_id), None),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
assert_eq!(import, Ok(()));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_prioritize_locals() {
|
fn should_prioritize_locals() {
|
||||||
let client = TestBlockChainClient::default();
|
let client = TestBlockChainClient::default();
|
||||||
|
@ -139,7 +139,12 @@ impl<'a, C: 'a> pool::client::Client for PoolClient<'a, C> where
|
|||||||
self.chain.transaction_block(TransactionId::Hash(*hash)).is_some()
|
self.chain.transaction_block(TransactionId::Hash(*hash)).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_transaction(&self, tx: UnverifiedTransaction)-> Result<SignedTransaction, transaction::Error> {
|
fn verify_transaction_basic(&self, tx: &UnverifiedTransaction) -> Result<(), transaction::Error> {
|
||||||
|
self.engine.verify_transaction_basic(tx, &self.best_block_header)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn verify_transaction(&self, tx: UnverifiedTransaction) -> Result<SignedTransaction, transaction::Error> {
|
||||||
self.engine.verify_transaction_basic(&tx, &self.best_block_header)?;
|
self.engine.verify_transaction_basic(&tx, &self.best_block_header)?;
|
||||||
let tx = tx.verify_unordered()?;
|
let tx = tx.verify_unordered()?;
|
||||||
|
|
||||||
|
@ -50,6 +50,15 @@ pub trait Client: fmt::Debug + Sync {
|
|||||||
/// Is transaction with given hash already in the blockchain?
|
/// Is transaction with given hash already in the blockchain?
|
||||||
fn transaction_already_included(&self, hash: &H256) -> bool;
|
fn transaction_already_included(&self, hash: &H256) -> bool;
|
||||||
|
|
||||||
|
/// Perform basic/cheap transaction verification.
|
||||||
|
///
|
||||||
|
/// This should include all cheap checks that can be done before
|
||||||
|
/// actually checking the signature, like chain-replay protection.
|
||||||
|
///
|
||||||
|
/// This method is currently used only for verifying local transactions.
|
||||||
|
fn verify_transaction_basic(&self, t: &transaction::UnverifiedTransaction)
|
||||||
|
-> Result<(), transaction::Error>;
|
||||||
|
|
||||||
/// Structurarily verify given transaction.
|
/// Structurarily verify given transaction.
|
||||||
fn verify_transaction(&self, tx: transaction::UnverifiedTransaction)
|
fn verify_transaction(&self, tx: transaction::UnverifiedTransaction)
|
||||||
-> Result<transaction::SignedTransaction, transaction::Error>;
|
-> Result<transaction::SignedTransaction, transaction::Error>;
|
||||||
|
@ -103,6 +103,12 @@ impl pool::client::Client for TestClient {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn verify_transaction_basic(&self, _tx: &UnverifiedTransaction)
|
||||||
|
-> Result<(), transaction::Error>
|
||||||
|
{
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn verify_transaction(&self, tx: UnverifiedTransaction)
|
fn verify_transaction(&self, tx: UnverifiedTransaction)
|
||||||
-> Result<SignedTransaction, transaction::Error>
|
-> Result<SignedTransaction, transaction::Error>
|
||||||
{
|
{
|
||||||
|
@ -250,7 +250,13 @@ impl<C: Client> txpool::Verifier<Transaction> for Verifier<C, ::pool::scoring::N
|
|||||||
return Err(err)
|
return Err(err)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Transaction::Local(tx) => tx,
|
Transaction::Local(tx) => match self.client.verify_transaction_basic(&**tx) {
|
||||||
|
Ok(()) => tx,
|
||||||
|
Err(err) => {
|
||||||
|
warn!(target: "txqueue", "[{:?}] Rejected local tx {:?}", hash, err);
|
||||||
|
return Err(err)
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Verify RLP payload
|
// Verify RLP payload
|
||||||
|
Loading…
Reference in New Issue
Block a user