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: stabilize meta transactions NEP-366 #8601

Merged
merged 2 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions chain/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ nightly = [
"nightly_protocol",
"protocol_feature_flat_state",
"near-chain/nightly",
"protocol_feature_nep366_delegate_action"
]
sandbox = [
"near-client-primitives/sandbox",
"near-chain/sandbox",
]
protocol_feature_flat_state = ["near-store/protocol_feature_flat_state", "near-chain/protocol_feature_flat_state"]
protocol_feature_nep366_delegate_action = []
6 changes: 1 addition & 5 deletions chain/client/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ use near_chunks::adapter::ShardsManagerRequestFromClient;
use near_chunks::client::ShardsManagerResponse;
use near_chunks::test_utils::{MockClientAdapterForShardsManager, SynchronousShardsManagerAdapter};
use near_client_primitives::types::Error;
#[cfg(feature = "protocol_feature_nep366_delegate_action")]
use near_crypto::Signer;
use near_crypto::{InMemorySigner, KeyType, PublicKey};
use near_crypto::{InMemorySigner, KeyType, PublicKey, Signer};
use near_network::test_utils::MockPeerManagerAdapter;
use near_network::types::{
AccountOrPeerIdOrHash, HighestHeightPeerInfo, PartialEncodedChunkRequestMsg,
Expand All @@ -54,7 +52,6 @@ use near_network::types::{
use near_o11y::testonly::TracingCapture;
use near_o11y::WithSpanContextExt;
use near_primitives::block::{ApprovalInner, Block, GenesisId};
#[cfg(feature = "protocol_feature_nep366_delegate_action")]
use near_primitives::delegate_action::{DelegateAction, NonDelegateAction, SignedDelegateAction};
use near_primitives::epoch_manager::RngSeed;
use near_primitives::hash::{hash, CryptoHash};
Expand Down Expand Up @@ -1828,7 +1825,6 @@ impl TestEnv {
}

/// Wrap actions in a delegate action, put it in a transaction, sign.
#[cfg(feature = "protocol_feature_nep366_delegate_action")]
pub fn meta_tx_from_actions(
&mut self,
actions: Vec<Action>,
Expand Down
7 changes: 1 addition & 6 deletions chain/rosetta-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,4 @@ insta = "1"
near-actix-test-utils = { path = "../../test-utils/actix-test-utils" }

[features]
protocol_feature_nep366_delegate_action = [
"near-primitives/protocol_feature_nep366_delegate_action"
]
nightly = [
"protocol_feature_nep366_delegate_action"
]
nightly = []
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 @@ -419,8 +419,8 @@ impl From<NearActions> for Vec<crate::models::Operation> {
);
operations.push(deploy_contract_operation);
}
#[cfg(feature = "protocol_feature_nep366_delegate_action")]
near_primitives::transaction::Action::Delegate(_) => todo!(),
// TODO(#8469): Implement delegate action support, for now they are ignored.
near_primitives::transaction::Action::Delegate(_) => (),
}
}
operations
Expand Down
3 changes: 1 addition & 2 deletions core/primitives-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ insta.workspace = true

[features]
default = []
protocol_feature_nep366_delegate_action = []
nightly = ["protocol_feature_nep366_delegate_action"]
nightly = []
1 change: 0 additions & 1 deletion core/primitives-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ pub enum ActionCosts {
new_action_receipt = 12,
new_data_receipt_base = 13,
new_data_receipt_byte = 14,
#[cfg(feature = "protocol_feature_nep366_delegate_action")]
delegate = 15,
}

