-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Verify transaction against its block during import #10954
Conversation
Have you measured the increased import time with this change? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think basic
verification should rather be performed before verify_signed
.
Also I would like to avoid using engine
directly and rather have client.verify_for_pending_block(&transaction, &open_block.header)
to keep the logic contained.
With the fix: Without fix: Only the time of the transactions' import to the block was measured. |
Are they different transactions? If yes, can you measure with the same txs? |
No, it was actually the same tx sent > 1000 times in the loop. curl --data '{"jsonrpc":"2.0","method":"personal_sendTransaction","params":[{"from":"0x004ec07d2329997267Ec62b4166639513386F32E","to":"0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e","value":"0xde0b6b3a7640000"}, "user"],"id":0}' -H "Content-Type: application/json" -X POST localhost:8540 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but I think we can simplify this even further.
ethcore/src/miner/pool_client.rs
Outdated
|
||
/// Verifies transaction against its block (before its import into this block) | ||
pub fn verify_for_pending_block(&self, transaction: &UnverifiedTransaction, header: &Header) -> Result<(), transaction::Error> { | ||
self.engine.machine().verify_transaction_basic(transaction, header) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not call verify_transaction
here as well (and verify against header
not best_block_header
)? So that we can actually simplify the miners code and perform only one check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't understand your suggestion. Which verify_transaction method do you mean? verify_transaction from machine doesn't call required verification methods. verify_transaction from pool client doesn't check against custom header, only for best block's
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry. I meant:
/// Verifies transaction against provided pending block header.
///
/// The check is performed before the transaction is imported into this block.
/// We also check any conditions that rely on chain status.
/// If you want to verify against chain's best block use `verify_signed`.
pub fn verify_for_pending_block(&self, transaction: &SignedTransaction, header: &Header) -> Result<(), transaction::Error> {
self.engine.machine().verify_transaction_basic(transaction, header)?;
self.engine.machine().verify_transaction(transaction, header, self.chain)?;
Ok(())
}
So that client.verify_for_pending_block
is the only method we call in the miner code:
let result = client.verify_for_pending_block(&transaction, &open_block.header)
.map_err(|e| e.into())
If verify_signed
is then not used anywhere after this change we should remove it.
My point is to have one single "verify" for the mining code exposed by PoolClient
abstraction, so that you don't need to know details about basic/signed verification and the order of checks performed (they can stay encapsulated in PoolClient
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Got it.
ethcore/src/miner/pool_client.rs
Outdated
|
||
self.verify_signed(&tx)?; | ||
|
||
self.verify_for_pending_block(&tx, &self.best_block_header)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, unfortunately we can't change the order here. basic
needs to be performed before verify_unordered
, otherwise we are risking a DoS attack vector.
Maybe just use engine.machine()
methods here directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
* master: Verify transaction against its block during import (#10954) [evmbin] fix compilation (#10976) Update to latest trie version. (#10972) [blooms-db] Fix benchmarks (#10974) Fix ethcore/benches build. (#10964) tx-pool: accept local tx with higher gas price when pool full (#10901) Disable unsyncable expanse chain (#10926)
* master: Extract the Engine trait (#10958) Better error message for rpc gas price errors (#10931) [.gitlab.yml] cargo check ethcore benches (#10965) Verify transaction against its block during import (#10954) [evmbin] fix compilation (#10976) Update to latest trie version. (#10972) [blooms-db] Fix benchmarks (#10974) Fix ethcore/benches build. (#10964) tx-pool: accept local tx with higher gas price when pool full (#10901) Disable unsyncable expanse chain (#10926)
* Verify transaction against its block during import * Client method for transaction verification added * Verification methods united * Verification sequence for transaction verifier returned
* Verify transaction against its block during import * Client method for transaction verification added * Verification methods united * Verification sequence for transaction verifier returned
* add more tx tests (#11038) * Fix parallel transactions race-condition (#10995) * Add blake2_f precompile (#11017) * [trace] introduce trace failed to Ext (#11019) * Edit publish-onchain.sh to use https (#11016) * Fix deadlock in network-devp2p (#11013) * EIP 1108: Reduce alt_bn128 precompile gas costs (#11008) * xDai chain support and nodes list update (#10989) * EIP 2028: transaction gas lowered from 68 to 16 (#10987) * EIP-1344 Add CHAINID op-code (#10983) * manual publish jobs for releases, no changes for nightlies (#10977) * [blooms-db] Fix benchmarks (#10974) * Verify transaction against its block during import (#10954) * Better error message for rpc gas price errors (#10931) * Fix fork choice (#10837) * Fix compilation on recent nightlies (#10991)
* add more tx tests (#11038) * Fix parallel transactions race-condition (#10995) * Add blake2_f precompile (#11017) * [trace] introduce trace failed to Ext (#11019) * Edit publish-onchain.sh to use https (#11016) * Fix deadlock in network-devp2p (#11013) * EIP 1108: Reduce alt_bn128 precompile gas costs (#11008) * xDai chain support and nodes list update (#10989) * EIP 2028: transaction gas lowered from 68 to 16 (#10987) * EIP-1344 Add CHAINID op-code (#10983) * manual publish jobs for releases, no changes for nightlies (#10977) * [blooms-db] Fix benchmarks (#10974) * Verify transaction against its block during import (#10954) * Better error message for rpc gas price errors (#10931) * tx-pool: accept local tx with higher gas price when pool full (#10901) * Fix fork choice (#10837) * Cleanup unused vm dependencies (#10787) * Fix compilation on recent nightlies (#10991)
Currently transaction's basic verification is not performed during its import from the pool (transaction's verify_basic method is not called).
As a result, incorrect transaction (for example, with incorrect chain id) can be added into the block and mined. Such blocks won't be accepted by other nodes (this transaction's verification will be called for the new block on other nodes). But incorrect block will stay on originator's node.
Solution: perform engine's verify_transaction_basic before adding transaction to the block during import (this will call transaction's verify_basic).
Drawback: this additional verification will increase import's time.
Closes #10411