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

(wip) (fix) Fix Storage Usage #4247

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
134a899
Account V2
EgorKulikov Apr 21, 2021
816a00f
Update core/primitives/src/account.rs
EgorKulikov Apr 21, 2021
ab029b8
Update chain/rosetta-rpc/src/lib.rs
EgorKulikov Apr 21, 2021
2e028a0
Merge branch 'master' into fix-account-storage-usage
EgorKulikov Apr 21, 2021
d73e475
Fixing build
EgorKulikov Apr 21, 2021
ecaabfc
Fixing build
EgorKulikov Apr 21, 2021
b110634
Fixing build
EgorKulikov Apr 21, 2021
1fb8a6b
Fixing build
EgorKulikov Apr 21, 2021
dbef212
Fixing build
EgorKulikov Apr 21, 2021
9f388b0
Fixing test
EgorKulikov Apr 21, 2021
2cb26d4
Merge branch 'master' into fix-account-storage-usage
EgorKulikov Apr 21, 2021
933d861
Storage usage fix
EgorKulikov Apr 22, 2021
f76351b
Merge remote-tracking branch 'origin/fix-account-storage-usage' into …
EgorKulikov Apr 22, 2021
0bf112b
Compliation fix
EgorKulikov Apr 22, 2021
869aa91
Compliation fix
EgorKulikov Apr 22, 2021
77e4bc0
Compliation fix
EgorKulikov Apr 22, 2021
40d7981
Merge branch 'master' into fix-account-storage-usage
EgorKulikov Apr 22, 2021
10ea648
Compliation fix
EgorKulikov Apr 22, 2021
2f3b0e7
Merge remote-tracking branch 'origin/fix-account-storage-usage' into …
EgorKulikov Apr 22, 2021
a3d33ec
Compliation fix
EgorKulikov Apr 22, 2021
89c9780
Compliation fix
EgorKulikov Apr 22, 2021
fbad24f
Compliation fix
EgorKulikov Apr 22, 2021
f5712b1
Comment
EgorKulikov Apr 22, 2021
a823ecb
Compilation fix
EgorKulikov Apr 22, 2021
e5a2238
Compilation fix
EgorKulikov Apr 22, 2021
2e8eb29
Moving delta storage usage from runtime config to static
EgorKulikov Apr 26, 2021
854c759
Compilation fix
EgorKulikov Apr 26, 2021
c6c7675
Compilation fix
EgorKulikov Apr 26, 2021
54a4335
Compilation fix
EgorKulikov Apr 26, 2021
6d96ee0
Compilation fix
EgorKulikov Apr 26, 2021
87b76c9
Merge branch 'master' into fix-account-storage-usage
EgorKulikov Apr 26, 2021
1748c6c
Merge branch 'master' into fix-account-storage-usage
EgorKulikov Apr 27, 2021
7e68414
Removing unnecessary into
EgorKulikov Apr 27, 2021
f6c5bd0
Merge remote-tracking branch 'origin/fix-account-storage-usage' into …
EgorKulikov Apr 27, 2021
53f2729
Merge branch 'master' into fix-account-storage-usage
EgorKulikov Apr 27, 2021
b8ad914
Update runtime/runtime/src/actions.rs
EgorKulikov Apr 27, 2021
2a94d2b
Merge branch 'master' into fix-account-storage-usage
EgorKulikov Apr 28, 2021
7fc8509
Merge branch 'master' into fix-account-storage-usage
EgorKulikov Apr 29, 2021
6e2f721
Merge branch 'master' into fix-account-storage-usage
EgorKulikov Apr 30, 2021
8e61380
Compilation fix
EgorKulikov Apr 30, 2021
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
12 changes: 12 additions & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ members = [
"genesis-tools/keypair-generator",
"tools/restaked",
"tools/indexer/example",
"tools/delay_detector"
"tools/delay_detector",
"utils/storage-usage-delta-calculator"
]

