git.delta.rocks / unique-network / refs/commits / 41df7418f56b

difftreelog

perf do not submit eth transactions with no logs

Yaroslav Bolyukin2021-05-04parent: #7994dd0.patch.diff
in: master

2 files changed

modifiedpallets/nft/src/eth/log.rsdiffbeforeafterboth
before · pallets/nft/src/eth/log.rs
1use pallet_evm::PrecompileLog;2use sp_std::cell::RefCell;3use sp_std::vec::Vec;4use sp_core::{H160, H256};56#[derive(Default)]7pub struct LogRecorder(RefCell<Vec<(Vec<H256>, Vec<u8>)>>);89impl LogRecorder {10    pub fn log(&self, topics: Vec<H256>, data: super::abi::AbiWriter) {11        self.0.borrow_mut().push((topics, data.finish()));12    }13    fn retrieve_logs(self) -> Vec<(Vec<H256>, Vec<u8>)> {14        self.0.replace(Vec::new())15    }16    pub fn retrieve_logs_for_contract(self, contract: H160) -> Vec<PrecompileLog> {17        // TODO: Remove reallocation18        self.retrieve_logs().into_iter()19            .map(|(topics, data)| PrecompileLog(contract.clone(), topics, data))20            .collect()21    }22}23impl Drop for LogRecorder {24    fn drop(&mut self) {25        #[cfg(feature = "std")]26        {27            // In debug mode, log recorder panics if dropped with logs left28            let logs = self.0.borrow();29            if !logs.is_empty() {30                eprintln!("Logs lost:");31                for line in logs.iter() {32                    eprintln!("{:?} {:?}", line.0, line.1);33                }34                panic!();35            }36        }37    }38}
after · pallets/nft/src/eth/log.rs
1use pallet_evm::PrecompileLog;2use sp_std::cell::RefCell;3use sp_std::vec::Vec;4use sp_core::{H160, H256};56#[derive(Default)]7pub struct LogRecorder(RefCell<Vec<(Vec<H256>, Vec<u8>)>>);89impl LogRecorder {10    pub fn is_empty(&self) -> bool {11        self.0.borrow().is_empty()12    }13    pub fn log(&self, topics: Vec<H256>, data: super::abi::AbiWriter) {14        self.0.borrow_mut().push((topics, data.finish()));15    }16    fn retrieve_logs(self) -> Vec<(Vec<H256>, Vec<u8>)> {17        self.0.replace(Vec::new())18    }19    pub fn retrieve_logs_for_contract(self, contract: H160) -> Vec<PrecompileLog> {20        // TODO: Remove reallocation21        self.retrieve_logs().into_iter()22            .map(|(topics, data)| PrecompileLog(contract.clone(), topics, data))23            .collect()24    }25}26impl Drop for LogRecorder {27    fn drop(&mut self) {28        #[cfg(feature = "std")]29        {30            // In debug mode, log recorder panics if dropped with logs left31            let logs = self.0.borrow();32            if !logs.is_empty() {33                eprintln!("Logs lost:");34                for line in logs.iter() {35                    eprintln!("{:?} {:?}", line.0, line.1);36                }37                panic!();38            }39        }40    }41}
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -2204,6 +2204,9 @@
     }
 
     fn submit_logs(collection: CollectionHandle<T>) -> DispatchResult {
+        if collection.logs.is_empty() {
+            return Ok(())
+        }
         T::EthereumTransactionSender::submit_logs_transaction(
             eth::generate_transaction(collection.id, T::EthereumChainId::get()),
             collection.logs.retrieve_logs_for_contract(eth::collection_id_to_address(collection.id)),