Skip to content

Commit

Permalink
Revert "feat(primitive): prepare for adding profile data to execution… (
Browse files Browse the repository at this point in the history
near#4451)

* Revert "feat(primitive): prepare for adding profile data to execution outcome (near#4376)"

This reverts commit 793178e.

* pin dependency
  • Loading branch information
bowenwang1996 authored Jul 1, 2021
1 parent fc859e9 commit 949d4e2
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 110 deletions.
5 changes: 2 additions & 3 deletions chain/chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use near_primitives::receipt::{ActionReceipt, Receipt, ReceiptEnum};
use near_primitives::serialize::to_base;
use near_primitives::sharding::ChunkHash;
use near_primitives::transaction::{
Action, ExecutionMetadata, ExecutionOutcome, ExecutionOutcomeWithId, ExecutionStatus,
SignedTransaction, TransferAction,
Action, ExecutionOutcome, ExecutionOutcomeWithId, ExecutionStatus, SignedTransaction,
TransferAction,
};
use near_primitives::types::validator_stake::{ValidatorStake, ValidatorStakeIter};
use near_primitives::types::{
Expand Down Expand Up @@ -726,7 +726,6 @@ impl RuntimeAdapter for KeyValueRuntime {
gas_burnt: 0,
tokens_burnt: 0,
executor_id: to.clone(),
metadata: ExecutionMetadata::ExecutionMetadataV1,
},
});
}
Expand Down
4 changes: 1 addition & 3 deletions chain/chain/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ mod tests {
use near_crypto::KeyType;
use near_primitives::block::{genesis_chunks, Approval};
use near_primitives::merkle::verify_path;
use near_primitives::transaction::{ExecutionMetadata, ExecutionOutcome, ExecutionStatus};
use near_primitives::transaction::{ExecutionOutcome, ExecutionStatus};
use near_primitives::validator_signer::InMemoryValidatorSigner;
use near_primitives::version::PROTOCOL_VERSION;

Expand Down Expand Up @@ -779,7 +779,6 @@ mod tests {
gas_burnt: 100,
tokens_burnt: 10000,
executor_id: "alice".to_string(),
metadata: ExecutionMetadata::ExecutionMetadataV1,
},
};
let outcome2 = ExecutionOutcomeWithId {
Expand All @@ -791,7 +790,6 @@ mod tests {
gas_burnt: 0,
tokens_burnt: 0,
executor_id: "bob".to_string(),
metadata: ExecutionMetadata::ExecutionMetadataV1,
},
};
let outcomes = vec![outcome1, outcome2];
Expand Down
18 changes: 1 addition & 17 deletions core/primitives/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl Default for ExecutionStatus {
}
}