[dev-dependencies]
Expand Down Expand Up @@ -116,7 +117,7 @@ protocol_feature_block_header_v3 = ["near-primitives/protocol_feature_block_head
protocol_feature_access_key_nonce_range = ["neard/protocol_feature_access_key_nonce_range", "testlib/protocol_feature_access_key_nonce_range"]
protocol_feature_tx_size_limit = ["near-primitives/protocol_feature_tx_size_limit", "node-runtime/protocol_feature_tx_size_limit", "neard/protocol_feature_tx_size_limit"]
protocol_feature_allow_create_account_on_delete = ["testlib/protocol_feature_allow_create_account_on_delete", "near-primitives/protocol_feature_allow_create_account_on_delete", "node-runtime/protocol_feature_allow_create_account_on_delete", "neard/protocol_feature_allow_create_account_on_delete"]
protocol_feature_add_account_versions = ["near-primitives/protocol_feature_add_account_versions"]
protocol_feature_add_account_versions = ["near-primitives/protocol_feature_add_account_versions", "neard/protocol_feature_add_account_versions"]

# enable this to build neard with wasmer 1.0 runner
# now if none of wasmer0_default, wasmer1_default or wasmtime_default is enabled, wasmer0 would be default
Expand Down
4 changes: 3 additions & 1 deletion chain/chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use tracing::debug;
use near_chain_primitives::{Error, ErrorKind};
use near_crypto::{KeyType, PublicKey, SecretKey, Signature};
use near_pool::types::PoolIterator;
use near_primitives::account::{AccessKey, Account};
use near_primitives::access_key::AccessKey;
use near_primitives::account::Account;
use near_primitives::challenge::ChallengesResult;
use near_primitives::epoch_manager::block_info::BlockInfo;
use near_primitives::epoch_manager::epoch_info::EpochInfo;
Expand Down Expand Up @@ -809,6 +810,7 @@ impl RuntimeAdapter for KeyValueRuntime {
0,
CryptoHash::default(),
0,
PROTOCOL_VERSION,
)
.into(),
),
Expand Down
19 changes: 19 additions & 0 deletions chain/client/tests/challenges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ fn test_verify_chunk_invalid_state_challenge() {
let merkle_proofs = Block::compute_chunk_headers_root(block.chunks().iter()).1;
assert_eq!(prev_merkle_proofs[0], challenge_body.prev_merkle_proof);
assert_eq!(merkle_proofs[0], challenge_body.merkle_proof);
#[cfg(not(feature = "protocol_feature_add_account_versions"))]
assert_eq!(
challenge_body.partial_state.0,
vec![
Expand All @@ -419,6 +420,24 @@ fn test_verify_chunk_invalid_state_challenge() {
]
],
);
#[cfg(feature = "protocol_feature_add_account_versions")]
assert_eq!(
challenge_body.partial_state.0,
vec![
vec![
1, 5, 0, 197, 185, 48, 117, 208, 162, 58, 178, 211, 174, 224, 17, 151, 175,
104, 50, 193, 73, 241, 135, 170, 42, 77, 144, 147, 221, 252, 5, 35, 120, 151,
31, 171, 30, 7, 228, 175, 99, 17, 113, 5, 94, 136, 200, 39, 136, 37, 110, 166,
241, 148, 128, 55, 131, 173, 97, 98, 201, 68, 82, 244, 223, 70, 86, 164, 5, 0,
0, 0, 0, 0, 0
],
vec![
3, 1, 0, 0, 0, 16, 63, 153, 161, 236, 209, 114, 108, 112, 213, 218, 218, 180,
13, 34, 58, 16, 28, 70, 130, 240, 120, 187, 247, 141, 141, 132, 82, 113, 80,
140, 82, 144, 216, 5, 0, 0, 0, 0, 0, 0
]
],
);
}
let challenge =
Challenge::produce(ChallengeBody::ChunkState(challenge_body), &validator_signer);
Expand Down
2 changes: 1 addition & 1 deletion chain/client/tests/process_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2749,7 +2749,7 @@ fn test_congestion_receipt_execution() {
mod access_key_nonce_range_tests {
use super::*;
use near_client::test_utils::create_chunk_with_transactions;
use near_primitives::account::AccessKey;
use near_primitives::access_key::AccessKey;

/// Test that duplicate transactions are properly rejected.
#[test]
Expand Down
2 changes: 1 addition & 1 deletion chain/jsonrpc/tests/rpc_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use near_jsonrpc_primitives::types::query::QueryResponseKind;
use near_jsonrpc_primitives::types::validator::RpcValidatorsOrderedRequest;
use near_logger_utils::init_test_logger;
use near_network::test_utils::WaitOrTimeout;
use near_primitives::account::{AccessKey, AccessKeyPermission};
use near_primitives::access_key::{AccessKey, AccessKeyPermission};
use near_primitives::hash::CryptoHash;
use near_primitives::types::{BlockId, BlockReference, ShardId, SyncCheckpoint};
use near_primitives::views::QueryRequest;
Expand Down
4 changes: 2 additions & 2 deletions chain/rosetta-rpc/src/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ impl std::convert::TryFrom<Vec<crate::models::Operation>> for NearActions {

actions.push(
near_primitives::transaction::AddKeyAction {
access_key: near_primitives::account::AccessKey::full_access(),
access_key: near_primitives::access_key::AccessKey::full_access(),
public_key,
}
.into(),
Expand Down Expand Up @@ -1015,7 +1015,7 @@ mod tests {
}
.into()];
let add_key_actions = vec![near_primitives::transaction::AddKeyAction {
access_key: near_primitives::account::AccessKey::full_access(),
access_key: near_primitives::access_key::AccessKey::full_access(),
public_key: near_crypto::SecretKey::from_random(near_crypto::KeyType::ED25519)
.public_key(),
}
Expand Down
10 changes: 9 additions & 1 deletion chain/rosetta-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use near_chain_configs::Genesis;
use near_client::{ClientActor, ViewClientActor};
use near_primitives::borsh::BorshDeserialize;
use near_primitives::serialize::BaseEncode;
use near_primitives::views::AccountView;

pub use config::RosettaRpcConfig;

Expand Down Expand Up @@ -376,7 +377,14 @@ async fn account_balance(
Err(crate::errors::ErrorKind::NotFound(_)) => (
block.header.hash,
block.header.height,
near_primitives::account::Account::new(0, 0, Default::default(), 0).into(),
AccountView {
amount: 0,
locked: 0,
code_hash: Default::default(),
storage_usage: 0,
storage_paid_at: 0,
}
.into(),
),
Err(err) => return Err(err.into()),
};
Expand Down
5 changes: 5 additions & 0 deletions core/chain-configs/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ impl GenesisConfig {
})
.collect()
}

/// Returns true iff chain_id is mainnet
pub fn is_mainnet(&self) -> bool {
self.chain_id.as_str() == "mainnet"
}
}

impl GenesisRecords {
Expand Down
1 change: 0 additions & 1 deletion core/primitives-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ lazy_static = "1.4"
[features]
default = []
costs_counting = []
protocol_feature_add_account_versions = []
protocol_feature_evm = []
protocol_feature_alt_bn128 = []
protocol_feature_tx_size_limit = []
70 changes: 70 additions & 0 deletions core/primitives-core/src/access_key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};

use crate::serialize::option_u128_dec_format;
use crate::types::{AccountId, Balance, Nonce};

/// Access key provides limited access to an account. Each access key belongs to some account and
/// is identified by a unique (within the account) public key. One account may have large number of
/// access keys. Access keys allow to act on behalf of the account by restricting transactions
/// that can be issued.
/// `account_id,public_key` is a key in the state
#[derive(
BorshSerialize, BorshDeserialize, Serialize, Deserialize, PartialEq, Eq, Hash, Clone, Debug,
)]
pub struct AccessKey {
/// The nonce for this access key.
/// NOTE: In some cases the access key needs to be recreated. If the new access key reuses the
/// same public key, the nonce of the new access key should be equal to the nonce of the old
/// access key. It's required to avoid replaying old transactions again.
pub nonce: Nonce,

/// Defines permissions for this access key.
pub permission: AccessKeyPermission,
}

