Skip to content

Commit

Permalink
feat: prepare for 1.20.0 release (#4443)
Browse files Browse the repository at this point in the history
* feat: prepare for 1.20.0 release

* fix

* address comments
  • Loading branch information
bowenwang1996 authored Jul 1, 2021
1 parent 60713c9 commit d95a1ed
Show file tree
Hide file tree
Showing 41 changed files with 100 additions and 360 deletions.
5 changes: 2 additions & 3 deletions chain/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ no_cache = ["near-store/no_cache"]
protocol_feature_evm = ["near-primitives/protocol_feature_evm", "near-chain-configs/protocol_feature_evm"]
protocol_feature_block_header_v3 = []
protocol_feature_restore_receipts_after_fix = []
protocol_feature_cap_max_gas_price = []
nightly_protocol_features = ["nightly_protocol", "protocol_feature_block_header_v3", "protocol_feature_restore_receipts_after_fix", "protocol_feature_cap_max_gas_price"]
nightly_protocol_features = ["nightly_protocol", "protocol_feature_block_header_v3", "protocol_feature_restore_receipts_after_fix"]
nightly_protocol = []
sandbox = []
sandbox = []
3 changes: 1 addition & 2 deletions chain/chain/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ impl BlockEconomicsConfig {
}

pub fn max_gas_price(&self, protocol_version: ProtocolVersion) -> Balance {
if checked_feature!("protocol_feature_cap_max_gas_price", CapMaxGasPrice, protocol_version)
{
if checked_feature!("stable", CapMaxGasPrice, protocol_version) {
std::cmp::min(
self.max_gas_price,
Self::MAX_GAS_MULTIPLIER * self.min_gas_price(protocol_version),
Expand Down
6 changes: 1 addition & 5 deletions chain/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,9 @@ metric_recorder = ["near-client-primitives/metric_recorder"]
delay_detector = ["near-chain/delay_detector", "near-network/delay_detector", "delay-detector"]
protocol_feature_evm = ["near-primitives/protocol_feature_evm", "near-chain/protocol_feature_evm", "node-runtime/protocol_feature_evm"]
protocol_feature_block_header_v3 = ["near-primitives/protocol_feature_block_header_v3", "near-chain/protocol_feature_block_header_v3", "near-store/protocol_feature_block_header_v3"]
protocol_feature_add_account_versions = ["near-primitives/protocol_feature_add_account_versions"]
protocol_feature_fix_storage_usage = ["near-primitives/protocol_feature_fix_storage_usage"]
protocol_feature_restore_receipts_after_fix = []
protocol_feature_cap_max_gas_price = ["near-primitives/protocol_feature_cap_max_gas_price"]
protocol_feature_count_refund_receipts_in_gas_limit = ["near-primitives/protocol_feature_count_refund_receipts_in_gas_limit", "node-runtime/protocol_feature_count_refund_receipts_in_gas_limit"]
nightly_protocol = []
nightly_protocol_features = ["nightly_protocol", "near-chain/nightly_protocol_features", "protocol_feature_block_header_v3", "protocol_feature_add_account_versions", "protocol_feature_fix_storage_usage", "protocol_feature_restore_receipts_after_fix", "protocol_feature_cap_max_gas_price", "protocol_feature_count_refund_receipts_in_gas_limit"]
nightly_protocol_features = ["nightly_protocol", "near-chain/nightly_protocol_features", "protocol_feature_block_header_v3", "protocol_feature_restore_receipts_after_fix"]
sandbox = ["near-network/sandbox", "near-chain/sandbox", "node-runtime/sandbox"]

[[test]]
Expand Down
3 changes: 0 additions & 3 deletions chain/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,6 @@ mod test {

use cached::Cached;

#[cfg(feature = "protocol_feature_cap_max_gas_price")]
use near_chain::Provenance;
use near_chain::{ChainGenesis, RuntimeAdapter};
use near_chain_configs::Genesis;
Expand All @@ -1681,7 +1680,6 @@ mod test {
use near_primitives::block::{Approval, ApprovalInner};
use near_primitives::hash::hash;
use near_primitives::validator_signer::InMemoryValidatorSigner;
#[cfg(feature = "protocol_feature_cap_max_gas_price")]
use near_primitives::version::ProtocolFeature;
use near_primitives::version::PROTOCOL_VERSION;
use near_store::test_utils::create_test_store;
Expand Down Expand Up @@ -1763,7 +1761,6 @@ mod test {
assert_eq!(env.clients[0].pending_approvals.cache_size(), 0);
}

#[cfg(feature = "protocol_feature_cap_max_gas_price")]
#[test]
fn test_cap_max_gas_price() {
let mut genesis = Genesis::test(vec!["test0", "test1"], 1);
Expand Down
25 changes: 6 additions & 19 deletions chain/client/tests/process_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use near_network::{
};
use near_primitives::block::{Approval, ApprovalInner};
use near_primitives::block_header::BlockHeader;
use near_primitives::checked_feature;

use near_primitives::errors::InvalidTxError;
use near_primitives::errors::TxExecutionError;
Expand Down Expand Up @@ -2381,16 +2380,7 @@ fn test_refund_receipts_processing() {
}

let ending_block_height = block_height - 1;
let count_refund_receipts_in_gas_limit = checked_feature!(
"protocol_feature_count_refund_receipts_in_gas_limit",
CountRefundReceiptsInGasLimit,
genesis.config.protocol_version
);
let begin_block_height = if count_refund_receipts_in_gas_limit {
ending_block_height - refund_receipt_ids.len() as u64 + 1
} else {
ending_block_height
};
let begin_block_height = ending_block_height - refund_receipt_ids.len() as u64 + 1;
let mut processed_refund_receipt_ids = HashSet::new();
for i in begin_block_height..=ending_block_height {
let block = env.clients[0].chain.get_block_by_height(i).unwrap().clone();
Expand All @@ -2404,12 +2394,8 @@ fn test_refund_receipts_processing() {
processed_refund_receipt_ids.insert(outcome.outcome_with_id.id);
});
let chunk_extra = env.clients[0].chain.get_chunk_extra(block.hash(), 0).unwrap().clone();
if count_refund_receipts_in_gas_limit {
assert_eq!(execution_outcomes_from_block.len(), 1);
assert!(chunk_extra.gas_used() >= chunk_extra.gas_limit());
} else {
assert_eq!(chunk_extra.gas_used(), 0);
}
assert_eq!(execution_outcomes_from_block.len(), 1);
assert!(chunk_extra.gas_used() >= chunk_extra.gas_limit());
}
assert_eq!(processed_refund_receipt_ids, refund_receipt_ids);
}
Expand Down Expand Up @@ -3182,8 +3168,10 @@ mod protocol_feature_restore_receipts_after_fix_tests {
}
}

// This test cannot be enabled at the same time as `protocol_feature_block_header_v3`.
// Otherwise `get_mut` for block header will panic.
#[cfg(test)]
#[cfg(feature = "protocol_feature_fix_storage_usage")]
#[cfg(not(feature = "protocol_feature_block_header_v3"))]
mod storage_usage_fix_tests {
use super::*;
use borsh::BorshDeserialize;
Expand Down Expand Up @@ -3267,7 +3255,6 @@ mod storage_usage_fix_tests {
}
}

#[cfg(feature = "protocol_feature_cap_max_gas_price")]
#[cfg(test)]
mod cap_max_gas_price_tests {
use super::*;
Expand Down
3 changes: 0 additions & 3 deletions core/primitives-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,4 @@ lazy_static = "1.4"
[features]
default = []
protocol_feature_evm = []
protocol_feature_add_account_versions = []
protocol_feature_alt_bn128 = []
protocol_feature_tx_size_limit = []
protocol_feature_math_extension = []
27 changes: 2 additions & 25 deletions core/primitives-core/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};
use std::io;

use crate::hash::CryptoHash;
use crate::serialize::{option_u128_dec_format, u128_dec_format_compatible};
use crate::types::{AccountId, Balance, Nonce, StorageUsage};
#[cfg(feature = "protocol_feature_add_account_versions")]
use std::io;

#[cfg(feature = "protocol_feature_add_account_versions")]
#[derive(
BorshSerialize, BorshDeserialize, Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Copy,
)]
pub enum AccountVersion {
V1,
}

#[cfg(feature = "protocol_feature_add_account_versions")]
impl Default for AccountVersion {
fn default() -> Self {
AccountVersion::V1
Expand All @@ -24,10 +20,6 @@ impl Default for AccountVersion {

/// Per account information stored in the state.
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
#[cfg_attr(
not(feature = "protocol_feature_add_account_versions"),
derive(BorshSerialize, BorshDeserialize)
)]
pub struct Account {
/// The total not locked tokens.
#[serde(with = "u128_dec_format_compatible")]
Expand All @@ -40,7 +32,6 @@ pub struct Account {
/// Storage used by the given account, includes account id, this struct, access keys and other data.
storage_usage: StorageUsage,
/// Version of Account in re migrations and similar
#[cfg(feature = "protocol_feature_add_account_versions")]
#[serde(default)]
version: AccountVersion,
}
Expand All @@ -56,14 +47,7 @@ impl Account {
code_hash: CryptoHash,
storage_usage: StorageUsage,
) -> Self {
Account {
amount,
locked,
code_hash,
storage_usage,
#[cfg(feature = "protocol_feature_add_account_versions")]
version: AccountVersion::V1,
}
Account { amount, locked, code_hash, storage_usage, version: AccountVersion::V1 }
}

#[inline]
Expand All @@ -87,7 +71,6 @@ impl Account {
}

#[inline]
#[cfg(feature = "protocol_feature_add_account_versions")]
pub fn version(&self) -> AccountVersion {
self.version
}
Expand All @@ -112,14 +95,11 @@ impl Account {
self.storage_usage = storage_usage;
}

#[inline]
#[cfg(feature = "protocol_feature_add_account_versions")]
pub fn set_version(&mut self, version: AccountVersion) {
self.version = version;
}
}

#[cfg(feature = "protocol_feature_add_account_versions")]
#[derive(BorshSerialize, BorshDeserialize)]
struct LegacyAccount {
amount: Balance,
Expand All @@ -128,7 +108,6 @@ struct LegacyAccount {
storage_usage: StorageUsage,
}

#[cfg(feature = "protocol_feature_add_account_versions")]
impl BorshDeserialize for Account {
fn deserialize(buf: &mut &[u8]) -> Result<Self, io::Error> {
if buf.len() == std::mem::size_of::<LegacyAccount>() {
Expand All @@ -148,7 +127,6 @@ impl BorshDeserialize for Account {
}
}

#[cfg(feature = "protocol_feature_add_account_versions")]
impl BorshSerialize for Account {
fn serialize<W: io::Write>(&self, writer: &mut W) -> io::Result<()> {
match self.version {
Expand Down Expand Up @@ -245,7 +223,6 @@ mod tests {
}

#[test]
#[cfg(feature = "protocol_feature_add_account_versions")]
fn test_account_deserialization() {
let old_account = LegacyAccount {
amount: 100,
Expand Down
17 changes: 0 additions & 17 deletions core/primitives-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ pub struct VMLimitConfig {
/// Max contract size
pub max_contract_size: u64,
/// Max transaction size
#[cfg(feature = "protocol_feature_tx_size_limit")]
pub max_transaction_size: u64,
/// Max storage key size
pub max_length_storage_key: u64,
Expand Down Expand Up @@ -154,7 +153,6 @@ impl Default for VMLimitConfig {
max_arguments_length: 4 * 2u64.pow(20), // 4 Mib
max_length_returned_data: 4 * 2u64.pow(20), // 4 Mib
max_contract_size: 4 * 2u64.pow(20), // 4 Mib,
#[cfg(feature = "protocol_feature_tx_size_limit")]
max_transaction_size: 4 * 2u64.pow(20), // 4 Mib

max_length_storage_key: 4 * 2u64.pow(20), // 4 Mib
Expand Down Expand Up @@ -223,14 +221,11 @@ pub struct ExtCostsConfig {
/// Cost of getting sha256 per byte
pub keccak512_byte: Gas,

#[cfg(feature = "protocol_feature_math_extension")]
/// Cost of getting ripemd160 base
pub ripemd160_base: Gas,
#[cfg(feature = "protocol_feature_math_extension")]
/// Cost of getting ripemd160 per message block
pub ripemd160_block: Gas,

#[cfg(feature = "protocol_feature_math_extension")]
/// Cost of calling ecrecover
pub ecrecover_base: Gas,

Expand Down Expand Up @@ -364,12 +359,9 @@ impl Default for ExtCostsConfig {
keccak256_byte: SAFETY_MULTIPLIER * 7157035,
keccak512_base: SAFETY_MULTIPLIER * 1937129412,
keccak512_byte: SAFETY_MULTIPLIER * 12216567,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_base: SAFETY_MULTIPLIER * 284558362,
#[cfg(feature = "protocol_feature_math_extension")]
// Cost per byte is 3542227. There are 64 bytes in a block.
ripemd160_block: SAFETY_MULTIPLIER * 226702528,
#[cfg(feature = "protocol_feature_math_extension")]
ecrecover_base: SAFETY_MULTIPLIER * 1121789875000,
log_base: SAFETY_MULTIPLIER * 1181104350,
log_byte: SAFETY_MULTIPLIER * 4399597,
Expand Down Expand Up @@ -441,11 +433,8 @@ impl ExtCostsConfig {
keccak256_byte: 0,
keccak512_base: 0,
keccak512_byte: 0,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_base: 0,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_block: 0,
#[cfg(feature = "protocol_feature_math_extension")]
ecrecover_base: 0,
log_base: 0,
log_byte: 0,
Expand Down Expand Up @@ -518,11 +507,8 @@ pub enum ExtCosts {
keccak256_byte,
keccak512_base,
keccak512_byte,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_base,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_block,
#[cfg(feature = "protocol_feature_math_extension")]
ecrecover_base,
log_base,
log_byte,
Expand Down Expand Up @@ -648,11 +634,8 @@ impl ExtCosts {
keccak256_byte => config.keccak256_byte,
keccak512_base => config.keccak512_base,
keccak512_byte => config.keccak512_byte,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_base => config.ripemd160_base,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_block => config.ripemd160_block,
#[cfg(feature = "protocol_feature_math_extension")]
ecrecover_base => config.ecrecover_base,
log_base => config.log_base,
log_byte => config.log_byte,
Expand Down
9 changes: 1 addition & 8 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,11 @@ near-rpc-error-macro = { path = "../../tools/rpctypegen/macro" }
[features]
default = ["jemallocator"]
dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"]
protocol_feature_add_account_versions = ["near-primitives-core/protocol_feature_add_account_versions"]
protocol_feature_evm = ["near-primitives-core/protocol_feature_evm"]
protocol_feature_block_header_v3 = []
protocol_feature_alt_bn128 = ["near-primitives-core/protocol_feature_alt_bn128", "near-vm-errors/protocol_feature_alt_bn128"]
protocol_feature_tx_size_limit = ["near-primitives-core/protocol_feature_tx_size_limit"]
protocol_feature_allow_create_account_on_delete = []
protocol_feature_fix_storage_usage = []
protocol_feature_restore_receipts_after_fix = []
protocol_feature_cap_max_gas_price = []
protocol_feature_count_refund_receipts_in_gas_limit = []
protocol_feature_math_extension = ["near-primitives-core/protocol_feature_math_extension"]
nightly_protocol_features = ["nightly_protocol", "protocol_feature_evm", "protocol_feature_block_header_v3", "protocol_feature_alt_bn128", "protocol_feature_add_account_versions", "protocol_feature_tx_size_limit", "protocol_feature_allow_create_account_on_delete", "protocol_feature_fix_storage_usage", "protocol_feature_restore_receipts_after_fix", "protocol_feature_cap_max_gas_price", "protocol_feature_count_refund_receipts_in_gas_limit", "protocol_feature_math_extension"]
nightly_protocol_features = ["nightly_protocol", "protocol_feature_evm", "protocol_feature_block_header_v3", "protocol_feature_alt_bn128", "protocol_feature_restore_receipts_after_fix"]
nightly_protocol = []

[dev-dependencies]
Expand Down
2 changes: 0 additions & 2 deletions core/primitives/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ pub enum InvalidTxError {
/// An error occurred while validating actions of a Transaction.
ActionsValidation(ActionsValidationError),
/// The size of serialized transaction exceeded the limit.
#[cfg(feature = "protocol_feature_tx_size_limit")]
TransactionSizeExceeded { size: u64, limit: u64 },
}

Expand Down Expand Up @@ -492,7 +491,6 @@ impl Display for InvalidTxError {
tx_nonce, upper_bound
)
}
#[cfg(feature = "protocol_feature_tx_size_limit")]
InvalidTxError::TransactionSizeExceeded { size, limit } => {
write!(f, "Size of serialized transaction {} exceeded the limit {}", size, limit)
}
Expand Down
4 changes: 0 additions & 4 deletions core/primitives/src/runtime/migration_data.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#[cfg(feature = "protocol_feature_restore_receipts_after_fix")]
use crate::receipt::ReceiptResult;
#[cfg(feature = "protocol_feature_fix_storage_usage")]
use crate::types::AccountId;
#[cfg(feature = "protocol_feature_fix_storage_usage")]
use crate::types::Gas;
use std::fmt;
use std::fmt::{Debug, Formatter};

#[derive(Default)]
pub struct MigrationData {
#[cfg(feature = "protocol_feature_fix_storage_usage")]
pub storage_usage_delta: Vec<(AccountId, u64)>,
#[cfg(feature = "protocol_feature_fix_storage_usage")]
pub storage_usage_fix_gas: Gas,
#[cfg(feature = "protocol_feature_restore_receipts_after_fix")]
pub restored_receipts: ReceiptResult,
Expand Down
Loading

0 comments on commit d95a1ed

Please sign in to comment.