Skip to content

Commit

Permalink
Remove GovernanceRole from Aptos core
Browse files Browse the repository at this point in the history
  • Loading branch information
Sital Kedia authored and davidiw committed Mar 5, 2022
1 parent f57f736 commit a96e817
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 264 deletions.
27 changes: 4 additions & 23 deletions diem-move/diem-vm/src/adapter_common.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::{counters::*, create_access_path, data_cache::StateViewCache};
use crate::{counters::*, data_cache::StateViewCache};
use anyhow::Result;
use diem_state_view::StateView;
use diem_types::{
account_address::AccountAddress,
account_config::{self, RoleId},
transaction::{
GovernanceRole, SignatureCheckedTransaction, SignedTransaction, VMValidatorResult,
},
transaction::{SignatureCheckedTransaction, SignedTransaction, VMValidatorResult},
vm_status::{StatusCode, VMStatus},
};
use move_core_types::{move_resource::MoveStructType, resolver::MoveResolver};
use move_core_types::resolver::MoveResolver;
use move_vm_runtime::session::Session;

use crate::logging::AdapterLogSchema;
Expand Down Expand Up @@ -86,7 +82,6 @@ pub fn validate_signed_transaction<A: VMAdapter>(
state_view: &impl StateView,
) -> VMValidatorResult {
let _timer = TXN_VALIDATION_SECONDS.start_timer();
let txn_sender = transaction.sender();
let log_context = AdapterLogSchema::new(state_view.id(), 0);

let txn = match A::check_signature(transaction) {
Expand All @@ -97,7 +92,6 @@ pub fn validate_signed_transaction<A: VMAdapter>(
};

let remote_cache = StateViewCache::new(state_view);
let account_role = get_account_role(txn_sender, &remote_cache);
let mut session = adapter.new_session(&remote_cache);

let (status, gas_price) = match adapter.get_gas_price(&*txn, &remote_cache) {
Expand All @@ -123,20 +117,7 @@ pub fn validate_signed_transaction<A: VMAdapter>(
.with_label_values(&[counter_label])
.inc();

VMValidatorResult::new(status, gas_price, account_role)
}

fn get_account_role<S: StateView>(
sender: AccountAddress,
remote_cache: &StateViewCache<S>,
) -> GovernanceRole {
let role_access_path = create_access_path(sender, RoleId::struct_tag());
match remote_cache.get(&role_access_path) {
Ok(Some(blob)) => bcs::from_bytes::<account_config::RoleId>(&blob)
.map(|role_id| GovernanceRole::from_role_id(role_id.role_id()))
.unwrap_or(GovernanceRole::NonGovernanceRole),
_ => GovernanceRole::NonGovernanceRole,
}
VMValidatorResult::new(status, gas_price)
}

pub(crate) fn validate_signature_checked_transaction<S: MoveResolver, A: VMAdapter>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath { address: 0000000000000000000000000a550c18, path: 0100000000000000000000000000000001094469656d426c6f636b0d426c6f636b4d6574616461746100 }, Value(010000000000000001000000000000001811000000000000000000000000000000000000000a550c18)), (AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010d4469656d54696d657374616d701743757272656e7454696d654d6963726f7365636f6e647300 }, Value(0100000000000000))] }), events: [ContractEvent { key: EventKey(11000000000000000000000000000000000000000a550c18), index: 0, type: Struct(StructTag { address: 00000000000000000000000000000001, module: Identifier("DiemBlock"), name: Identifier("NewBlockEvent"), type_params: [] }), event_data: "000000000000000051c1b9fc2f32d6f2fff669823ef31cbe000100000000000000" }], gas_used: 100000000, status: Keep(EXECUTED) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath { address: 0000000000000000000000000b1e55ed, path: 01000000000000000000000000000000010b4469656d4163636f756e740b4469656d4163636f756e7400 }, Value(207deeccb1080854f499ec8b4c1b213b82c5e34b925cf6875fec02d4b77adbd2d6010000000000000000000000000b1e55ed010000000000000000000000000b1e55ed00000000000000001801000000000000000000000000000000000000000b1e55ed00000000000000001802000000000000000000000000000000000000000b1e55ed0100000000000000))] }), events: [], gas_used: 72, status: Keep(EXECUTED) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010b4469656d4163636f756e740b4469656d4163636f756e7400 }, Value(20872d108c30648f16843e29655b181edc12dcc9318ec7d90d98a52801cdcd96c9010000000000000000000000000a550c18010000000000000000000000000a550c1800000000000000001802000000000000000000000000000000000000000a550c1800000000000000001803000000000000000000000000000000000000000a550c180100000000000000)), (AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010b4469656d4163636f756e74134469656d57726974655365744d616e6167657200 }, Value(01000000000000001801000000000000000000000000000000000000000a550c18)), (AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010a4469656d436f6e6669670d436f6e66696775726174696f6e00 }, Value(0200000000000000010000000000000002000000000000001804000000000000000000000000000000000000000a550c18)), (AccessPath { address: 4aa8d7aa575961a69cf69fdfac52e2dc, path: 01000000000000000000000000000000010b4469656d4163636f756e740b4469656d4163636f756e7400 }, Value(20130ec3bbccd77165593e968aac9d68584aa8d7aa575961a69cf69fdfac52e2dc014aa8d7aa575961a69cf69fdfac52e2dc014aa8d7aa575961a69cf69fdfac52e2dc00000000000000001800000000000000004aa8d7aa575961a69cf69fdfac52e2dc00000000000000001800000000000000004aa8d7aa575961a69cf69fdfac52e2dc0a00000000000000)), (AccessPath { address: 4aa8d7aa575961a69cf69fdfac52e2dc, path: 01000000000000000000000000000000010b4469656d4163636f756e740742616c616e6365010700000000000000000000000000000001035855530358555300 }, Value(0000000000000000)), (AccessPath { address: 4aa8d7aa575961a69cf69fdfac52e2dc, path: 01000000000000000000000000000000010f4163636f756e74467265657a696e670b467265657a696e6742697400 }, Value(00)), (AccessPath { address: 4aa8d7aa575961a69cf69fdfac52e2dc, path: 010000000000000000000000000000000105526f6c657306526f6c65496400 }, Value(0500000000000000))] }), events: [ContractEvent { key: EventKey(01000000000000000000000000000000000000000a550c18), index: 0, type: Struct(StructTag { address: 00000000000000000000000000000001, module: Identifier("DiemAccount"), name: Identifier("AdminTransactionEvent"), type_params: [] }), event_data: "0000000000000000" }, ContractEvent { key: EventKey(04000000000000000000000000000000000000000a550c18), index: 1, type: Struct(StructTag { address: 00000000000000000000000000000001, module: Identifier("DiemConfig"), name: Identifier("NewEpochEvent"), type_params: [] }), event_data: "0200000000000000" }], gas_used: 0, status: Keep(EXECUTED) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010b4469656d4163636f756e740b4469656d4163636f756e7400 }, Value(20872d108c30648f16843e29655b181edc12dcc9318ec7d90d98a52801cdcd96c9010000000000000000000000000a550c18010000000000000000000000000a550c1800000000000000001802000000000000000000000000000000000000000a550c1800000000000000001803000000000000000000000000000000000000000a550c180100000000000000)), (AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010b4469656d4163636f756e74134469656d57726974655365744d616e6167657200 }, Value(01000000000000001801000000000000000000000000000000000000000a550c18)), (AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010a4469656d436f6e6669670d436f6e66696775726174696f6e00 }, Value(0200000000000000010000000000000002000000000000001804000000000000000000000000000000000000000a550c18)), (AccessPath { address: 4aa8d7aa575961a69cf69fdfac52e2dc, path: 01000000000000000000000000000000010b4469656d4163636f756e740b4469656d4163636f756e7400 }, Value(20130ec3bbccd77165593e968aac9d68584aa8d7aa575961a69cf69fdfac52e2dc014aa8d7aa575961a69cf69fdfac52e2dc014aa8d7aa575961a69cf69fdfac52e2dc00000000000000001800000000000000004aa8d7aa575961a69cf69fdfac52e2dc00000000000000001800000000000000004aa8d7aa575961a69cf69fdfac52e2dc0a00000000000000)), (AccessPath { address: 4aa8d7aa575961a69cf69fdfac52e2dc, path: 01000000000000000000000000000000010b4469656d4163636f756e740742616c616e6365010700000000000000000000000000000001035855530358555300 }, Value(0000000000000000)), (AccessPath { address: 4aa8d7aa575961a69cf69fdfac52e2dc, path: 01000000000000000000000000000000010f4163636f756e74467265657a696e670b467265657a696e6742697400 }, Value(00))] }), events: [ContractEvent { key: EventKey(01000000000000000000000000000000000000000a550c18), index: 0, type: Struct(StructTag { address: 00000000000000000000000000000001, module: Identifier("DiemAccount"), name: Identifier("AdminTransactionEvent"), type_params: [] }), event_data: "0000000000000000" }, ContractEvent { key: EventKey(04000000000000000000000000000000000000000a550c18), index: 1, type: Struct(StructTag { address: 00000000000000000000000000000001, module: Identifier("DiemConfig"), name: Identifier("NewEpochEvent"), type_params: [] }), event_data: "0200000000000000" }], gas_used: 0, status: Keep(EXECUTED) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath { address: 4aa8d7aa575961a69cf69fdfac52e2dc, path: 01000000000000000000000000000000010b4469656d4163636f756e740b4469656d4163636f756e7400 }, Value(207deeccb1080854f499ec8b4c1b213b82c5e34b925cf6875fec02d4b77adbd2d6014aa8d7aa575961a69cf69fdfac52e2dc014aa8d7aa575961a69cf69fdfac52e2dc00000000000000001800000000000000004aa8d7aa575961a69cf69fdfac52e2dc00000000000000001800000000000000004aa8d7aa575961a69cf69fdfac52e2dc0b00000000000000))] }), events: [], gas_used: 72, status: Keep(EXECUTED) }])
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath { address: 0000000000000000000000000a550c18, path: 0100000000000000000000000000000001094469656d426c6f636b0d426c6f636b4d6574616461746100 }, Value(010000000000000001000000000000001811000000000000000000000000000000000000000a550c18)), (AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010d4469656d54696d657374616d701743757272656e7454696d654d6963726f7365636f6e647300 }, Value(0100000000000000))] }), events: [ContractEvent { key: EventKey(11000000000000000000000000000000000000000a550c18), index: 0, type: Struct(StructTag { address: 00000000000000000000000000000001, module: Identifier("DiemBlock"), name: Identifier("NewBlockEvent"), type_params: [] }), event_data: "000000000000000051c1b9fc2f32d6f2fff669823ef31cbe000100000000000000" }], gas_used: 100000000, status: Keep(EXECUTED) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010b4469656d4163636f756e740b4469656d4163636f756e7400 }, Value(20872d108c30648f16843e29655b181edc12dcc9318ec7d90d98a52801cdcd96c9010000000000000000000000000a550c18010000000000000000000000000a550c1800000000000000001802000000000000000000000000000000000000000a550c1800000000000000001803000000000000000000000000000000000000000a550c180100000000000000)), (AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010b4469656d4163636f756e74134469656d57726974655365744d616e6167657200 }, Value(01000000000000001801000000000000000000000000000000000000000a550c18)), (AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010a4469656d436f6e6669670d436f6e66696775726174696f6e00 }, Value(0200000000000000010000000000000002000000000000001804000000000000000000000000000000000000000a550c18)), (AccessPath { address: 3eebd722df1633f4bf38f1e2087222e9, path: 01000000000000000000000000000000010b4469656d4163636f756e740b4469656d4163636f756e7400 }, Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9013eebd722df1633f4bf38f1e2087222e9013eebd722df1633f4bf38f1e2087222e900000000000000001800000000000000003eebd722df1633f4bf38f1e2087222e900000000000000001800000000000000003eebd722df1633f4bf38f1e2087222e90a00000000000000)), (AccessPath { address: 3eebd722df1633f4bf38f1e2087222e9, path: 01000000000000000000000000000000010b4469656d4163636f756e740742616c616e6365010700000000000000000000000000000001035855530358555300 }, Value(0000000000000000)), (AccessPath { address: 3eebd722df1633f4bf38f1e2087222e9, path: 01000000000000000000000000000000010f4163636f756e74467265657a696e670b467265657a696e6742697400 }, Value(00)), (AccessPath { address: 3eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000105526f6c657306526f6c65496400 }, Value(0500000000000000))] }), events: [ContractEvent { key: EventKey(01000000000000000000000000000000000000000a550c18), index: 0, type: Struct(StructTag { address: 00000000000000000000000000000001, module: Identifier("DiemAccount"), name: Identifier("AdminTransactionEvent"), type_params: [] }), event_data: "0000000000000000" }, ContractEvent { key: EventKey(04000000000000000000000000000000000000000a550c18), index: 1, type: Struct(StructTag { address: 00000000000000000000000000000001, module: Identifier("DiemConfig"), name: Identifier("NewEpochEvent"), type_params: [] }), event_data: "0200000000000000" }], gas_used: 0, status: Keep(EXECUTED) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010b4469656d4163636f756e740b4469656d4163636f756e7400 }, Value(20872d108c30648f16843e29655b181edc12dcc9318ec7d90d98a52801cdcd96c9010000000000000000000000000a550c18010000000000000000000000000a550c1800000000000000001802000000000000000000000000000000000000000a550c1800000000000000001803000000000000000000000000000000000000000a550c180100000000000000)), (AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010b4469656d4163636f756e74134469656d57726974655365744d616e6167657200 }, Value(01000000000000001801000000000000000000000000000000000000000a550c18)), (AccessPath { address: 0000000000000000000000000a550c18, path: 01000000000000000000000000000000010a4469656d436f6e6669670d436f6e66696775726174696f6e00 }, Value(0200000000000000010000000000000002000000000000001804000000000000000000000000000000000000000a550c18)), (AccessPath { address: 3eebd722df1633f4bf38f1e2087222e9, path: 01000000000000000000000000000000010b4469656d4163636f756e740b4469656d4163636f756e7400 }, Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9013eebd722df1633f4bf38f1e2087222e9013eebd722df1633f4bf38f1e2087222e900000000000000001800000000000000003eebd722df1633f4bf38f1e2087222e900000000000000001800000000000000003eebd722df1633f4bf38f1e2087222e90a00000000000000)), (AccessPath { address: 3eebd722df1633f4bf38f1e2087222e9, path: 01000000000000000000000000000000010b4469656d4163636f756e740742616c616e6365010700000000000000000000000000000001035855530358555300 }, Value(0000000000000000)), (AccessPath { address: 3eebd722df1633f4bf38f1e2087222e9, path: 01000000000000000000000000000000010f4163636f756e74467265657a696e670b467265657a696e6742697400 }, Value(00))] }), events: [ContractEvent { key: EventKey(01000000000000000000000000000000000000000a550c18), index: 0, type: Struct(StructTag { address: 00000000000000000000000000000001, module: Identifier("DiemAccount"), name: Identifier("AdminTransactionEvent"), type_params: [] }), event_data: "0000000000000000" }, ContractEvent { key: EventKey(04000000000000000000000000000000000000000a550c18), index: 1, type: Struct(StructTag { address: 00000000000000000000000000000001, module: Identifier("DiemConfig"), name: Identifier("NewEpochEvent"), type_params: [] }), event_data: "0200000000000000" }], gas_used: 0, status: Keep(EXECUTED) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [] }), events: [], gas_used: 0, status: Discard(SEQUENCE_NUMBER_TOO_OLD) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [] }), events: [], gas_used: 0, status: Discard(SEQUENCE_NUMBER_TOO_NEW) }])
29 changes: 4 additions & 25 deletions diem-move/e2e-tests/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use diem_types::{
account_address::AccountAddress,
account_config::{
self, from_currency_code_string, type_tag_for_currency_code, BalanceResource,
DiemAccountResource, RoleId, XDX_NAME, XUS_NAME,
DiemAccountResource, XDX_NAME, XUS_NAME,
},
chain_id::ChainId,
event::EventHandle,
Expand Down Expand Up @@ -415,15 +415,6 @@ impl AccountRoleSpecifier {
pub fn to_value(&self) -> Value {
Value::struct_(Struct::pack(vec![Value::u64(self.id())]))
}

pub fn role_id_struct_tag() -> StructTag {
StructTag {
address: account_config::CORE_CODE_ADDRESS,
module: RoleId::module_identifier(),
name: RoleId::struct_identifier(),
type_params: vec![],
}
}
}

impl FromStr for AccountRoleSpecifier {
Expand Down Expand Up @@ -650,14 +641,13 @@ impl AccountData {
}

/// Creates and returns the top-level resources to be published under the account
pub fn to_value(&self) -> (Value, Vec<(Identifier, Value)>, Value) {
pub fn to_value(&self) -> (Value, Vec<(Identifier, Value)>) {
// TODO: publish some concept of Account
let balances: Vec<_> = self
.balances
.iter()
.map(|(code, balance)| (code.clone(), balance.to_value()))
.collect();
let role_id = self.account_role.account_specifier.to_value();
let account = Value::struct_(Struct::pack(vec![
// TODO: this needs to compute the auth key instead
Value::vector_u8(AuthenticationKey::ed25519(&self.account.pubkey).to_vec()),
Expand All @@ -673,7 +663,7 @@ impl AccountData {
])),
Value::u64(self.sequence_number),
]));
(account, balances, role_id)
(account, balances)
}

/// Returns the AccessPath that describes the Account resource instance.
Expand All @@ -693,7 +683,7 @@ impl AccountData {
/// Creates a writeset that contains the account data and can be patched to the storage
/// directly.
pub fn to_writeset(&self) -> WriteSet {
let (account_blob, balance_blobs, role_id_blob) = self.to_value();
let (account_blob, balance_blobs) = self.to_value();
let mut write_set = Vec::new();
let account = account_blob
.value_as::<Struct>()
Expand Down Expand Up @@ -721,17 +711,6 @@ impl AccountData {
WriteOp::Value(freezing_bit),
));

let role_id = role_id_blob
.value_as::<Struct>()
.unwrap()
.simple_serialize(&AccountRoleSpecifier::layout())
.unwrap();
write_set.push((
self.account
.make_access_path(AccountRoleSpecifier::role_id_struct_tag()),
WriteOp::Value(role_id),
));

WriteSetMut::new(write_set).freeze().unwrap()
}

Expand Down
12 changes: 1 addition & 11 deletions mempool/src/core_mempool/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
logging::{LogEntry, LogSchema},
};
use diem_logger::prelude::*;
use diem_types::{account_address::AccountAddress, transaction::GovernanceRole};
use diem_types::account_address::AccountAddress;
use rand::seq::SliceRandom;
use std::{
cmp::Ordering,
Expand Down Expand Up @@ -57,7 +57,6 @@ impl PriorityIndex {
expiration_time: txn.expiration_time,
address: txn.get_sender(),
sequence_number: txn.sequence_info,
governance_role: txn.governance_role,
}
}

Expand All @@ -76,7 +75,6 @@ pub struct OrderedQueueKey {
pub expiration_time: Duration,
pub address: AccountAddress,
pub sequence_number: SequenceInfo,
pub governance_role: GovernanceRole,
}

impl PartialOrd for OrderedQueueKey {
Expand All @@ -87,14 +85,6 @@ impl PartialOrd for OrderedQueueKey {

impl Ord for OrderedQueueKey {
fn cmp(&self, other: &OrderedQueueKey) -> Ordering {
match self
.governance_role
.priority()
.cmp(&other.governance_role.priority())
{
Ordering::Equal => {}
ordering => return ordering,
}
match self.gas_ranking_score.cmp(&other.gas_ranking_score) {
Ordering::Equal => {}
ordering => return ordering,
Expand Down
Loading

0 comments on commit a96e817

Please sign in to comment.