impl AccessKey {
pub const ACCESS_KEY_NONCE_RANGE_MULTIPLIER: u64 = 1_000_000;

pub fn full_access() -> Self {
Self { nonce: 0, permission: AccessKeyPermission::FullAccess }
}
}

/// Defines permissions for AccessKey
#[derive(
BorshSerialize, BorshDeserialize, Serialize, Deserialize, PartialEq, Eq, Hash, Clone, Debug,
)]
pub enum AccessKeyPermission {
FunctionCall(FunctionCallPermission),

/// Grants full access to the account.
/// NOTE: It's used to replace account-level public keys.
FullAccess,
}

/// Grants limited permission to make transactions with FunctionCallActions
/// The permission can limit the allowed balance to be spent on the prepaid gas.
/// It also restrict the account ID of the receiver for this function call.
/// It also can restrict the method name for the allowed function calls.
#[derive(
BorshSerialize, BorshDeserialize, Serialize, Deserialize, PartialEq, Eq, Hash, Clone, Debug,
)]
pub struct FunctionCallPermission {
/// Allowance is a balance limit to use by this access key to pay for function call gas and
/// transaction fees. When this access key is used, both account balance and the allowance is
/// decreased by the same value.
/// `None` means unlimited allowance.
/// NOTE: To change or increase the allowance, the old access key needs to be deleted and a new
/// access key should be created.
#[serde(with = "option_u128_dec_format")]
pub allowance: Option<Balance>,

/// The access key only allows transactions with the given receiver's account id.
pub receiver_id: AccountId,

/// A list of method names that can be used. The access key only allows transactions with the
/// function call of one of the given method names.
/// Empty list means any method name can be used.
pub method_names: Vec<String>,
}
2 changes: 1 addition & 1 deletion core/primitives-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub use borsh;
pub use num_rational;

pub mod account;
pub mod access_key;
pub mod config;
pub mod contract;
pub mod hash;
Expand Down
4 changes: 3 additions & 1 deletion core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ bs58 = "0.4"
base64 = "0.13"
byteorder = "1.3"
chrono = { version = "0.4.4", features = ["serde"] }
csv = "1.1"
derive_more = "0.99.3"
easy-ext = "0.2"
sha2 = "0.9"
lazy_static = "1.4"
lazy-static-include = "3"
bowenwang1996 marked this conversation as resolved.
Show resolved Hide resolved
serde = { version = "1", features = ["derive"] }
serde_json = "1"
smart-default = "0.6"
Expand All @@ -43,7 +45,7 @@ default = ["jemallocator", "stable_protocol_features"]
dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"]
stable_protocol_features = ["protocol_feature_lower_storage_cost"]
protocol_feature_lower_storage_cost = []
protocol_feature_add_account_versions = ["near-primitives-core/protocol_feature_add_account_versions"]
protocol_feature_add_account_versions = []
protocol_feature_forward_chunk_parts = []
protocol_feature_rectify_inflation = []
protocol_feature_evm = ["near-primitives-core/protocol_feature_evm"]
Expand Down
Loading