From f2a0748d87fe2b25ce3bc68e1cfca98ceae47285 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Fri, 22 Apr 2022 18:12:31 +0800 Subject: [PATCH 1/3] fix: Update tip block number fetcher --- src/db.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/db.rs b/src/db.rs index fae9e6b..90cd4ed 100644 --- a/src/db.rs +++ b/src/db.rs @@ -71,6 +71,7 @@ pub fn get_syncer_tip_block_number() -> Result { let conn = &POOL.clone().get().expect("Mysql pool connection error"); check_infos .select(block_number) + .order(block_number.desc()) .first::(conn) .map_err(|e| { error!("Query block number error: {}", e.to_string()); From 29213578568d9a9c0bb7859369b3fe99cc16a1a5 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Wed, 4 May 2022 12:06:26 +0800 Subject: [PATCH 2/3] feat: Add lock to registry smt --- src/smt/entry.rs | 14 +++++++++++++- src/smt/smt.rs | 5 ++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/smt/entry.rs b/src/smt/entry.rs index a55023a..b59e665 100644 --- a/src/smt/entry.rs +++ b/src/smt/entry.rs @@ -1,5 +1,6 @@ use crate::db::check_lock_hashes_registered; use crate::error::Error; +use crate::indexer::index::get_registry_smt_root; use crate::smt::db::db::RocksDB; use crate::smt::smt::{generate_history_smt, RootSaver}; use crate::smt::transaction::store_transaction::StoreTransaction; @@ -9,7 +10,14 @@ use cota_smt::registry::{ CotaNFTRegistryEntriesBuilder, Registry, RegistryBuilder, RegistryVecBuilder, }; use cota_smt::smt::H256; +use lazy_static::lazy_static; use log::info; +use parking_lot::Mutex; +use std::sync::Arc; + +lazy_static! { + static ref SMT_LOCK: Arc> = Arc::new(Mutex::new(())); +} pub async fn generate_registry_smt( db: &RocksDB, @@ -28,12 +36,16 @@ pub async fn generate_registry_smt( previous_leaves.push((key, H256::zero())); } + let smt_root_opt = get_registry_smt_root().await?; + + let lock = SMT_LOCK.lock(); let transaction = StoreTransaction::new(db.transaction()); - let mut smt = generate_history_smt(&transaction).await?; + let mut smt = generate_history_smt(&transaction, smt_root_opt)?; smt.update_all(update_leaves.clone()) .expect("SMT update leave error"); smt.save_root_and_leaves(previous_leaves)?; transaction.commit()?; + drop(lock); let root_hash = hex::encode(smt.root().as_slice()); info!("registry_smt_root_hash: {:?}", root_hash); diff --git a/src/smt/smt.rs b/src/smt/smt.rs index 9d947b4..d952b76 100644 --- a/src/smt/smt.rs +++ b/src/smt/smt.rs @@ -1,6 +1,5 @@ use crate::db::get_registered_lock_hashes; use crate::error::Error; -use crate::indexer::index::get_registry_smt_root; use crate::smt::db::schema::{ COLUMN_SMT_BRANCH, COLUMN_SMT_LEAF, COLUMN_SMT_ROOT, COLUMN_SMT_TEMP_LEAVES, }; @@ -28,8 +27,9 @@ impl<'a> RootSaver for CotaSMT<'a> { } } -pub async fn generate_history_smt<'a>( +pub fn generate_history_smt<'a>( transaction: &'a StoreTransaction, + smt_root_opt: Option>, ) -> Result, Error> { let smt_store = SMTStore::new( COLUMN_SMT_LEAF, @@ -48,7 +48,6 @@ pub async fn generate_history_smt<'a>( if root == H256::zero() { return generate_mysql_smt(smt); } - let smt_root_opt = get_registry_smt_root().await?; debug!("registry cell smt root: {:?}", smt_root_opt,); if let Some(smt_root) = smt_root_opt { if smt_root.as_slice() == root.as_slice() { From 33f91e3f29fb88f84a0a7223a6b615eda7f1600a Mon Sep 17 00:00:00 2001 From: duanyytop Date: Wed, 4 May 2022 12:06:41 +0800 Subject: [PATCH 3/3] chore: Bump to v0.4.1 --- Cargo.lock | 86 ++++++++++++++++++++++++++++++++++++++++++++++++------ Cargo.toml | 3 +- 2 files changed, 79 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e400712..5acee8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,9 +45,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" @@ -532,7 +532,7 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "cota-registry-aggregator" -version = "0.4.0" +version = "0.4.1" dependencies = [ "chrono", "ckb-jsonrpc-types", @@ -549,6 +549,7 @@ dependencies = [ "lazy_static", "log", "molecule", + "parking_lot 0.12.0", "reqwest", "serde", "serde_json", @@ -1103,7 +1104,7 @@ dependencies = [ "jsonrpc-server-utils", "log", "net2", - "parking_lot", + "parking_lot 0.11.2", "unicase", ] @@ -1155,10 +1156,11 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" dependencies = [ + "autocfg", "scopeguard", ] @@ -1447,7 +1449,17 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api", - "parking_lot_core", + "parking_lot_core 0.8.5", +] + +[[package]] +name = "parking_lot" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" +dependencies = [ + "lock_api", + "parking_lot_core 0.9.3", ] [[package]] @@ -1464,6 +1476,19 @@ dependencies = [ "winapi", ] +[[package]] +name = "parking_lot_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall", + "smallvec", + "windows-sys", +] + [[package]] name = "peeking_take_while" version = "0.1.2" @@ -1531,7 +1556,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "545c5bc2b880973c9c10e4067418407a0ccaa3091781d1671d46eb35107cb26f" dependencies = [ "log", - "parking_lot", + "parking_lot 0.11.2", "scheduled-thread-pool", ] @@ -1681,7 +1706,7 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc6f74fd1204073fa02d5d5d68bec8021be4c38690b61264b2fdb48083d0e7d7" dependencies = [ - "parking_lot", + "parking_lot 0.11.2", ] [[package]] @@ -2162,6 +2187,49 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + [[package]] name = "winreg" version = "0.10.1" diff --git a/Cargo.toml b/Cargo.toml index e0d22ad..86adfc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cota-registry-aggregator" -version = "0.4.0" +version = "0.4.1" edition = "2018" [dependencies] @@ -20,6 +20,7 @@ serde = { version = "1.0", features = [ "derive" ] } sparse-merkle-tree = "0.5.3" ckb-types = "=0.101.8" ckb-jsonrpc-types = ">=0.103.0" +parking_lot = "0.12.0" reqwest = { version = "0.11", features = ["json"] } serde_json = "1.0" cota-smt = {package = "cota-smt", git = "https://github.com/nervina-labs/cota-smt", tag = "0.1.0"} \ No newline at end of file