Expand Down
1 change: 0 additions & 1 deletion core/primitives-core/src/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ impl From<ActionCosts> for FeeParameter {
match other {
ActionCosts::create_account => Self::ActionCreateAccount,
ActionCosts::delete_account => Self::ActionDeleteAccount,
#[cfg(feature = "protocol_feature_nep366_delegate_action")]
ActionCosts::delegate => Self::ActionDelegate,
ActionCosts::deploy_contract_base => Self::ActionDeployContract,
ActionCosts::deploy_contract_byte => Self::ActionDeployContractPerByte,
Expand Down
7 changes: 3 additions & 4 deletions core/primitives-core/src/runtime/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,10 @@ impl RuntimeFeesConfig {
send_not_sir: 59357464,
execution: 59357464,
},
#[cfg(feature = "protocol_feature_nep366_delegate_action")]
ActionCosts::delegate => Fee {
send_sir: 2319861500000,
send_not_sir: 2319861500000,
execution: 2319861500000,
send_sir: 200_000_000_000,
send_not_sir: 200_000_000_000,
execution: 200_000_000_000,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: core/primitives-core/src/profile.rs
expression: pretty_debug_str
---
------------------------------
Action gas: 15105
Action gas: 16120
------ Host functions --------
contract_loading_base -> 1 [0% host]
contract_loading_bytes -> 2 [0% host]
Expand Down Expand Up @@ -81,5 +81,6 @@ delete_key -> 1011
new_action_receipt -> 1012
new_data_receipt_base -> 1013
new_data_receipt_byte -> 1014
delegate -> 1015
------------------------------

4 changes: 0 additions & 4 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,11 @@ dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"]
protocol_feature_fix_staking_threshold = []
protocol_feature_fix_contract_loading_cost = []
protocol_feature_reject_blocks_with_outdated_protocol_version = []
protocol_feature_nep366_delegate_action = [
"near-primitives-core/protocol_feature_nep366_delegate_action"
]
nightly = [
"nightly_protocol",
"protocol_feature_fix_staking_threshold",
"protocol_feature_fix_contract_loading_cost",
"protocol_feature_reject_blocks_with_outdated_protocol_version",
"protocol_feature_nep366_delegate_action",
]

nightly_protocol = []
Expand Down
42 changes: 1 addition & 41 deletions core/primitives/src/delegate_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,12 @@ pub struct DelegateAction {
pub public_key: PublicKey,
}

#[cfg_attr(feature = "protocol_feature_nep366_delegate_action", derive(BorshDeserialize))]
#[derive(BorshSerialize, Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
pub struct SignedDelegateAction {
pub delegate_action: DelegateAction,
pub signature: Signature,
}

#[cfg(not(feature = "protocol_feature_nep366_delegate_action"))]
impl borsh::de::BorshDeserialize for SignedDelegateAction {
fn deserialize(_buf: &mut &[u8]) -> ::core::result::Result<Self, borsh::maybestd::io::Error> {
return Err(Error::new(ErrorKind::InvalidInput, "Delegate action isn't supported"));
}
}

impl SignedDelegateAction {
pub fn verify(&self) -> bool {
let delegate_action = &self.delegate_action;
Expand All @@ -62,7 +54,6 @@ impl SignedDelegateAction {
}
}

#[cfg(feature = "protocol_feature_nep366_delegate_action")]
impl From<SignedDelegateAction> for Action {
fn from(delegate_action: SignedDelegateAction) -> Self {
Self::Delegate(delegate_action)
Expand Down Expand Up @@ -112,7 +103,6 @@ mod private_non_delegate_action {
#[error("attempted to construct NonDelegateAction from Action::Delegate")]
pub struct IsDelegateAction;

#[cfg(feature = "protocol_feature_nep366_delegate_action")]
impl TryFrom<Action> for NonDelegateAction {
type Error = IsDelegateAction;

Expand Down Expand Up @@ -149,9 +139,7 @@ mod private_non_delegate_action {
#[cfg(test)]
mod tests {
use super::*;
#[cfg(feature = "protocol_feature_nep366_delegate_action")]
use crate::transaction::CreateAccountAction;
#[cfg(feature = "protocol_feature_nep366_delegate_action")]
use near_crypto::KeyType;

/// A serialized `Action::Delegate(SignedDelegateAction)` for testing.
Expand All @@ -167,7 +155,6 @@ mod tests {
"0000000000000000000000000000000000000000000000000000000000"
);

#[cfg(feature = "protocol_feature_nep366_delegate_action")]
fn create_delegate_action(actions: Vec<Action>) -> Action {
Action::Delegate(SignedDelegateAction {
delegate_action: DelegateAction {
Expand All @@ -186,7 +173,6 @@ mod tests {
}

#[test]
#[cfg(feature = "protocol_feature_nep366_delegate_action")]
fn test_delegate_action_deserialization() {
// Expected an error. Buffer is empty
assert_eq!(
Expand Down Expand Up @@ -218,35 +204,9 @@ mod tests {
);
}

/// Check that we will not accept delegate actions with the feature
/// disabled.
///
/// This test is to ensure that while working on meta transactions, we don't
/// accientally start accepting delegate actions in receipts. Otherwise, a
/// malicious validator could create receipts that include delegate actions
/// and other nodes will accept such a receipt.
///
/// TODO: Before stabilizing "protocol_feature_nep366_delegate_action" we
/// have to replace this rest with a test that checks that we discard
/// delegate actions for earlier versions somewhere in validation.
#[test]
#[cfg(not(feature = "protocol_feature_nep366_delegate_action"))]
fn test_delegate_action_deserialization() {
let serialized_delegate_action = hex::decode(DELEGATE_ACTION_HEX).expect("invalid hex");

// DelegateAction isn't supported
assert_eq!(
Action::try_from_slice(&serialized_delegate_action).map_err(|e| e.kind()),
Err(ErrorKind::InvalidInput)
);
}

/// Check that the hard-coded delegate action is valid.
#[test]
#[cfg(feature = "protocol_feature_nep366_delegate_action")]
fn test_delegate_action_deserialization_hard_coded() {
use crate::transaction::CreateAccountAction;

let serialized_delegate_action = hex::decode(DELEGATE_ACTION_HEX).expect("invalid hex");
// The hex data is the same as the one we create below.
let delegate_action =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ expression: config_view
"send_sir": 147489000000,
"send_not_sir": 147489000000,
"execution": 147489000000
},
"delegate_cost": {
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 200000000000
}
},
"storage_usage_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ expression: config_view
"send_sir": 147489000000,
"send_not_sir": 147489000000,
"execution": 147489000000
},
"delegate_cost": {
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 200000000000
}
},
"storage_usage_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ expression: config_view
"send_sir": 147489000000,
"send_not_sir": 147489000000,
"execution": 147489000000
},
"delegate_cost": {
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 200000000000
}
},
"storage_usage_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ expression: config_view
"send_sir": 147489000000,
"send_not_sir": 147489000000,
"execution": 147489000000
},
"delegate_cost": {
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 200000000000
}
},
"storage_usage_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ expression: config_view
"send_sir": 147489000000,
"send_not_sir": 147489000000,
"execution": 147489000000
},
"delegate_cost": {
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 200000000000
}
},
"storage_usage_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ expression: config_view
"send_sir": 147489000000,
"send_not_sir": 147489000000,
"execution": 147489000000
},
"delegate_cost": {
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 200000000000
}
},
"storage_usage_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ expression: config_view
"send_sir": 147489000000,
"send_not_sir": 147489000000,
"execution": 147489000000
},
"delegate_cost": {
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 200000000000
}
},
"storage_usage_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ expression: config_view
"send_sir": 147489000000,
"send_not_sir": 147489000000,
"execution": 147489000000
},
"delegate_cost": {
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 200000000000
}
},
"storage_usage_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ expression: config_view
"send_sir": 147489000000,
"send_not_sir": 147489000000,
"execution": 147489000000
},
"delegate_cost": {
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 200000000000
}
},
"storage_usage_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ expression: config_view
"send_sir": 147489000000,
"send_not_sir": 147489000000,
"execution": 147489000000
},
"delegate_cost": {
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 200000000000
}
},
"storage_usage_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ expression: config_view
"send_sir": 147489000000,
"send_not_sir": 147489000000,
"execution": 147489000000
},
"delegate_cost": {
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 200000000000
}
},
"storage_usage_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ expression: config_view
"send_sir": 147489000000,
"send_not_sir": 147489000000,
"execution": 147489000000
},
"delegate_cost": {
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 200000000000
}
},
"storage_usage_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ expression: config_view
"send_sir": 147489000000,
"send_not_sir": 147489000000,
"execution": 147489000000
},
"delegate_cost": {
"send_sir": 200000000000,
"send_not_sir": 200000000000,
"execution": 200000000000
}
},
"storage_usage_config": {
Expand Down
Loading