Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage): Store Validator State Test + Binary #2680

Merged
merged 6 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 35 additions & 66 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ members = [
"test-utils/testlib",
"test-utils/loadtester",
"test-utils/state-viewer",
"test-utils/store-validator-bin",
"test-utils/store-validator",
"neard/",
"tools/rpctypegen/core",
Expand Down
1 change: 1 addition & 0 deletions chain/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ near-pool = { path = "../pool" }

[dev-dependencies]
near-logger-utils = {path = "../../test-utils/logger"}
near-store-validator = { path = "../../test-utils/store-validator" }

[features]
# if enabled, we assert in most situations that are impossible unless some byzantine behavior is observed.
Expand Down
10 changes: 7 additions & 3 deletions chain/chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,7 @@ mod tests {
use near_primitives::utils::index_to_bytes;
use near_primitives::validator_signer::{InMemoryValidatorSigner, ValidatorSigner};
use near_store::test_utils::create_test_store;
use near_store::StoreValidator;
use near_store_validator::StoreValidator;

use crate::chain::{check_refcount_map, MAX_HEIGHTS_TO_CLEAR};
use crate::store::{ChainStoreAccess, GCMode};
Expand Down Expand Up @@ -2742,8 +2742,12 @@ mod tests {
assert!(check_refcount_map(&mut chain).is_ok());
let mut genesis = GenesisConfig::default();
genesis.genesis_height = 0;
let mut store_validator = StoreValidator::default();
store_validator.validate(&*chain.store().owned_store(), &genesis);
let mut store_validator = StoreValidator::new(
genesis.clone(),
chain.runtime_adapter.get_tries(),
chain.store().owned_store(),
);
store_validator.validate();
assert!(!store_validator.is_failed());
}
}
Expand Down
12 changes: 6 additions & 6 deletions chain/chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use near_primitives::transaction::{
TransferAction,
};
use near_primitives::types::{
AccountId, ApprovalStake, Balance, BlockHeight, EpochId, Gas, Nonce, NumBlocks, ShardId,
StateRoot, StateRootNode, ValidatorStake, ValidatorStats,
AccountId, ApprovalStake, Balance, BlockHeight, EpochId, Gas, Nonce, NumBlocks, NumShards,
ShardId, StateRoot, StateRootNode, ValidatorStake, ValidatorStats,
};
use near_primitives::validator_signer::InMemoryValidatorSigner;
use near_primitives::views::{
Expand Down Expand Up @@ -61,7 +61,7 @@ pub struct KeyValueRuntime {
tries: ShardTries,
validators: Vec<Vec<ValidatorStake>>,
validator_groups: u64,
num_shards: ShardId,
num_shards: NumShards,
epoch_length: u64,

// A mapping state_root => {account id => amounts}, for transactions and receipts
Expand All @@ -76,7 +76,7 @@ pub struct KeyValueRuntime {
epoch_start: RwLock<HashMap<CryptoHash, u64>>,
}

pub fn account_id_to_shard_id(account_id: &AccountId, num_shards: ShardId) -> ShardId {
pub fn account_id_to_shard_id(account_id: &AccountId, num_shards: NumShards) -> ShardId {
u64::from((hash(&account_id.clone().into_bytes()).0).0[0]) % num_shards
}

Expand All @@ -101,7 +101,7 @@ impl KeyValueRuntime {
store: Arc<Store>,
validators: Vec<Vec<AccountId>>,
validator_groups: u64,
num_shards: ShardId,
num_shards: NumShards,
epoch_length: u64,
) -> Self {
let tries = ShardTries::new(store.clone(), num_shards);
Expand Down Expand Up @@ -993,7 +993,7 @@ pub fn setup_with_tx_validity_period(
pub fn setup_with_validators(
validators: Vec<AccountId>,
validator_groups: u64,
num_shards: ShardId,
num_shards: NumShards,
epoch_length: u64,
tx_validity_period: NumBlocks,
) -> (Chain, Arc<KeyValueRuntime>, Vec<Arc<InMemoryValidatorSigner>>) {
Expand Down
Loading