Skip to content

Commit

Permalink
use a separate schema for api server database
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Mar 23, 2024
1 parent f1a2c0b commit a51c45a
Show file tree
Hide file tree
Showing 25 changed files with 135 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ use super::ApiServerInMemoryStorageTransactionalRw;

#[async_trait::async_trait]
impl<'t> ApiServerStorageWrite for ApiServerInMemoryStorageTransactionalRw<'t> {
async fn initialize_storage(
&mut self,
chain_config: &ChainConfig,
) -> Result<(), ApiServerStorageError> {
self.transaction.initialize_storage(chain_config)
}

async fn reinitialize_storage(
&mut self,
chain_config: &ChainConfig,
Expand Down
187 changes: 103 additions & 84 deletions api-server/api-server-common/src/storage/impls/postgres/queries.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ use super::{ApiServerPostgresTransactionalRw, CONN_ERR};

#[async_trait::async_trait]
impl<'a> ApiServerStorageWrite for ApiServerPostgresTransactionalRw<'a> {
async fn initialize_storage(
&mut self,
chain_config: &ChainConfig,
) -> Result<(), ApiServerStorageError> {
let mut conn = QueryFromConnection::new(self.connection.as_ref().expect(CONN_ERR));
conn.initialize_database(chain_config).await?;

Ok(())
}

async fn reinitialize_storage(
&mut self,
chain_config: &ChainConfig,
Expand Down
5 changes: 0 additions & 5 deletions api-server/api-server-common/src/storage/storage_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,6 @@ pub trait ApiServerStorageRead: Sync {

#[async_trait::async_trait]
pub trait ApiServerStorageWrite: ApiServerStorageRead {
async fn initialize_storage(
&mut self,
chain_config: &ChainConfig,
) -> Result<(), ApiServerStorageError>;

async fn reinitialize_storage(
&mut self,
chain_config: &ChainConfig,
Expand Down
2 changes: 1 addition & 1 deletion api-server/scanner-daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub async fn run<S: ApiServerStorage>(
.unwrap_or_else(|e| panic!("Storage initialization checking failed {}", e))
{
db_tx
.initialize_storage(chain_config)
.reinitialize_storage(chain_config)
.await
.unwrap_or_else(|e| panic!("Storage initialization failed {}", e));

Expand Down
4 changes: 2 additions & 2 deletions api-server/scanner-lib/src/sync/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ async fn compare_pool_rewards_with_chainstate_real_state(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down Expand Up @@ -616,7 +616,7 @@ async fn reorg_locked_balance(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
6 changes: 3 additions & 3 deletions api-server/stack-test-suite/tests/v2/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async fn multiple_outputs_to_single_address(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down Expand Up @@ -490,7 +490,7 @@ async fn test_unlocking_for_locked_utxos(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down Expand Up @@ -713,7 +713,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
4 changes: 2 additions & 2 deletions api-server/stack-test-suite/tests/v2/address_all_utxos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ async fn multiple_utxos_to_single_address(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down Expand Up @@ -521,7 +521,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ async fn multiple_utxos_to_single_address(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down Expand Up @@ -503,7 +503,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
2 changes: 1 addition & 1 deletion api-server/stack-test-suite/tests/v2/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(chain_config).await.unwrap();
db_tx.reinitialize_storage(chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
2 changes: 1 addition & 1 deletion api-server/stack-test-suite/tests/v2/block_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(tf.chain_config());

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(tf.chain_config()).await.unwrap();
db_tx.reinitialize_storage(tf.chain_config()).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
4 changes: 2 additions & 2 deletions api-server/stack-test-suite/tests/v2/block_reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async fn no_reward(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down Expand Up @@ -200,7 +200,7 @@ async fn has_reward(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
2 changes: 1 addition & 1 deletion api-server/stack-test-suite/tests/v2/chain_at_height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async fn height_n(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
2 changes: 1 addition & 1 deletion api-server/stack-test-suite/tests/v2/chain_tip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async fn height_n(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
2 changes: 1 addition & 1 deletion api-server/stack-test-suite/tests/v2/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
2 changes: 1 addition & 1 deletion api-server/stack-test-suite/tests/v2/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
2 changes: 1 addition & 1 deletion api-server/stack-test-suite/tests/v2/pool_block_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
2 changes: 1 addition & 1 deletion api-server/stack-test-suite/tests/v2/pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
2 changes: 1 addition & 1 deletion api-server/stack-test-suite/tests/v2/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
4 changes: 2 additions & 2 deletions api-server/stack-test-suite/tests/v2/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async fn multiple_tx_in_same_block(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down Expand Up @@ -361,7 +361,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async fn get_block_failed(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down Expand Up @@ -226,7 +226,7 @@ async fn transaction_not_part_of_block(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down Expand Up @@ -344,7 +344,7 @@ async fn cannot_find_transaction_in_block(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down Expand Up @@ -488,7 +488,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
2 changes: 1 addition & 1 deletion api-server/stack-test-suite/tests/v2/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async fn ok(#[case] seed: Seed) {
let mut storage = TransactionalApiServerInMemoryStorage::new(&chain_config);

let mut db_tx = storage.transaction_rw().await.unwrap();
db_tx.initialize_storage(&chain_config).await.unwrap();
db_tx.reinitialize_storage(&chain_config).await.unwrap();
db_tx.commit().await.unwrap();

storage
Expand Down
4 changes: 2 additions & 2 deletions api-server/storage-test-suite/src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
let mut storage = storage_maker().await;
let mut tx = storage.transaction_rw().await.unwrap();
let chain_config = create_unit_test_config();
tx.initialize_storage(&chain_config).await.unwrap();
tx.reinitialize_storage(&chain_config).await.unwrap();
tx.commit().await.unwrap();
let tx = storage.transaction_ro().await.unwrap();
assert!(tx.is_initialized().await.unwrap());
Expand All @@ -87,7 +87,7 @@ where
let mut storage = storage_maker().await;
let mut tx = storage.transaction_rw().await.unwrap();
let chain_config = create_unit_test_config();
tx.initialize_storage(&chain_config).await.unwrap();
tx.reinitialize_storage(&chain_config).await.unwrap();
tx.commit().await.unwrap();

let db_tx = storage.transaction_ro().await.unwrap();
Expand Down

0 comments on commit a51c45a

Please sign in to comment.