Skip to content

Commit

Permalink
chore: Remove NEP-491 (#12818)
Browse files Browse the repository at this point in the history
There is ongoing work on [global
contracts](#12716) that addresses
the problem near/NEPs#491 was originally
designed to solve. NEP-491 code is quite messy and has been around for
about a year. We no longer see external interest in this feature, but if
the need arises in the future, we can always restore the code.

Reverts most of (because some part is used by
#12794):
- #9600
- #10701

Also, #11005 can be closed.
  • Loading branch information
staffik authored Jan 30, 2025
1 parent 30dccce commit 9a4504c
Show file tree
Hide file tree
Showing 41 changed files with 59 additions and 1,298 deletions.
2 changes: 0 additions & 2 deletions chain/chain/src/test_utils/kv_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,10 +1267,8 @@ impl RuntimeAdapter for KeyValueRuntime {
|state| *state.amounts.get(account_id).unwrap_or(&0),
),
0,
0,
CryptoHash::default(),
0,
PROTOCOL_VERSION,
)
.into(),
),
Expand Down
2 changes: 0 additions & 2 deletions chain/rosetta-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ near-actix-test-utils.workspace = true
near-time.workspace = true

[features]
protocol_feature_nonrefundable_transfer_nep491 = []
nightly_protocol = [
"near-actix-test-utils/nightly_protocol",
"near-chain-configs/nightly_protocol",
Expand All @@ -67,5 +66,4 @@ nightly = [
"near-primitives/nightly",
"nightly_protocol",
"node-runtime/nightly",
"protocol_feature_nonrefundable_transfer_nep491",
]
58 changes: 0 additions & 58 deletions chain/rosetta-rpc/src/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,23 +352,6 @@ impl From<NearActions> for Vec<crate::models::Operation> {
);
}

#[cfg(feature = "protocol_feature_nonrefundable_transfer_nep491")]
// Non-refundable transfer deposit is burnt for permanent storage bytes on the receiving account.
near_primitives::transaction::Action::NonrefundableStorageTransfer(action) => {
let transfer_amount = crate::models::Amount::from_yoctonear(action.deposit);

let sender_transfer_operation_id =
crate::models::OperationIdentifier::new(&operations);
operations.push(
validated_operations::TransferOperation {
account: sender_account_identifier.clone(),
amount: -transfer_amount.clone(),
predecessor_id: Some(sender_account_identifier.clone()),
}
.into_operation(sender_transfer_operation_id.clone()),
);
}

near_primitives::transaction::Action::Stake(action) => {
operations.push(
validated_operations::StakeOperation {
Expand Down Expand Up @@ -884,8 +867,6 @@ mod tests {
amount: 5000000000000000000,
code_hash: near_primitives::hash::CryptoHash::default(),
locked: 400000000000000000000000000000,
#[cfg(feature = "protocol_feature_nonrefundable_transfer_nep491")]
permanent_storage_bytes: 0,
storage_paid_at: 0,
storage_usage: 200000,
},
Expand All @@ -901,8 +882,6 @@ mod tests {
amount: 4000000000000000000,
code_hash: near_primitives::hash::CryptoHash::default(),
locked: 400000000000000000000000000000,
#[cfg(feature = "protocol_feature_nonrefundable_transfer_nep491")]
permanent_storage_bytes: 0,
storage_paid_at: 0,
storage_usage: 200000,
},
Expand All @@ -916,8 +895,6 @@ mod tests {
amount: 7000000000000000000,
code_hash: near_primitives::hash::CryptoHash::default(),
locked: 400000000000000000000000000000,
#[cfg(feature = "protocol_feature_nonrefundable_transfer_nep491")]
permanent_storage_bytes: 0,
storage_paid_at: 0,
storage_usage: 200000,
},
Expand All @@ -933,8 +910,6 @@ mod tests {
amount: 8000000000000000000,
code_hash: near_primitives::hash::CryptoHash::default(),
locked: 400000000000000000000000000000,
#[cfg(feature = "protocol_feature_nonrefundable_transfer_nep491")]
permanent_storage_bytes: 0,
storage_paid_at: 0,
storage_usage: 200000,
},
Expand All @@ -948,8 +923,6 @@ mod tests {
amount: 4000000000000000000,
code_hash: near_primitives::hash::CryptoHash::default(),
locked: 400000000000000000000000000000,
#[cfg(feature = "protocol_feature_nonrefundable_transfer_nep491")]
permanent_storage_bytes: 0,
storage_paid_at: 0,
storage_usage: 200000,
},
Expand All @@ -960,8 +933,6 @@ mod tests {
amount: 6000000000000000000,
code_hash: near_primitives::hash::CryptoHash::default(),
locked: 400000000000000000000000000000,
#[cfg(feature = "protocol_feature_nonrefundable_transfer_nep491")]
permanent_storage_bytes: 0,
storage_paid_at: 0,
storage_usage: 200000,
},
Expand Down Expand Up @@ -1592,33 +1563,4 @@ mod tests {
Err(crate::errors::ErrorKind::InvalidInput(_))
));
}

#[cfg(feature = "protocol_feature_nonrefundable_transfer_nep491")]
#[test]
fn test_convert_nonrefundable_storage_transfer_action() {
let deposit = near_primitives::types::Balance::MAX - 1;
let nonrefundable_transfer_actions = vec![
near_primitives::transaction::NonrefundableStorageTransferAction { deposit }.into(),
];
let near_nonrefundable_transfer_actions = NearActions {
sender_account_id: "sender.near".parse().unwrap(),
receiver_account_id: "receiver.near".parse().unwrap(),
actions: nonrefundable_transfer_actions,
};
let nonrefundable_transfer_operations_converted: Vec<crate::models::Operation> =
near_nonrefundable_transfer_actions.into();
assert_eq!(nonrefundable_transfer_operations_converted.len(), 1);
assert_eq!(
nonrefundable_transfer_operations_converted[0].type_,
crate::models::OperationType::Transfer
);
assert_eq!(
nonrefundable_transfer_operations_converted[0].account,
"sender.near".parse().unwrap()
);
assert_eq!(
nonrefundable_transfer_operations_converted[0].amount,
Some(-crate::models::Amount::from_yoctonear(deposit))
);
}
}
12 changes: 2 additions & 10 deletions chain/rosetta-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use config::RosettaRpcConfig;
use near_chain_configs::Genesis;
use near_client::{ClientActor, ViewClientActor};
use near_o11y::WithSpanContextExt;
use near_primitives::{borsh::BorshDeserialize, version::PROTOCOL_VERSION};
use near_primitives::borsh::BorshDeserialize;

mod adapters;
mod config;
Expand Down Expand Up @@ -369,15 +369,7 @@ async fn account_balance(
Err(crate::errors::ErrorKind::NotFound(_)) => (
block.header.hash,
block.header.height,
near_primitives::account::Account::new(
0,
0,
0,
Default::default(),
0,
PROTOCOL_VERSION,
)
.into(),
near_primitives::account::Account::new(0, 0, Default::default(), 0).into(),
),
Err(err) => return Err(err.into()),
};
Expand Down
2 changes: 0 additions & 2 deletions core/chain-configs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ near-primitives.workspace = true
near-config-utils.workspace = true

[features]
protocol_feature_nonrefundable_transfer_nep491 = []
nightly_protocol = [
"near-o11y/nightly_protocol",
"near-parameters/nightly_protocol",
Expand All @@ -43,7 +42,6 @@ nightly = [
"near-parameters/nightly",
"near-primitives/nightly",
"nightly_protocol",
"protocol_feature_nonrefundable_transfer_nep491",
]
test_genesis = ["near-primitives/rand", "near-primitives/test_utils"]
test_utils = ["near-primitives/rand"]
Expand Down
22 changes: 1 addition & 21 deletions core/chain-configs/src/genesis_validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,31 +200,11 @@ mod test {
use near_crypto::{KeyType, PublicKey};
use near_primitives::account::{AccessKey, Account};
use near_primitives::types::AccountInfo;
use near_primitives::version::PROTOCOL_VERSION;

const VALID_ED25519_RISTRETTO_KEY: &str = "ed25519:KuTCtARNzxZQ3YvXDeLjx83FDqxv2SdQTSbiq876zR7";

fn create_account() -> Account {
Account::new(100, 10, 0, Default::default(), 0, PROTOCOL_VERSION)
}

#[cfg(feature = "protocol_feature_nonrefundable_transfer_nep491")]
#[test]
fn test_total_supply_does_not_depend_on_permanent_storage_bytes() {
let mut config = GenesisConfig::default();
config.epoch_length = 42;
config.total_supply = 110;
config.validators = vec![AccountInfo {
account_id: "test".parse().unwrap(),
public_key: VALID_ED25519_RISTRETTO_KEY.parse().unwrap(),
amount: 10,
}];
let records = GenesisRecords(vec![StateRecord::Account {
account_id: "test".parse().unwrap(),
account: Account::new(100, 10, 1, Default::default(), 0, PROTOCOL_VERSION),
}]);
let genesis = &Genesis::new(config, records).unwrap();
validate_genesis(genesis).unwrap();
Account::new(100, 10, Default::default(), 0)
}

#[test]
Expand Down
11 changes: 1 addition & 10 deletions core/chain-configs/src/test_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,8 @@ impl TestGenesisBuilder {
account: Account::new(
user_account.balance,
validator_stake.remove(&user_account.account_id).unwrap_or(0),
0,
CryptoHash::default(),
0,
self.protocol_version,
),
});
for access_key in &user_account.access_keys {
Expand All @@ -467,14 +465,7 @@ impl TestGenesisBuilder {
for (account_id, balance) in validator_stake {
records.push(StateRecord::Account {
account_id,
account: Account::new(
0,
balance,
0,
CryptoHash::default(),
0,
self.protocol_version,
),
account: Account::new(0, balance, CryptoHash::default(), 0),
});
}

Expand Down
2 changes: 1 addition & 1 deletion core/chain-configs/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub fn add_account_with_key(
) {
records.push(StateRecord::Account {
account_id: account_id.clone(),
account: Account::new(amount, staked, 0, code_hash, 0, PROTOCOL_VERSION),
account: Account::new(amount, staked, code_hash, 0),
});
records.push(StateRecord::AccessKey {
account_id,
Expand Down
2 changes: 0 additions & 2 deletions core/primitives-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ expect-test.workspace = true
[features]
default = []
protocol_feature_fix_contract_loading_cost = []
protocol_feature_nonrefundable_transfer_nep491 = []

nightly = [
"nightly_protocol",
"protocol_feature_fix_contract_loading_cost",
"protocol_feature_nonrefundable_transfer_nep491",
]

nightly_protocol = [
Expand Down
Loading

0 comments on commit 9a4504c

Please sign in to comment.