/// ExecutionOutcome for proof. Excludes logs and metadata
/// ExecutionOutcome for proof. Excludes logs.
#[derive(BorshSerialize, BorshDeserialize, Serialize, PartialEq, Clone)]
struct PartialExecutionOutcome {
pub receipt_ids: Vec<CryptoHash>,
Expand Down Expand Up @@ -348,20 +348,6 @@ pub struct ExecutionOutcome {
/// NOTE: Should be the latest field since it contains unparsable by light client
/// ExecutionStatus::Failure
pub status: ExecutionStatus,
/// Execution metadata, versioned
pub metadata: ExecutionMetadata,
}

#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, PartialEq, Clone, Eq, Debug)]
pub enum ExecutionMetadata {
// V1: Empty Metadata
ExecutionMetadataV1,
}

impl Default for ExecutionMetadata {
fn default() -> Self {
ExecutionMetadata::ExecutionMetadataV1
}
}

impl ExecutionOutcome {
Expand All @@ -384,7 +370,6 @@ impl fmt::Debug for ExecutionOutcome {
.field("burnt_gas", &self.gas_burnt)
.field("tokens_burnt", &self.tokens_burnt)
.field("status", &self.status)
.field("meatdata", &self.metadata)
.finish()
}
}
Expand Down Expand Up @@ -523,7 +508,6 @@ mod tests {
gas_burnt: 123,
tokens_burnt: 1234000,
executor_id: "alice".to_string(),
metadata: ExecutionMetadata::ExecutionMetadataV1,
};
let hashes = outcome.to_hashes();
assert_eq!(hashes.len(), 3);
Expand Down
2 changes: 1 addition & 1 deletion core/primitives/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Version {
pub type DbVersion = u32;

/// Current version of the database.
pub const DB_VERSION: DbVersion = 24;
pub const DB_VERSION: DbVersion = 23;

/// Protocol version type.
pub use near_primitives_core::types::ProtocolVersion;
Expand Down
8 changes: 2 additions & 6 deletions core/primitives/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ use crate::sharding::{ChunkHash, ShardChunk, ShardChunkHeader, ShardChunkHeaderI
use crate::sharding::{ShardChunkHeaderInnerV2, ShardChunkHeaderV3};
use crate::transaction::{
Action, AddKeyAction, CreateAccountAction, DeleteAccountAction, DeleteKeyAction,
DeployContractAction, ExecutionMetadata, ExecutionOutcome, ExecutionOutcomeWithIdAndProof,
ExecutionStatus, FunctionCallAction, SignedTransaction, StakeAction, TransferAction,
DeployContractAction, ExecutionOutcome, ExecutionOutcomeWithIdAndProof, ExecutionStatus,
FunctionCallAction, SignedTransaction, StakeAction, TransferAction,
};
use crate::types::{
AccountId, AccountWithPublicKey, Balance, BlockHeight, CompiledContractCache, EpochHeight,
Expand Down Expand Up @@ -1018,9 +1018,6 @@ pub struct ExecutionOutcomeView {
pub executor_id: AccountId,
/// Execution status. Contains the result in case of successful execution.
pub status: ExecutionStatusView,
/// Execution metadata, versioned
#[serde(skip)]
pub metadata: ExecutionMetadata,
}

impl From<ExecutionOutcome> for ExecutionOutcomeView {
Expand All @@ -1032,7 +1029,6 @@ impl From<ExecutionOutcome> for ExecutionOutcomeView {
tokens_burnt: outcome.tokens_burnt,
executor_id: outcome.executor_id,
status: outcome.status.into(),
metadata: outcome.metadata,
}
}
}
Expand Down
72 changes: 5 additions & 67 deletions core/store/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use near_primitives::sharding::{
EncodedShardChunk, EncodedShardChunkV1, PartialEncodedChunk, PartialEncodedChunkV1,
ReceiptList, ReceiptProof, ReedSolomonWrapper, ShardChunk, ShardChunkV1, ShardProof,
};
use near_primitives::transaction::{
ExecutionMetadata, ExecutionOutcome, ExecutionOutcomeWithId, ExecutionOutcomeWithIdAndProof,
ExecutionStatus, LogEntry,
};
use near_primitives::transaction::ExecutionOutcomeWithIdAndProof;
use near_primitives::version::DbVersion;

use crate::db::DBCol::{ColBlockHeader, ColBlockMisc, ColChunks, ColPartialChunks, ColStateParts};
Expand All @@ -32,13 +29,12 @@ use near_primitives::block_header::BlockHeader;
#[cfg(feature = "protocol_feature_block_header_v3")]
use near_primitives::epoch_manager::epoch_info::EpochInfo;
use near_primitives::epoch_manager::epoch_info::EpochInfoV1;
use near_primitives::merkle::{merklize, MerklePath};
use near_primitives::merkle::merklize;
use near_primitives::receipt::{DelayedReceiptIndices, Receipt, ReceiptEnum};
use near_primitives::syncing::{ShardStateSyncResponseHeader, ShardStateSyncResponseHeaderV1};
use near_primitives::trie_key::TrieKey;
#[cfg(feature = "protocol_feature_block_header_v3")]
use near_primitives::types::validator_stake::ValidatorStake;
use near_primitives::types::{AccountId, Balance, Gas};
use near_primitives::utils::{create_receipt_id_from_transaction, get_block_shard_id};
use near_primitives::validator_signer::InMemoryValidatorSigner;
use std::rc::Rc;
Expand Down Expand Up @@ -569,7 +565,7 @@ pub fn migrate_17_to_18(path: &String) {

use near_primitives::challenge::SlashedValidator;
use near_primitives::types::validator_stake::ValidatorStakeV1;
use near_primitives::types::{BlockHeight, EpochId};
use near_primitives::types::{Balance, BlockHeight, EpochId};
use near_primitives::version::ProtocolVersion;

// Migrate from OldBlockInfo to NewBlockInfo - add hash
Expand Down Expand Up @@ -649,7 +645,7 @@ pub fn migrate_21_to_22(path: &String) {
use near_primitives::epoch_manager::BlockInfoV1;
use near_primitives::epoch_manager::SlashState;
use near_primitives::types::validator_stake::ValidatorStakeV1;
use near_primitives::types::{BlockHeight, EpochId};
use near_primitives::types::{AccountId, Balance, BlockHeight, EpochId};
use near_primitives::version::ProtocolVersion;
#[derive(BorshDeserialize)]
struct OldBlockInfo {
Expand Down Expand Up @@ -718,7 +714,7 @@ pub fn migrate_18_to_new_validator_stake(store: &Store) {
use near_primitives::types::chunk_extra::{ChunkExtra, ChunkExtraV1};
use near_primitives::types::validator_stake::ValidatorStakeV1;
use near_primitives::types::{
BlockChunkValidatorStats, EpochId, ProtocolVersion, ShardId, ValidatorId,
AccountId, BlockChunkValidatorStats, EpochId, ProtocolVersion, ShardId, ValidatorId,
ValidatorKickoutReason, ValidatorStats,
};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -794,61 +790,3 @@ pub fn migrate_18_to_new_validator_stake(store: &Store) {
}
store_update.finish().unwrap();
}

pub fn fill_col_outcomes_with_metadata(store: &Store) {
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Clone, Default, Eq, Debug)]
pub struct OldExecutionOutcome {
pub logs: Vec<LogEntry>,
pub receipt_ids: Vec<CryptoHash>,
pub gas_burnt: Gas,
pub tokens_burnt: Balance,
pub executor_id: AccountId,
pub status: ExecutionStatus,
}

#[derive(PartialEq, Clone, Default, Debug, BorshSerialize, BorshDeserialize, Eq)]
pub struct OldExecutionOutcomeWithId {
pub id: CryptoHash,
pub outcome: OldExecutionOutcome,
}

#[derive(PartialEq, Clone, Default, Debug, BorshSerialize, BorshDeserialize, Eq)]
pub struct OldExecutionOutcomeWithIdAndProof {
pub proof: MerklePath,
pub block_hash: CryptoHash,
pub outcome_with_id: OldExecutionOutcomeWithId,
}

impl Into<ExecutionOutcomeWithIdAndProof> for OldExecutionOutcomeWithIdAndProof {
fn into(self) -> ExecutionOutcomeWithIdAndProof {
ExecutionOutcomeWithIdAndProof {
proof: self.proof,
block_hash: self.block_hash,
outcome_with_id: ExecutionOutcomeWithId {
id: self.outcome_with_id.id,
outcome: ExecutionOutcome {
logs: self.outcome_with_id.outcome.logs,
receipt_ids: self.outcome_with_id.outcome.receipt_ids,
gas_burnt: self.outcome_with_id.outcome.gas_burnt,
tokens_burnt: self.outcome_with_id.outcome.tokens_burnt,
executor_id: self.outcome_with_id.outcome.executor_id,
status: self.outcome_with_id.outcome.status,
metadata: ExecutionMetadata::ExecutionMetadataV1,
},
},
}
}
}

let mut store_update = BatchedStoreUpdate::new(&store, 10_000_000);
for (key, value) in store.iter(DBCol::ColTransactionResult) {
let old_outcomes = Vec::<OldExecutionOutcomeWithIdAndProof>::try_from_slice(&value)
.expect("BorshDeserialize should not fail");
let outcomes: Vec<ExecutionOutcomeWithIdAndProof> =
old_outcomes.into_iter().map(|outcome| outcome.into()).collect();
store_update
.set_ser(DBCol::ColTransactionResult, key.as_ref(), &outcomes)
.expect("BorshSerialize should not fail");
}
store_update.finish().expect("Failed to migrate");
}
13 changes: 3 additions & 10 deletions nearcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ pub use crate::config::{init_configs, load_config, load_test_config, NearConfig,
use crate::migrations::{migrate_12_to_13, migrate_18_to_19, migrate_19_to_20, migrate_22_to_23};
pub use crate::runtime::NightshadeRuntime;
use near_store::migrations::{
fill_col_outcomes_by_hash, fill_col_outcomes_with_metadata, fill_col_transaction_refcount,
get_store_version, migrate_10_to_11, migrate_11_to_12, migrate_13_to_14, migrate_14_to_15,
migrate_17_to_18, migrate_21_to_22, migrate_6_to_7, migrate_7_to_8, migrate_8_to_9,
migrate_9_to_10, set_store_version,
fill_col_outcomes_by_hash, fill_col_transaction_refcount, get_store_version, migrate_10_to_11,
migrate_11_to_12, migrate_13_to_14, migrate_14_to_15, migrate_17_to_18, migrate_21_to_22,
migrate_6_to_7, migrate_7_to_8, migrate_8_to_9, migrate_9_to_10, set_store_version,
};

#[cfg(feature = "protocol_feature_block_header_v3")]
Expand Down Expand Up @@ -216,12 +215,6 @@ pub fn apply_store_migrations(path: &String, near_config: &NearConfig) {
info!(target: "near", "Migrate DB from version 22 to 23");
migrate_22_to_23(&path, &near_config);
}
if db_version <= 23 {
info!(target: "near", "Migrate DB from version 23 to 24");
let store = create_store(&path);
fill_col_outcomes_with_metadata(&store);
set_store_version(&store, 24);
}
#[cfg(feature = "nightly_protocol")]
{
let store = create_store(&path);
Expand Down
3 changes: 0 additions & 3 deletions runtime/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ use near_primitives::contract::ContractCode;
pub use near_primitives::runtime::apply_state::ApplyState;
use near_primitives::runtime::fees::RuntimeFeesConfig;
use near_primitives::runtime::migration_data::{MigrationData, MigrationFlags};
use near_primitives::transaction::ExecutionMetadata;
use near_primitives::version::{
is_implicit_account_creation_enabled, ProtocolFeature, ProtocolVersion,
};
Expand Down Expand Up @@ -264,7 +263,6 @@ impl Runtime {
gas_burnt: verification_result.gas_burnt,
tokens_burnt: verification_result.burnt_amount,
executor_id: transaction.signer_id.clone(),
metadata: ExecutionMetadata::ExecutionMetadataV1,
},
};
Ok((receipt, outcome))
Expand Down Expand Up @@ -733,7 +731,6 @@ impl Runtime {
gas_burnt: result.gas_burnt,
tokens_burnt,
executor_id: account_id.clone(),
metadata: ExecutionMetadata::ExecutionMetadataV1,
},
})
}
Expand Down

0 comments on commit 949d4e2

Please sign in to comment.