Skip to content

Commit

Permalink
store: make bulk_object_insert private
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Jan 11, 2023
1 parent f350bcf commit 2c70d36
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
7 changes: 0 additions & 7 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2234,13 +2234,6 @@ impl AuthorityState {
.expect("Cannot insert genesis object")
}

pub async fn insert_genesis_objects_bulk_unsafe(&self, objects: &[&Object]) {
self.database
.bulk_object_insert(objects)
.await
.expect("Cannot bulk insert genesis objects")
}

/// Make an information response for a transaction
pub async fn make_transaction_info(
&self,
Expand Down
8 changes: 3 additions & 5 deletions crates/sui-core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ impl AuthorityStore {
/// Insert an object directly into the store, and also update relevant tables
/// NOTE: does not handle transaction lock.
/// This is used to insert genesis objects
pub async fn insert_object_direct(&self, object_ref: ObjectRef, object: &Object) -> SuiResult {
async fn insert_object_direct(&self, object_ref: ObjectRef, object: &Object) -> SuiResult {
let mut write_batch = self.perpetual_tables.objects.batch();

// Insert object
Expand Down Expand Up @@ -532,10 +532,8 @@ impl AuthorityStore {
Ok(())
}

/// This function is used by the bench.rs script, and should not be used in other contexts
/// In particular it does not check the old locks before inserting new ones, so the objects
/// must be new.
pub async fn bulk_object_insert(&self, objects: &[&Object]) -> SuiResult<()> {
/// This function should only be used for initializing genesis and should remain private.
async fn bulk_object_insert(&self, objects: &[&Object]) -> SuiResult<()> {
let mut batch = self.perpetual_tables.objects.batch();
let ref_and_objects: Vec<_> = objects
.iter()
Expand Down
39 changes: 29 additions & 10 deletions crates/sui-core/src/unit_tests/pay_sui_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::authority::authority_tests::{init_state, send_and_confirm_transaction};
use crate::authority::authority_tests::{
init_state, init_state_with_committee, send_and_confirm_transaction,
};
use crate::authority::AuthorityState;
use futures::future::join_all;
use std::collections::HashMap;
Expand Down Expand Up @@ -458,15 +460,32 @@ async fn execute_pay_all_sui(
sender_key: AccountKeyPair,
gas_budget: u64,
) -> PaySuiTransactionExecutionResult {
let authority_state = init_state().await;
authority_state
.insert_genesis_objects_bulk_unsafe(&input_coin_objects)
.await;

let input_coins: Vec<ObjectRef> = input_coin_objects
.iter()
.map(|obj| obj.compute_object_reference())
.collect();
let dir = tempfile::TempDir::new().unwrap();
let network_config = sui_config::builder::ConfigBuilder::new(&dir)
.with_objects(
input_coin_objects
.clone()
.into_iter()
.map(ToOwned::to_owned)
.collect(),
)
.build();
let genesis = network_config.genesis;
let keypair = network_config.validator_configs[0].protocol_key_pair();

let authority_state = init_state_with_committee(&genesis, keypair).await;

let mut input_coins = Vec::new();
for coin in input_coin_objects {
let id = coin.id();
let object_ref = genesis
.objects()
.iter()
.find(|o| o.id() == id)
.unwrap()
.compute_object_reference();
input_coins.push(object_ref);
}
let gas_object_ref = input_coins[0];

let kind = TransactionKind::Single(SingleTransactionKind::PayAllSui(PayAllSui {
Expand Down

0 comments on commit 2c70d36

Please sign in to comment.