Skip to content

Commit c6f9c41

Browse files
authored
Fix/fix scroll call contract bug (#590)
* feat: add doc store * fix: add test case * fix: add use legacy tx * fix: update the readme * fix: fix the metastore case
1 parent ddbe612 commit c6f9c41

File tree

8 files changed

+103
-29
lines changed

8 files changed

+103
-29
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,19 @@ if you have any questions, please feel free to ask us for help and you can find
8383
* the doc about [queryDoc](https://docs.db3.network/functions/queryDoc.html)
8484

8585

86-
# Try Our Cloud Sandbox
86+
# Try the testnet
8787

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

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

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

98+
9699
# How it works
97100

98101
The DB3 Network has two roles:

src/node/src/command.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ pub enum DB3Command {
104104
/// this is just for upgrade the node
105105
#[clap(long, default_value = "100000")]
106106
doc_id_start: i64,
107+
/// use the legacy transaction format
108+
#[clap(long, default_value = "false")]
109+
use_legacy_tx: bool,
107110
},
108111

109112
/// Start the data index node
@@ -241,6 +244,7 @@ impl DB3Command {
241244
key_root_path,
242245
admin_addr,
243246
doc_id_start,
247+
use_legacy_tx,
244248
} => {
245249
let log_level = if verbose {
246250
LevelFilter::DEBUG
@@ -261,6 +265,7 @@ impl DB3Command {
261265
key_root_path.as_str(),
262266
admin_addr.as_str(),
263267
doc_id_start,
268+
use_legacy_tx,
264269
)
265270
.await;
266271
let running = Arc::new(AtomicBool::new(true));
@@ -479,11 +484,13 @@ impl DB3Command {
479484
key_root_path: &str,
480485
admin_addr: &str,
481486
doc_start_id: i64,
487+
use_legacy_tx: bool,
482488
) {
483489
let listen_addr = format!("{bind_host}:{listening_port}");
484490
let rollup_config = RollupExecutorConfig {
485491
temp_data_path: rollup_data_path.to_string(),
486492
key_root_path: key_root_path.to_string(),
493+
use_legacy_tx,
487494
};
488495

489496
let store_config = MutationStoreConfig {

src/node/src/node_test_base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub mod tests {
5959
let rollup_config = RollupExecutorConfig {
6060
temp_data_path: format!("{real_path}/rollup_data_path"),
6161
key_root_path: key_root_path.to_string(),
62+
use_legacy_tx: false,
6263
};
6364
if let Err(_e) = std::fs::create_dir_all(rollup_config.temp_data_path.as_str()) {
6465
println!("create dir error");

src/node/src/recover.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ impl Recover {
6969
format!("0x{}", hex::encode(wallet.address().as_bytes()))
7070
);
7171
let meta_store = Arc::new(
72-
MetaStoreClient::new(contract_addr.as_str(), evm_node_url.as_str(), wallet).await?,
72+
MetaStoreClient::new(contract_addr.as_str(), evm_node_url.as_str(), wallet, false)
73+
.await?,
7374
);
7475
let ar_fs_config = ArFileSystemConfig {
7576
arweave_url: ar_node_url,

src/node/src/rollup_executor.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use tracing::{info, warn}; // Workaround to use prinltn! for logs.
3636
pub struct RollupExecutorConfig {
3737
pub temp_data_path: String,
3838
pub key_root_path: String,
39+
pub use_legacy_tx: bool,
3940
}
4041

4142
pub struct RollupExecutor {
@@ -71,8 +72,13 @@ impl RollupExecutor {
7172
let wallet = system_store.get_evm_wallet(c.chain_id)?;
7273
let min_rollup_size = c.min_rollup_size;
7374
let meta_store = ArcSwapOption::from(Some(Arc::new(
74-
MetaStoreClient::new(c.contract_addr.as_str(), c.evm_node_url.as_str(), wallet)
75-
.await?,
75+
MetaStoreClient::new(
76+
c.contract_addr.as_str(),
77+
c.evm_node_url.as_str(),
78+
wallet,
79+
config.use_legacy_tx,
80+
)
81+
.await?,
7682
)));
7783
let ar_fs_config = ArFileSystemConfig {
7884
arweave_url: c.ar_node_url.clone(),
@@ -134,8 +140,13 @@ impl RollupExecutor {
134140
self.rollup_max_interval
135141
.store(c.rollup_max_interval, Ordering::Relaxed);
136142
let meta_store = Some(Arc::new(
137-
MetaStoreClient::new(c.contract_addr.as_str(), c.evm_node_url.as_str(), wallet)
138-
.await?,
143+
MetaStoreClient::new(
144+
c.contract_addr.as_str(),
145+
c.evm_node_url.as_str(),
146+
wallet,
147+
self.config.use_legacy_tx,
148+
)
149+
.await?,
139150
));
140151
self.min_gc_round_offset
141152
.store(c.min_gc_offset, Ordering::Relaxed);
@@ -303,10 +314,12 @@ impl RollupExecutor {
303314
network_id,
304315
)
305316
.await?;
317+
306318
let (evm_cost, tx_hash) = meta_store
307319
.update_rollup_step(id.as_str(), network_id)
308320
.await?;
309321
let tx_str = format!("0x{}", hex::encode(tx_hash.as_bytes()));
322+
310323
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(),
311324
id.as_str(), reward,
312325
tx_str.as_str(),

src/node/src/storage_node_light_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ mod tests {
718718
let rollup_config = RollupExecutorConfig {
719719
temp_data_path: format!("{real_path}/data_path"),
720720
key_root_path: format!("{real_path}/keys"),
721+
use_legacy_tx: false,
721722
};
722723

723724
let system_store_config = SystemStoreConfig {

src/storage/src/meta_store_client.rs

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,19 @@ abigen!(Events, "abi/Events.json");
3434
pub struct MetaStoreClient {
3535
address: Address,
3636
client: Arc<SignerMiddleware<Arc<NonceManagerMiddleware<Provider<Ws>>>, LocalWallet>>,
37+
use_legacy_tx: bool,
3738
}
3839

3940
unsafe impl Sync for MetaStoreClient {}
4041
unsafe impl Send for MetaStoreClient {}
4142

4243
impl MetaStoreClient {
43-
pub async fn new(contract_addr: &str, rpc_url: &str, wallet: LocalWallet) -> Result<Self> {
44+
pub async fn new(
45+
contract_addr: &str,
46+
rpc_url: &str,
47+
wallet: LocalWallet,
48+
use_legacy_tx: bool,
49+
) -> Result<Self> {
4450
let address = contract_addr
4551
.parse::<Address>()
4652
.map_err(|_| DB3Error::InvalidAddress)?;
@@ -51,7 +57,11 @@ impl MetaStoreClient {
5157
let provider_arc = Arc::new(provider);
5258
let signable_client = SignerMiddleware::new(provider_arc, wallet);
5359
let client = Arc::new(signable_client);
54-
Ok(Self { address, client })
60+
Ok(Self {
61+
address,
62+
client,
63+
use_legacy_tx,
64+
})
5565
}
5666

5767
pub async fn register_data_network(
@@ -74,11 +84,21 @@ impl MetaStoreClient {
7484
empty_index_addresses,
7585
desc,
7686
);
77-
tx.send()
78-
.await
79-
.map_err(|e| DB3Error::StoreEventError(format!("fail to register data network {e}")))?;
87+
match self.use_legacy_tx {
88+
true => {
89+
tx.legacy().send().await.map_err(|e| {
90+
DB3Error::StoreEventError(format!("fail to register data network {e}"))
91+
})?;
92+
}
93+
false => {
94+
tx.send().await.map_err(|e| {
95+
DB3Error::StoreEventError(format!("fail to register data network {e}"))
96+
})?;
97+
}
98+
}
8099
Ok(())
81100
}
101+
82102
pub async fn create_database(&self, network: u64, desc: &str) -> Result<(U256, TxHash)> {
83103
let store = DB3MetaStore::new(self.address, self.client.clone());
84104
let desc_bytes = desc.as_bytes();
@@ -88,12 +108,25 @@ impl MetaStoreClient {
88108
let mut desc_bytes32: [u8; 32] = Default::default();
89109
desc_bytes32[..desc_bytes.len()].clone_from_slice(desc_bytes);
90110
let tx = store.create_doc_database(network.into(), desc_bytes32);
91-
let pending_tx = tx.send().await.map_err(|e| {
92-
DB3Error::StoreEventError(format!(
93-
"fail to send create doc database request with error {e}"
94-
))
95-
})?;
96-
let tx_hash = pending_tx.tx_hash();
111+
let tx_hash = match self.use_legacy_tx {
112+
true => {
113+
let tx = tx.legacy();
114+
let pending_tx = tx.send().await.map_err(|e| {
115+
DB3Error::StoreEventError(format!(
116+
"fail to send create doc database request with error {e}"
117+
))
118+
})?;
119+
pending_tx.tx_hash()
120+
}
121+
false => {
122+
let pending_tx = tx.send().await.map_err(|e| {
123+
DB3Error::StoreEventError(format!(
124+
"fail to send create doc database request with error {e}"
125+
))
126+
})?;
127+
pending_tx.tx_hash()
128+
}
129+
};
97130
let mut count_down: i32 = 5;
98131
loop {
99132
if count_down <= 0 {
@@ -159,11 +192,25 @@ impl MetaStoreClient {
159192
ar_tx, network
160193
);
161194
let tx = store.update_rollup_steps(network_id, ar_tx_binary);
162-
//TODO set gas limit
163-
let pending_tx = tx.send().await.map_err(|e| {
164-
DB3Error::StoreEventError(format!("fail to send update rollup request with error {e}"))
165-
})?;
166-
let tx_hash = pending_tx.tx_hash();
195+
let tx_hash = match self.use_legacy_tx {
196+
true => {
197+
let tx = tx.legacy();
198+
let pending_tx = tx.send().await.map_err(|e| {
199+
DB3Error::StoreEventError(format!(
200+
"fail to send create doc database request with error {e}"
201+
))
202+
})?;
203+
pending_tx.tx_hash()
204+
}
205+
false => {
206+
let pending_tx = tx.send().await.map_err(|e| {
207+
DB3Error::StoreEventError(format!(
208+
"fail to send create doc database request with error {e}"
209+
))
210+
})?;
211+
pending_tx.tx_hash()
212+
}
213+
};
167214
info!("update rollup step done! tx hash: {}", tx_hash);
168215
let mut count_down: i32 = 5;
169216
loop {
@@ -195,6 +242,7 @@ mod tests {
195242
use super::*;
196243
use fastcrypto::encoding::{Base64, Encoding};
197244
use tokio::time::{sleep, Duration as TokioDuration};
245+
198246
#[tokio::test]
199247
async fn register_no1_data_network() {
200248
let data = hex::decode("ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
@@ -206,7 +254,7 @@ mod tests {
206254
let contract_addr = "0x5fbdb2315678afecb367f032d93f642f64180aa3";
207255
let rpc_url = "ws://127.0.0.1:8545";
208256
sleep(TokioDuration::from_millis(10 * 1000)).await;
209-
let client = MetaStoreClient::new(contract_addr, rpc_url, wallet)
257+
let client = MetaStoreClient::new(contract_addr, rpc_url, wallet, false)
210258
.await
211259
.unwrap();
212260
let result = client
@@ -226,7 +274,7 @@ mod tests {
226274
let rollup_node_address = wallet.address();
227275
let contract_addr = "0x5FbDB2315678afecb367f032d93F642f64180aa3";
228276
let rpc_url = "ws://127.0.0.1:8545";
229-
let client = MetaStoreClient::new(contract_addr, rpc_url, wallet)
277+
let client = MetaStoreClient::new(contract_addr, rpc_url, wallet, false)
230278
.await
231279
.unwrap();
232280
let result = client

0 commit comments

Comments
 (0)