Skip to content

Commit

Permalink
Rename chunks.height_included into stored_at_block_height addressing …
Browse files Browse the repository at this point in the history
…review suggestion
  • Loading branch information
khorolets committed Aug 16, 2023
1 parent 781a256 commit 7402301
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions rpc-server/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ impl TryFrom<(num_bigint::BigInt, num_bigint::BigInt)> for BlockHeightShardId {
type Error = anyhow::Error;

fn try_from(value: (num_bigint::BigInt, num_bigint::BigInt)) -> Result<Self, Self::Error> {
let height_included = value
let stored_at_block_height = value
.0
.to_u64()
.ok_or_else(|| anyhow::anyhow!("Failed to parse `height_included` to u64"))?;
.ok_or_else(|| anyhow::anyhow!("Failed to parse `stored_at_block_height` to u64"))?;

let parsed_shard_id = value
.1
.to_u64()
.ok_or_else(|| anyhow::anyhow!("Failed to parse `shard_id` to u64"))?;

Ok(BlockHeightShardId(height_included, parsed_shard_id))
Ok(BlockHeightShardId(stored_at_block_height, parsed_shard_id))
}
}

Expand All @@ -40,7 +40,7 @@ pub struct ScyllaDBManager {
get_account_access_keys: PreparedStatement,
get_receipt: PreparedStatement,
get_transaction_by_hash: PreparedStatement,
get_height_included_and_shard_id_by_block_height: PreparedStatement,
get_stored_at_block_height_and_shard_id_by_block_height: PreparedStatement,
}

#[async_trait::async_trait]
Expand All @@ -58,7 +58,7 @@ impl ScyllaStorageManager for ScyllaDBManager {

get_block_by_chunk_id: Self::prepare_read_query(
&scylla_db_session,
"SELECT height_included, shard_id FROM state_indexer.chunks WHERE chunk_hash = ? LIMIT 1",
"SELECT stored_at_block_height, shard_id FROM state_indexer.chunks WHERE chunk_hash = ? LIMIT 1",
).await?,

get_all_state_keys: Self::prepare_read_query(
Expand Down Expand Up @@ -108,9 +108,9 @@ impl ScyllaStorageManager for ScyllaDBManager {
"SELECT transaction_details FROM tx_indexer.transactions_details WHERE transaction_hash = ? LIMIT 1",
).await?,

get_height_included_and_shard_id_by_block_height: Self::prepare_read_query(
get_stored_at_block_height_and_shard_id_by_block_height: Self::prepare_read_query(
&scylla_db_session,
"SELECT height_included, shard_id FROM state_indexer.chunks WHERE block_height = ?",
"SELECT stored_at_block_height, shard_id FROM state_indexer.chunks WHERE block_height = ?",
).await?,
}))
}
Expand Down Expand Up @@ -327,18 +327,18 @@ impl ScyllaDBManager {
) -> anyhow::Result<BlockHeightShardId> {
let rows = Self::execute_prepared_query(
&self.scylla_session,
&self.get_height_included_and_shard_id_by_block_height,
&self.get_stored_at_block_height_and_shard_id_by_block_height,
(num_bigint::BigInt::from(block_height),),
)
.await?
.rows()?;

let height_included_and_shard_id = rows
let block_height_and_shard_id = rows
.into_typed::<(num_bigint::BigInt, num_bigint::BigInt)>()
.filter_map(Result::ok)
.find(|(_, shard)| shard == &num_bigint::BigInt::from(shard_id));

height_included_and_shard_id
block_height_and_shard_id
.map(BlockHeightShardId::try_from)
.unwrap_or_else(|| {
Err(anyhow::anyhow!(
Expand Down
4 changes: 2 additions & 2 deletions state-indexer/src/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl ScyllaStorageManager for ScyllaDBManager {
chunk_hash varchar,
block_height varint,
shard_id varint,
height_included varint,
stored_at_block_height varint,
PRIMARY KEY (chunk_hash, block_height)
)
",
Expand Down Expand Up @@ -459,7 +459,7 @@ impl ScyllaStorageManager for ScyllaDBManager {
add_chunk: Self::prepare_write_query(
&scylla_db_session,
"INSERT INTO state_indexer.chunks
(chunk_hash, block_height, shard_id, height_included)
(chunk_hash, block_height, shard_id, stored_at_block_height)
VALUES (?, ?, ?, ?)",
)
.await?,
Expand Down

0 comments on commit 7402301

Please sign in to comment.