Skip to content

Commit

Permalink
chore: modify according review
Browse files Browse the repository at this point in the history
  • Loading branch information
quake committed Jun 17, 2019
1 parent 1c99774 commit 942467d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
13 changes: 12 additions & 1 deletion indexer/src/store.rs
Expand Up @@ -318,13 +318,24 @@ impl<CS: ChainStore + 'static> DefaultIndexerStore<CS> {
});

// attach blocks until reach tip or batch limit
// need to check empty again because `remove_lock_hash` may be called during detach
let mut lock_hash_index_states = self.get_lock_hash_index_states();
if lock_hash_index_states.is_empty() {
return;
}
let min_block_number: BlockNumber = lock_hash_index_states
.values()
.min_by_key(|index_state| index_state.block_number)
.expect("none empty index states")
.block_number;

// should index genesis block also
let start_number = if min_block_number == 0 {
0
} else {
min_block_number + 1
};

let (tip_number, tip_hash) = {
let tip_header = self
.shared
Expand All @@ -334,7 +345,7 @@ impl<CS: ChainStore + 'static> DefaultIndexerStore<CS> {
(tip_header.number(), tip_header.hash().to_owned())
};
self.commit_batch(|batch| {
(min_block_number + 1..=tip_number)
(start_number..=tip_number)
.take(BATCH_ATTACH_BLOCK_NUMS)
.for_each(|block_number| {
let index_lock_hashes = lock_hash_index_states
Expand Down
11 changes: 6 additions & 5 deletions indexer/src/types.rs
Expand Up @@ -70,11 +70,12 @@ impl LockHashIndex {
}

pub fn to_vec(&self) -> Vec<u8> {
let mut bytes = self.lock_hash.to_vec();
bytes.extend_from_slice(&self.block_number.to_be_bytes());
bytes.extend_from_slice(self.cell_out_point.tx_hash.as_bytes());
bytes.extend_from_slice(&self.cell_out_point.index.to_be_bytes());
bytes.to_vec()
let mut result = Vec::with_capacity(76);
result.extend_from_slice(self.lock_hash.as_bytes());
result.extend_from_slice(&self.block_number.to_be_bytes());
result.extend_from_slice(self.cell_out_point.tx_hash.as_bytes());
result.extend_from_slice(&self.cell_out_point.index.to_be_bytes());
result
}
}

Expand Down
6 changes: 3 additions & 3 deletions rpc/README.md
Expand Up @@ -798,7 +798,7 @@ http://localhost:8114

### `deindex_lock_hash`

Remove index for live cells and transaction by the hash of lock script.
Remove index for live cells and transaction by the hash of lock script. Returns empty array when the `lock_hash` not indexed yet.

#### Parameters

Expand Down Expand Up @@ -933,7 +933,7 @@ http://localhost:8114

### `get_transactions_by_lock_hash`

Returns the transactions collection by the hash of lock script.
Returns the transactions collection by the hash of lock script. Returns empty array when the `lock_hash` not indexed yet.

#### Parameters

Expand Down Expand Up @@ -991,7 +991,7 @@ Create index for live cells and transactions by the hash of lock script.

#### Parameters

index_from - Create an index from starting block number, an optional parameter, null means starting from tip
index_from - Create an index from starting block number (exclusive), an optional parameter, null means starting from tip and 0 means starting from genesis
lock_hash - Cell lock script hash

#### Examples
Expand Down
6 changes: 3 additions & 3 deletions rpc/json/rpc.json
Expand Up @@ -644,7 +644,7 @@
},
"types": [
{
"index_from": "Create an index from starting block number, an optional parameter, null means starting from tip"
"index_from": "Create an index from starting block number (exclusive), an optional parameter, null means starting from tip and 0 means starting from genesis"
},
{
"lock_hash": "Cell lock script hash"
Expand Down Expand Up @@ -723,7 +723,7 @@
]
},
{
"description": "Returns the transactions collection by the hash of lock script.",
"description": "Returns the transactions collection by the hash of lock script. Returns empty array when the `lock_hash` not indexed yet.",
"method": "get_transactions_by_lock_hash",
"module": "indexer",
"params": [
Expand Down Expand Up @@ -765,7 +765,7 @@
]
},
{
"description": "Remove index for live cells and transaction by the hash of lock script.",
"description": "Remove index for live cells and transaction by the hash of lock script. Returns empty array when the `lock_hash` not indexed yet.",
"method": "deindex_lock_hash",
"module": "indexer",
"params": [
Expand Down
2 changes: 1 addition & 1 deletion util/app-config/src/app_config.rs
Expand Up @@ -42,7 +42,7 @@ pub struct CKBAppConfig {
pub block_assembler: Option<BlockAssemblerConfig>,
#[serde(default)]
pub db: DBConfig,
#[serde(skip)]
#[serde(default)]
pub indexer_db: DBConfig,
pub network: NetworkConfig,
pub rpc: RpcConfig,
Expand Down

0 comments on commit 942467d

Please sign in to comment.