Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

Commit a9535bc

Browse files
author
Eason Gao
authored
docs(config): add the document of config instruction (#302)
* docs: add config instrcution * update README * update README * follow review opinion * refactor move machine id to db config * fix page * remove useless test * cargo clippy
1 parent 0bd65a6 commit a9535bc

File tree

12 files changed

+228
-82
lines changed

12 files changed

+228
-82
lines changed

README.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Mercury
2+
13
## About Mercury
24

35
Mercury is a tool that handles application development on [CKB](https://github.com/nervosnetwork/ckb).
@@ -50,13 +52,18 @@ If you want to use Mercury in a production project, please deploy and run Mercur
5052
- Step 1. Run a CKB node. If you already have a running node, skip this step.
5153
- run a [mainnet node](https://docs.nervos.org/docs/basics/guides/mainnet)
5254
- run a [testnet node](https://docs.nervos.org/docs/basics/guides/testnet)
53-
- Step 2. Edit `mainnet_config.toml` or `testnet_config.toml` respectively. These config files are located in `./devtools/config/`.
55+
56+
- Step 2. Edit `mainnet_config.toml` or `testnet_config.toml` according to mainnet or testnet. These config files are located in `./devtools/config/`. The instrcution of config file is [here](docs/config.md).
57+
5458
- Step 3. Download the latest version of Mercury from the [release page](https://github.com/nervosnetwork/Mercury/releases).
59+
5560
- Step 4. Run Mercury.
61+
5662
```shell
57-
## mainnet
63+
# mainnet
5864
$ Mercury -c devtools/config/mainnet_config.toml run
59-
## testnet
65+
66+
# testnet
6067
$ Mercury -c devtools/config/testnet_config.toml run
6168
```
6269

@@ -89,14 +96,17 @@ environment:
8996
```
9097
9198
- Step 3. Build Mercury images from the Dockerfile.
99+
92100
```shell
93101
$ docker build -t Mercury .
94102
```
95103

96104
- Step 4. Run Mercury via docker.
105+
97106
```shell
98107
$ docker-compose up -d
99108
```
109+
100110
or
101111

102112
```shell
@@ -131,5 +141,5 @@ The `Mercury` crate's minimum supported rust version is 1.55.0.
131141

132142
## Documentations
133143

134-
- [Mercury API Documentation](https://github.com/nervosnetwork/Mercury/blob/main/core/rpc/README.md)
135-
144+
- [Mercury API Documentation](core/rpc/README.md)
145+
- [Mercury Config Documentation](docs/config.md)

common/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ impl PaginationRequest {
209209
}
210210
}
211211

212+
pub fn set_order(mut self, order: Order) -> Self {
213+
self.order = order;
214+
self
215+
}
216+
212217
pub fn set_limit(mut self, limit: Option<u64>) -> Self {
213218
self.limit = limit;
214219
self

common/src/utils.rs

+1-22
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ enum UtilsError {
2929
// Convert to short address, use as universal identity
3030
pub fn parse_address(input: &str) -> Result<Address> {
3131
match Address::from_str(input) {
32-
Ok(addr) => Ok(to_universal_identity(addr.network(), &addr, addr.is_new)),
32+
Ok(addr) => Ok(addr),
3333
Err(e) => Err(MercuryError::utils(UtilsError::ParseCKBAddressError(e)).into()),
3434
}
3535
}
@@ -121,8 +121,6 @@ pub fn u256_low_u64(u: U256) -> u64 {
121121
mod test {
122122
use super::*;
123123

124-
use crate::NetworkType;
125-
use ckb_types::h160;
126124
use rand::random;
127125

128126
fn rand_bytes(len: usize) -> Vec<u8> {
@@ -139,25 +137,6 @@ mod test {
139137
assert_eq!(a, b);
140138
}
141139

142-
#[test]
143-
fn test_parse_address() {
144-
let addr = "ckt1qyqr79tnk3pp34xp92gerxjc4p3mus2690psf0dd70";
145-
let res = parse_address(addr);
146-
147-
assert!(res.is_ok());
148-
assert_eq!(res.unwrap().network(), NetworkType::Testnet);
149-
150-
let acp_addr = "ckb1qypzygjgr5425uvg2jcq3c7cxvpuv0rp4nssh7wm4f";
151-
let address = parse_address(acp_addr).unwrap();
152-
let payload = AddressPayload::new_short(
153-
NetworkType::Mainnet,
154-
CodeHashIndex::Sighash,
155-
h160!("0x2222481d2aaa718854b008e3d83303c63c61ace1"),
156-
);
157-
assert_eq!(address.network(), NetworkType::Mainnet);
158-
assert_eq!(address.payload().clone(), payload);
159-
}
160-
161140
#[test]
162141
fn test_find() {
163142
let test = (0..10).collect::<Vec<_>>();

core/cli/src/config.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub struct NetworkConfig {
2525

2626
#[derive(Deserialize, Default, Clone, Debug)]
2727
pub struct DBConfig {
28+
pub center_id: u16,
29+
pub machine_id: u16,
2830
pub max_connections: u32,
2931
pub db_type: String,
3032
pub db_host: String,
@@ -44,7 +46,7 @@ pub struct LogConfig {
4446
pub log_level: String,
4547

4648
#[serde(default = "default_is_spilt_file")]
47-
pub use_split_file: bool,
49+
pub auto_split_log_file: bool,
4850

4951
#[serde(default = "default_file_size_limit")]
5052
pub file_size_limit: u64,
@@ -72,7 +74,7 @@ pub struct ScriptConfig {
7274
#[derive(Deserialize, Default, Clone, Debug)]
7375
pub struct SyncConfig {
7476
pub sync_block_batch_size: usize,
75-
pub max_task_count: usize,
77+
pub max_task_number: usize,
7678
}
7779

7880
#[derive(Deserialize, Default, Clone, Debug)]
@@ -83,17 +85,15 @@ pub struct ExtensionConfig {
8385

8486
#[derive(Deserialize, Default, Clone, Debug)]
8587
pub struct MercuryConfig {
86-
pub center_id: u16,
87-
pub machine_id: u16,
88-
pub indexer_mode: bool,
88+
pub sync_mode: bool,
8989
pub db_config: DBConfig,
9090
pub log_config: LogConfig,
9191
pub network_config: NetworkConfig,
9292
pub sync_config: SyncConfig,
9393
pub builtin_scripts: Vec<ScriptConfig>,
9494

9595
#[serde(default = "default_need_sync")]
96-
pub need_sync: bool,
96+
pub allow_parallel_sync: bool,
9797

9898
#[serde(default = "default_rpc_thread_num")]
9999
pub rpc_thread_num: usize,

core/cli/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ impl<'a> Cli<'a> {
109109

110110
let service = Service::new(
111111
self.config.db_config.max_connections,
112-
self.config.center_id,
113-
self.config.machine_id,
112+
self.config.db_config.center_id,
113+
self.config.db_config.machine_id,
114114
Duration::from_secs(2),
115115
self.config.rpc_thread_num,
116116
&self.config.network_config.network_type,
@@ -133,17 +133,17 @@ impl<'a> Cli<'a> {
133133
)
134134
.await;
135135

136-
if self.config.need_sync {
136+
if self.config.allow_parallel_sync {
137137
service
138138
.do_sync(
139139
self.config.sync_config.sync_block_batch_size,
140-
self.config.sync_config.max_task_count,
140+
self.config.sync_config.max_task_number,
141141
)
142142
.await
143143
.unwrap();
144144
}
145145

146-
if self.config.indexer_mode {
146+
if self.config.sync_mode {
147147
service
148148
.start(self.config.flush_tx_pool_cache_interval)
149149
.await;

core/rpc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub trait MercuryRpc {
6565
payload: SimpleTransferPayload,
6666
) -> RpcResult<TransactionCompletionResponse>;
6767

68-
#[method(name = "register_address")]
68+
#[method(name = "register_addresses")]
6969
async fn register_addresses(&self, addresses: Vec<String>) -> RpcResult<Vec<H160>>;
7070

7171
#[method(name = "get_mercury_info")]

core/storage/src/relational/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::relational::{
1616
use crate::{error::DBError, Storage};
1717

1818
use common::{
19-
async_trait, utils::to_fixed_array, Context, DetailedCell, PaginationRequest,
19+
async_trait, utils::to_fixed_array, Context, DetailedCell, Order, PaginationRequest,
2020
PaginationResponse, Range, Result,
2121
};
2222
use common_logger::{tracing, tracing_async};
@@ -361,19 +361,24 @@ impl Storage for RelationalStorage {
361361
}
362362

363363
tx_hashes.sort();
364-
let next_cursor = if tx_hashes.len() as u64 <= limit {
364+
let next_cursor = if count <= limit {
365365
None
366366
} else if is_asc {
367367
Some(tx_hashes.last().unwrap().id)
368368
} else {
369369
Some(tx_hashes.first().unwrap().id)
370370
};
371+
let pag = if is_asc {
372+
PaginationRequest::default()
373+
} else {
374+
PaginationRequest::default().set_order(Order::Desc)
375+
};
371376
let tx_tables = self
372377
.query_transactions(
373378
ctx.clone(),
374379
tx_hashes.into_iter().map(|i| i.tx_hash).collect(),
375380
block_range,
376-
Default::default(),
381+
pag,
377382
)
378383
.await?;
379384
let txs_wrapper = self

db/xsql/src/page.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
use common::{Order, PaginationRequest};
1+
use common::{utils::to_fixed_array, PaginationRequest};
22

33
use bson2::Bson;
44
use rbatis::plugin::page::{IPageRequest, PagePlugin};
55
use rbatis::{core::Error as RbError, sql::TEMPLATE, DriverType};
66
use serde::{Deserialize, Serialize};
77

8-
use std::convert::TryInto;
9-
108
#[derive(Default, Clone, Debug)]
119
pub struct CursorPagePlugin;
1210

@@ -137,18 +135,11 @@ impl From<PaginationRequest> for PageRequest {
137135
PageRequest {
138136
cursor: p
139137
.cursor
140-
.map(|bytes| {
141-
i64::from_be_bytes(
142-
bytes
143-
.to_vec()
144-
.try_into()
145-
.expect("slice with incorrect length"),
146-
)
147-
})
148-
.unwrap_or(0),
138+
.map(|bytes| i64::from_be_bytes(to_fixed_array(&bytes[0..8])))
139+
.unwrap_or_else(|| if p.order.is_asc() { i64::MIN } else { i64::MAX }),
149140
count: p.limit.unwrap_or((i64::MAX - 1) as u64),
150141
skip: p.skip.unwrap_or(0),
151-
is_asc: p.order == Order::Asc,
142+
is_asc: p.order.is_asc(),
152143
search_count: true,
153144
}
154145
}

devtools/config/docker_compose_config.toml

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
center_id = 0
2-
3-
machine_id = 0
1+
sync_mode = true
42

5-
need_sync = true
6-
7-
indexer_mode = true
3+
allow_parallel_sync = true
84

95
rpc_thread_num = 3
106

@@ -13,10 +9,12 @@ flush_tx_pool_cache_interval = 300
139
# Fill cellbase maturity in the same as the ckb genesis block.
1410
cellbase_maturity = 4
1511

16-
cheque_timeout = 6
12+
cheque_since = 6
1713

1814
[db_config]
1915
# Use your pgsql configuration
16+
center_id = 0
17+
machine_id = 0
2018
max_connections = 1000
2119
db_type = "postgres"
2220
db_host = "postgres"
@@ -29,7 +27,7 @@ db_log_level = "WARN"
2927

3028
[log_config]
3129
log_level = "INFO"
32-
use_split_file = false
30+
auto_split_log_file = true
3331
log_path = "./free-space/mainnet/log"
3432

3533

@@ -43,7 +41,7 @@ listen_uri = "0.0.0.0:8116"
4341

4442
[sync_config]
4543
sync_block_batch_size = 1000
46-
max_task_count = 30
44+
max_task_number = 30
4745

4846

4947
[[builtin_scripts]]

devtools/config/mainnet_config.toml

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
center_id = 0
2-
3-
machine_id = 0
1+
sync_mode = true
42

5-
indexer_mode = true
6-
7-
need_sync = true
3+
allow_parallel_sync = true
84

95
rpc_thread_num = 3
106

@@ -13,9 +9,11 @@ flush_tx_pool_cache_interval = 300
139
# Fill cellbase maturity in the same as the ckb genesis block.
1410
cellbase_maturity = 4
1511

16-
cheque_timeout = 6
12+
cheque_since = 6
1713

1814
[db_config]
15+
center_id = 0
16+
machine_id = 0
1917
max_connections = 1000
2018
db_type = "postgres"
2119
db_host = "127.0.0.1"
@@ -28,7 +26,7 @@ db_log_level = "WARN"
2826

2927
[log_config]
3028
log_level = "INFO"
31-
use_split_file = false
29+
auto_split_log_file = true
3230
log_path = "./free-space/mainnet/log"
3331

3432

@@ -41,7 +39,7 @@ listen_uri = "127.0.0.1:8116"
4139

4240
[sync_config]
4341
sync_block_batch_size = 1000
44-
max_task_count = 30
42+
max_task_number = 30
4543

4644

4745
[[builtin_scripts]]

0 commit comments

Comments
 (0)