Skip to content

Commit

Permalink
fix: add use legacy tx
Browse files Browse the repository at this point in the history
  • Loading branch information
imotai committed Jul 28, 2023
1 parent 6ecd418 commit 51b5bad
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 45 deletions.
7 changes: 7 additions & 0 deletions src/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ pub enum DB3Command {
/// this is just for upgrade the node
#[clap(long, default_value = "100000")]
doc_id_start: i64,
/// use the legacy transaction format
#[clap(long, default_value = "false")]
use_legacy_tx: bool,
},

/// Start the data index node
Expand Down Expand Up @@ -241,6 +244,7 @@ impl DB3Command {
key_root_path,
admin_addr,
doc_id_start,
use_legacy_tx,
} => {
let log_level = if verbose {
LevelFilter::DEBUG
Expand All @@ -261,6 +265,7 @@ impl DB3Command {
key_root_path.as_str(),
admin_addr.as_str(),
doc_id_start,
use_legacy_tx,
)
.await;
let running = Arc::new(AtomicBool::new(true));
Expand Down Expand Up @@ -479,11 +484,13 @@ impl DB3Command {
key_root_path: &str,
admin_addr: &str,
doc_start_id: i64,
use_legacy_tx: bool,
) {
let listen_addr = format!("{bind_host}:{listening_port}");
let rollup_config = RollupExecutorConfig {
temp_data_path: rollup_data_path.to_string(),
key_root_path: key_root_path.to_string(),
use_legacy_tx,
};

let store_config = MutationStoreConfig {
Expand Down
1 change: 1 addition & 0 deletions src/node/src/node_test_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub mod tests {
let rollup_config = RollupExecutorConfig {
temp_data_path: format!("{real_path}/rollup_data_path"),
key_root_path: key_root_path.to_string(),
use_legacy_tx: false,
};
if let Err(_e) = std::fs::create_dir_all(rollup_config.temp_data_path.as_str()) {
println!("create dir error");
Expand Down
3 changes: 2 additions & 1 deletion src/node/src/recover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ impl Recover {
format!("0x{}", hex::encode(wallet.address().as_bytes()))
);
let meta_store = Arc::new(
MetaStoreClient::new(contract_addr.as_str(), evm_node_url.as_str(), wallet).await?,
MetaStoreClient::new(contract_addr.as_str(), evm_node_url.as_str(), wallet, false)
.await?,
);
let ar_fs_config = ArFileSystemConfig {
arweave_url: ar_node_url,
Expand Down
19 changes: 15 additions & 4 deletions src/node/src/rollup_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use tracing::{info, warn}; // Workaround to use prinltn! for logs.
pub struct RollupExecutorConfig {
pub temp_data_path: String,
pub key_root_path: String,
pub use_legacy_tx: bool,
}

pub struct RollupExecutor {
Expand Down Expand Up @@ -71,8 +72,13 @@ impl RollupExecutor {
let wallet = system_store.get_evm_wallet(c.chain_id)?;
let min_rollup_size = c.min_rollup_size;
let meta_store = ArcSwapOption::from(Some(Arc::new(
MetaStoreClient::new(c.contract_addr.as_str(), c.evm_node_url.as_str(), wallet)
.await?,
MetaStoreClient::new(
c.contract_addr.as_str(),
c.evm_node_url.as_str(),
wallet,
config.use_legacy_tx,
)
.await?,
)));
let ar_fs_config = ArFileSystemConfig {
arweave_url: c.ar_node_url.clone(),
Expand Down Expand Up @@ -134,8 +140,13 @@ impl RollupExecutor {
self.rollup_max_interval
.store(c.rollup_max_interval, Ordering::Relaxed);
let meta_store = Some(Arc::new(
MetaStoreClient::new(c.contract_addr.as_str(), c.evm_node_url.as_str(), wallet)
.await?,
MetaStoreClient::new(
c.contract_addr.as_str(),
c.evm_node_url.as_str(),
wallet,
self.config.use_legacy_tx,
)
.await?,
));
self.min_gc_round_offset
.store(c.min_gc_offset, Ordering::Relaxed);
Expand Down
1 change: 1 addition & 0 deletions src/node/src/storage_node_light_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ mod tests {
let rollup_config = RollupExecutorConfig {
temp_data_path: format!("{real_path}/data_path"),
key_root_path: format!("{real_path}/keys"),
use_legacy_tx: false,
};

let system_store_config = SystemStoreConfig {
Expand Down
101 changes: 62 additions & 39 deletions src/storage/src/meta_store_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ abigen!(Events, "abi/Events.json");
pub struct MetaStoreClient {
address: Address,
client: Arc<SignerMiddleware<Arc<NonceManagerMiddleware<Provider<Ws>>>, LocalWallet>>,
use_legacy_tx: bool,
}

unsafe impl Sync for MetaStoreClient {}
unsafe impl Send for MetaStoreClient {}

impl MetaStoreClient {
pub async fn new(contract_addr: &str, rpc_url: &str, wallet: LocalWallet) -> Result<Self> {
pub async fn new(
contract_addr: &str,
rpc_url: &str,
wallet: LocalWallet,
use_legacy_tx: bool,
) -> Result<Self> {
let address = contract_addr
.parse::<Address>()
.map_err(|_| DB3Error::InvalidAddress)?;
Expand All @@ -51,7 +57,11 @@ impl MetaStoreClient {
let provider_arc = Arc::new(provider);
let signable_client = SignerMiddleware::new(provider_arc, wallet);
let client = Arc::new(signable_client);
Ok(Self { address, client })
Ok(Self {
address,
client,
use_legacy_tx,
})
}

pub async fn register_data_network(
Expand All @@ -74,9 +84,18 @@ impl MetaStoreClient {
empty_index_addresses,
desc,
);
tx.send()
.await
.map_err(|e| DB3Error::StoreEventError(format!("fail to register data network {e}")))?;
match self.use_legacy_tx {
true => {
tx.legacy().send().await.map_err(|e| {
DB3Error::StoreEventError(format!("fail to register data network {e}"))
})?;
}
false => {
tx.send().await.map_err(|e| {
DB3Error::StoreEventError(format!("fail to register data network {e}"))
})?;
}
}
Ok(())
}

Expand All @@ -89,12 +108,25 @@ impl MetaStoreClient {
let mut desc_bytes32: [u8; 32] = Default::default();
desc_bytes32[..desc_bytes.len()].clone_from_slice(desc_bytes);
let tx = store.create_doc_database(network.into(), desc_bytes32);
let pending_tx = tx.send().await.map_err(|e| {
DB3Error::StoreEventError(format!(
"fail to send create doc database request with error {e}"
))
})?;
let tx_hash = pending_tx.tx_hash();
let tx_hash = match self.use_legacy_tx {
true => {
let tx = tx.legacy();
let pending_tx = tx.send().await.map_err(|e| {
DB3Error::StoreEventError(format!(
"fail to send create doc database request with error {e}"
))
})?;
pending_tx.tx_hash()
}
false => {
let pending_tx = tx.send().await.map_err(|e| {
DB3Error::StoreEventError(format!(
"fail to send create doc database request with error {e}"
))
})?;
pending_tx.tx_hash()
}
};
let mut count_down: i32 = 5;
loop {
if count_down <= 0 {
Expand Down Expand Up @@ -160,11 +192,25 @@ impl MetaStoreClient {
ar_tx, network
);
let tx = store.update_rollup_steps(network_id, ar_tx_binary);
//TODO set gas limit
let pending_tx = tx.send().await.map_err(|e| {
DB3Error::StoreEventError(format!("fail to send update rollup request with error {e}"))
})?;
let tx_hash = pending_tx.tx_hash();
let tx_hash = match self.use_legacy_tx {
true => {
let tx = tx.legacy();
let pending_tx = tx.send().await.map_err(|e| {
DB3Error::StoreEventError(format!(
"fail to send create doc database request with error {e}"
))
})?;
pending_tx.tx_hash()
}
false => {
let pending_tx = tx.send().await.map_err(|e| {
DB3Error::StoreEventError(format!(
"fail to send create doc database request with error {e}"
))
})?;
pending_tx.tx_hash()
}
};
info!("update rollup step done! tx hash: {}", tx_hash);
let mut count_down: i32 = 5;
loop {
Expand Down Expand Up @@ -197,29 +243,6 @@ mod tests {
use fastcrypto::encoding::{Base64, Encoding};
use tokio::time::{sleep, Duration as TokioDuration};

#[tokio::test]
async fn register_scroll_data_network() {
let data = hex::decode("ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
.unwrap();
let data_ref: &[u8] = data.as_ref();
let wallet = LocalWallet::from_bytes(data_ref).unwrap();
let wallet = wallet.with_chain_id(31337_u32);
let rollup_node_address = wallet.address();
let contract_addr = "0x5fbdb2315678afecb367f032d93f642f64180aa3";
let rpc_url = "ws://127.0.0.1:8545";
sleep(TokioDuration::from_millis(10 * 1000)).await;
let client = MetaStoreClient::new(contract_addr, rpc_url, wallet)
.await
.unwrap();
let result = client
.register_data_network(&rollup_node_address, rpc_url)
.await;
assert!(result.is_ok(), "register data network failed {:?}", result);
sleep(TokioDuration::from_millis(5 * 1000)).await;


}

#[tokio::test]
async fn register_no1_data_network() {
let data = hex::decode("ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
Expand Down

0 comments on commit 51b5bad

Please sign in to comment.