Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/fix scroll call contract bug #590

Merged
merged 28 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3c03fd0
feat: add doc store
imotai Jun 13, 2023
bf6b69b
Merge remote-tracking branch 'origin/main'
imotai Jun 14, 2023
50dd93a
Merge remote-tracking branch 'origin/main'
imotai Jun 19, 2023
99d8aad
Merge remote-tracking branch 'origin/main'
imotai Jun 21, 2023
ea84758
Merge remote-tracking branch 'origin/main'
imotai Jun 23, 2023
3dc6d3a
Merge remote-tracking branch 'origin/main'
imotai Jun 25, 2023
954d205
Merge remote-tracking branch 'origin/main'
imotai Jun 26, 2023
a70c835
Merge remote-tracking branch 'origin/main'
imotai Jun 29, 2023
4da2934
Merge remote-tracking branch 'origin/main'
imotai Jun 29, 2023
e2938c9
Merge remote-tracking branch 'origin/main'
imotai Jul 2, 2023
afaaa0c
Merge remote-tracking branch 'origin/main'
imotai Jul 3, 2023
3851509
Merge remote-tracking branch 'origin/main'
imotai Jul 4, 2023
20e1d28
Merge remote-tracking branch 'origin/main'
imotai Jul 4, 2023
7d74a39
Merge remote-tracking branch 'origin/main'
imotai Jul 8, 2023
e1d65c8
Merge remote-tracking branch 'origin/main'
imotai Jul 9, 2023
f55f1b8
Merge remote-tracking branch 'origin/main'
imotai Jul 11, 2023
73ac492
Merge remote-tracking branch 'origin/main'
imotai Jul 17, 2023
4ea9ea2
Merge remote-tracking branch 'origin/main'
imotai Jul 20, 2023
6d4dae2
Merge remote-tracking branch 'origin/main'
imotai Jul 20, 2023
a03b34f
Merge remote-tracking branch 'origin/main'
imotai Jul 21, 2023
a991f2c
Merge remote-tracking branch 'origin/main'
imotai Jul 24, 2023
072c1bf
Merge remote-tracking branch 'origin/main'
imotai Jul 28, 2023
1b14371
fix: add test case
imotai Jul 28, 2023
6ecd418
Merge remote-tracking branch 'origin/main' into fix/fix_scroll_call_c…
imotai Jul 28, 2023
51b5bad
fix: add use legacy tx
imotai Jul 28, 2023
b7cf3fc
fix: update the readme
imotai Jul 28, 2023
528aaec
fix: merge from main
imotai Jul 28, 2023
34abedf
fix: fix the metastore case
imotai Jul 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,19 @@ if you have any questions, please feel free to ask us for help and you can find
* the doc about [queryDoc](https://docs.db3.network/functions/queryDoc.html)


# Try Our Cloud Sandbox
# Try the testnet

* [Console](https://console.cloud.db3.network/console/home):https://console.cloud.db3.network/console/home
* Data Rollup Node: https://rollup.cloud.db3.network
* Data Index Node: https://index.cloud.db3.network

You can connect to the Data Rollup Node and Data Index Node with db3.js
| Public Chains | Testnet | Mainnet |
|----------|:-------------:|:------:|
| zksync |data rollup node:`https://zksync.rollup.testnet.db3.network` <br> data index node:`https://zksync.index.testnet.db3.network` | :soon: |
| scroll |data rollup node:`https://scroll.rollup.testnet.db3.network` <br> data index node:`https://scroll.index.testnet.db3.network` | :soon: |


You can connect to the Data Rollup Node and Data Index Node with db3.js
Note: the cloud sandbox is just for testing and unstable


# How it works

The DB3 Network has two roles:
Expand Down
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
21 changes: 17 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 Expand Up @@ -303,10 +314,12 @@ impl RollupExecutor {
network_id,
)
.await?;

let (evm_cost, tx_hash) = meta_store
.update_rollup_step(id.as_str(), network_id)
.await?;
let tx_str = format!("0x{}", hex::encode(tx_hash.as_bytes()));

info!("the process rollup done with num mutations {num_rows}, raw data size {memory_size}, compress data size {size} and processed time {} id {} ar cost {} and evm tx {} and cost {}", now.elapsed().as_secs(),
id.as_str(), reward,
tx_str.as_str(),
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
84 changes: 66 additions & 18 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,11 +84,21 @@ 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(())
}

pub async fn create_database(&self, network: u64, desc: &str) -> Result<(U256, TxHash)> {
let store = DB3MetaStore::new(self.address, self.client.clone());
let desc_bytes = desc.as_bytes();
Expand All @@ -88,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 @@ -159,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 @@ -195,6 +242,7 @@ mod tests {
use super::*;
use fastcrypto::encoding::{Base64, Encoding};
use tokio::time::{sleep, Duration as TokioDuration};

#[tokio::test]
async fn register_no1_data_network() {
let data = hex::decode("ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
Expand All @@ -206,7 +254,7 @@ mod tests {
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)
let client = MetaStoreClient::new(contract_addr, rpc_url, wallet, false)
.await
.unwrap();
let result = client
Expand All @@ -226,7 +274,7 @@ mod tests {
let rollup_node_address = wallet.address();
let contract_addr = "0x5FbDB2315678afecb367f032d93F642f64180aa3";
let rpc_url = "ws://127.0.0.1:8545";
let client = MetaStoreClient::new(contract_addr, rpc_url, wallet)
let client = MetaStoreClient::new(contract_addr, rpc_url, wallet, false)
.await
.unwrap();
let result = client
Expand Down
Loading