From 9843719ba5d725bcdf562c978350b6327af1cf0c Mon Sep 17 00:00:00 2001 From: Bai Chuan Date: Thu, 29 Aug 2024 19:40:15 +0800 Subject: [PATCH] [Clean] [break] Cleanup transaction sequence info compatible code (#2534) * cleanup transaction sequence info compatible code * rerelease framework v8 and skip compatibility check --- .../src/actor/processor.rs | 5 - crates/rooch-types/src/transaction/mod.rs | 111 +----------------- .../framework-release/released/8/stdlib | Bin 160990 -> 160739 bytes frameworks/rooch-framework/doc/transaction.md | 74 +----------- .../rooch-framework/sources/transaction.move | 33 ------ .../sources/transaction_validator.move | 6 +- 6 files changed, 10 insertions(+), 219 deletions(-) diff --git a/crates/rooch-pipeline-processor/src/actor/processor.rs b/crates/rooch-pipeline-processor/src/actor/processor.rs index f5db95508f..7251976bca 100644 --- a/crates/rooch-pipeline-processor/src/actor/processor.rs +++ b/crates/rooch-pipeline-processor/src/actor/processor.rs @@ -16,7 +16,6 @@ use rooch_executor::proxy::ExecutorProxy; use rooch_indexer::proxy::IndexerProxy; use rooch_proposer::proxy::ProposerProxy; use rooch_sequencer::proxy::SequencerProxy; -use rooch_types::transaction::TransactionSequenceInfoV1; use rooch_types::{ service_status::ServiceStatus, transaction::{ @@ -262,10 +261,6 @@ impl PipelineProcessorActor { .start_timer(); // Add sequence info to tx context, let the Move contract can get the sequence info moveos_tx.ctx.add(tx.sequence_info.clone())?; - // We must add TransactionSequenceInfo and TransactionSequenceInfoV1 both to the tx_context because the rust code is upgraded first, then the framework is upgraded. - // The old framework will read the TransactionSequenceInfoV1. - let tx_sequence_info_v1 = TransactionSequenceInfoV1::from(tx.sequence_info.clone()); - moveos_tx.ctx.add(tx_sequence_info_v1)?; // Then execute let size = moveos_tx.ctx.tx_size; diff --git a/crates/rooch-types/src/transaction/mod.rs b/crates/rooch-types/src/transaction/mod.rs index 99c27329d1..f652bb5a59 100644 --- a/crates/rooch-types/src/transaction/mod.rs +++ b/crates/rooch-types/src/transaction/mod.rs @@ -10,7 +10,7 @@ use move_core_types::identifier::IdentStr; use moveos_types::state::{MoveState, MoveStructState, MoveStructType}; use moveos_types::transaction::TransactionExecutionInfo; use moveos_types::{h256::H256, transaction::TransactionOutput}; -use serde::{Deserialize, Deserializer, Serialize}; +use serde::{Deserialize, Serialize}; pub mod authenticator; mod ledger_transaction; @@ -66,56 +66,8 @@ impl From for Vec { } } -///`TransactionSequenceInfoV1` represents the result of sequence a transaction. -// Can be cleanup after framework upgraded -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -pub struct TransactionSequenceInfoV1 { - /// The tx order - pub tx_order: u64, - /// The tx order signature, it is the signature of the sequencer to commit the tx order. - pub tx_order_signature: Vec, - /// The tx accumulator root after the tx is append to the accumulator. - pub tx_accumulator_root: H256, - /// The tx accumulator info after the tx is append to the accumulator. - // pub tx_accumulator_info: Option, - /// The timestamp of the sequencer when the tx is sequenced, in millisecond. - pub tx_timestamp: u64, -} - -impl MoveStructType for TransactionSequenceInfoV1 { - const ADDRESS: AccountAddress = ROOCH_FRAMEWORK_ADDRESS; - const MODULE_NAME: &'static IdentStr = ident_str!("transaction"); - const STRUCT_NAME: &'static IdentStr = ident_str!("TransactionSequenceInfo"); -} - -impl MoveStructState for TransactionSequenceInfoV1 { - fn struct_layout() -> move_core_types::value::MoveStructLayout { - move_core_types::value::MoveStructLayout::new(vec![ - move_core_types::value::MoveTypeLayout::U64, - move_core_types::value::MoveTypeLayout::Vector(Box::new( - move_core_types::value::MoveTypeLayout::U8, - )), - move_core_types::value::MoveTypeLayout::Vector(Box::new( - move_core_types::value::MoveTypeLayout::U8, - )), - move_core_types::value::MoveTypeLayout::U64, - ]) - } -} - -impl From for TransactionSequenceInfoV1 { - fn from(tx_sequence_info: TransactionSequenceInfo) -> Self { - Self { - tx_order: tx_sequence_info.tx_order, - tx_order_signature: tx_sequence_info.tx_order_signature, - tx_accumulator_root: tx_sequence_info.tx_accumulator_root, - tx_timestamp: tx_sequence_info.tx_timestamp, - } - } -} - ///`TransactionSequenceInfo` represents the result of sequence a transaction. -#[derive(Clone, Debug, Eq, PartialEq, Serialize)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct TransactionSequenceInfo { /// The tx order pub tx_order: u64, @@ -129,13 +81,10 @@ pub struct TransactionSequenceInfo { pub tx_timestamp: u64, /// Frozen subtree roots of the accumulator. - #[serde(default)] pub tx_accumulator_frozen_subtree_roots: Vec, /// The total number of leaves in the accumulator. - #[serde(default)] pub tx_accumulator_num_leaves: u64, /// The total number of nodes in the accumulator. - #[serde(default)] pub tx_accumulator_num_nodes: u64, } @@ -174,7 +123,7 @@ impl TransactionSequenceInfo { impl MoveStructType for TransactionSequenceInfo { const ADDRESS: AccountAddress = ROOCH_FRAMEWORK_ADDRESS; const MODULE_NAME: &'static IdentStr = ident_str!("transaction"); - const STRUCT_NAME: &'static IdentStr = ident_str!("TransactionSequenceInfoV2"); + const STRUCT_NAME: &'static IdentStr = ident_str!("TransactionSequenceInfo"); } impl MoveStructState for TransactionSequenceInfo { @@ -195,60 +144,6 @@ impl MoveStructState for TransactionSequenceInfo { } } -// Implement custom Deserialize for TransactionSequenceInfo -impl<'de> Deserialize<'de> for TransactionSequenceInfo { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - struct TransactionSequenceInfoVisitor; - - impl<'de> serde::de::Visitor<'de> for TransactionSequenceInfoVisitor { - type Value = TransactionSequenceInfo; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("Expect TransactionSequenceInfo for deserializer") - } - - // To be compatible with old data, tx_accumulator_frozen_subtree_roots, tx_accumulator_num_leaves, - // and tx_accumulator_num_nodes are allowed to be missing. - fn visit_seq(self, mut seq: S) -> Result - where - S: serde::de::SeqAccess<'de>, - { - let tx_order = seq.next_element()?.ok_or_else(|| serde::de::Error::custom("Missing or invalid tx_order field when deserialize TransactionSequenceInfo"))?; - let tx_order_signature = seq.next_element()?.ok_or_else(|| serde::de::Error::custom("Missing or invalid tx_order_signature field when deserialize TransactionSequenceInfo"))?; - let tx_accumulator_root = seq.next_element()?.ok_or_else(|| serde::de::Error::custom("Missing or invalid tx_accumulator_root field when deserialize TransactionSequenceInfo"))?; - let tx_timestamp: u64 = seq.next_element()?.ok_or_else(|| serde::de::Error::custom("Missing or invalid tx_timestamp field when deserialize TransactionSequenceInfo"))?; - - // Ignore deserialize error "unexpected end of input" for old data when missing field - let tx_accumulator_frozen_subtree_roots = - seq.next_element().unwrap_or(None).unwrap_or(vec![]); - // Ignore deserialize error "unexpected end of input" for old data when missing field - let tx_accumulator_num_leaves = seq.next_element().unwrap_or(None).unwrap_or(0u64); - // Ignore deserialize error "unexpected end of input" for old data when missing field - let tx_accumulator_num_nodes = seq.next_element().unwrap_or(None).unwrap_or(0u64); - - Ok(TransactionSequenceInfo { - tx_order, - tx_order_signature, - tx_accumulator_root, - tx_timestamp, - tx_accumulator_frozen_subtree_roots, - tx_accumulator_num_leaves, - tx_accumulator_num_nodes, - }) - } - } - - deserializer.deserialize_struct( - TRANSACTION_SEQUENCE_INFO_STR, - TRANSACTION_SEQUENCE_INFO_FIELDS, - TransactionSequenceInfoVisitor, - ) - } -} - /// Transaction with sequence info and execution info. #[derive(Debug, Clone)] pub struct TransactionWithInfo { diff --git a/frameworks/framework-release/released/8/stdlib b/frameworks/framework-release/released/8/stdlib index 80c905faac8306820b7d33486e85b4f00a10bf84..c5a0b315d827ccc79bde3c27f047f0ef2fa6ede2 100644 GIT binary patch delta 228 zcmXwzFHZwe5X5(O@BO*$k-junN(ll13e$cFg2&V}4WERd&;&xBB2AOiD3T)tgF@np zff@u5s6n6*eJ3!xzuC-8cJZ0Nz2_%42=4G+W?Nq^OGFA{=1gp9Hr4Ii!oOfU{9#`o zxLeG5uy!gw`QV6{KqP5V){toq))SN=@z`NEs>h=pCOaWMd+c>n$cbditZc-pCh0F; z2mK9hy0R7pE?NFrO0Ms6j4yE>d(-9-^}p>SI}aWG2&P!p2UDyY^x~vSC$TQINWpf?HU)1Le?er0f+GC_ zQRo+V_6I}}4VW^(_Kxp~a&U0@(PXX147$@c(2BM^~ddPWpS zINK=|U4z6G%V?6CG((bq zfv+`XS?+g6?n3~E&^_R((GU$yhSEuY^2`t)ni~>B3q#(}o*|h!pB9p?sH=pCtbeI+ z{c!PU?B91R(84@h?-GBfNpZj)P=4@zUw!5`z3X69KL;ZF)?YcsaWU8+m5Rw;51Zm= L7yXwWzFvI;)B{}J diff --git a/frameworks/rooch-framework/doc/transaction.md b/frameworks/rooch-framework/doc/transaction.md index c1f1d380a2..05547d43f8 100644 --- a/frameworks/rooch-framework/doc/transaction.md +++ b/frameworks/rooch-framework/doc/transaction.md @@ -6,15 +6,10 @@ - [Struct `TransactionSequenceInfo`](#0x3_transaction_TransactionSequenceInfo) -- [Struct `TransactionSequenceInfoV2`](#0x3_transaction_TransactionSequenceInfoV2) - [Function `tx_order`](#0x3_transaction_tx_order) - [Function `tx_order_signature`](#0x3_transaction_tx_order_signature) - [Function `tx_accumulator_root`](#0x3_transaction_tx_accumulator_root) - [Function `tx_timestamp`](#0x3_transaction_tx_timestamp) -- [Function `get_tx_order`](#0x3_transaction_get_tx_order) -- [Function `get_tx_order_signature`](#0x3_transaction_get_tx_order_signature) -- [Function `get_tx_accumulator_root`](#0x3_transaction_get_tx_accumulator_root) -- [Function `get_tx_timestamp`](#0x3_transaction_get_tx_timestamp)
@@ -28,32 +23,18 @@
#[data_struct]
-#[deprecated]
 struct TransactionSequenceInfo has copy, drop, store
 
- - -## Struct `TransactionSequenceInfoV2` - - - -
#[data_struct]
-struct TransactionSequenceInfoV2 has copy, drop, store
-
- - - ## Function `tx_order` -
#[deprecated]
-public fun tx_order(self: &transaction::TransactionSequenceInfo): u64
+
public fun tx_order(self: &transaction::TransactionSequenceInfo): u64
 
@@ -64,8 +45,7 @@ -
#[deprecated]
-public fun tx_order_signature(self: &transaction::TransactionSequenceInfo): vector<u8>
+
public fun tx_order_signature(self: &transaction::TransactionSequenceInfo): vector<u8>
 
@@ -76,8 +56,7 @@ -
#[deprecated]
-public fun tx_accumulator_root(self: &transaction::TransactionSequenceInfo): vector<u8>
+
public fun tx_accumulator_root(self: &transaction::TransactionSequenceInfo): vector<u8>
 
@@ -88,50 +67,5 @@ -
#[deprecated]
-public fun tx_timestamp(self: &transaction::TransactionSequenceInfo): u64
-
- - - - - -## Function `get_tx_order` - - - -
public fun get_tx_order(self: &transaction::TransactionSequenceInfoV2): u64
-
- - - - - -## Function `get_tx_order_signature` - - - -
public fun get_tx_order_signature(self: &transaction::TransactionSequenceInfoV2): vector<u8>
-
- - - - - -## Function `get_tx_accumulator_root` - - - -
public fun get_tx_accumulator_root(self: &transaction::TransactionSequenceInfoV2): vector<u8>
-
- - - - - -## Function `get_tx_timestamp` - - - -
public fun get_tx_timestamp(self: &transaction::TransactionSequenceInfoV2): u64
+
public fun tx_timestamp(self: &transaction::TransactionSequenceInfo): u64
 
diff --git a/frameworks/rooch-framework/sources/transaction.move b/frameworks/rooch-framework/sources/transaction.move index 9a13bd294c..d9c07a448f 100644 --- a/frameworks/rooch-framework/sources/transaction.move +++ b/frameworks/rooch-framework/sources/transaction.move @@ -3,7 +3,6 @@ module rooch_framework::transaction { - #[deprecated] #[data_struct] struct TransactionSequenceInfo has copy, drop, store{ /// The tx order @@ -14,18 +13,6 @@ module rooch_framework::transaction { tx_accumulator_root: vector, /// The timestamp of the sequencer when the tx is sequenced, in millisecond. tx_timestamp: u64, - } - - #[data_struct] - struct TransactionSequenceInfoV2 has copy, drop, store{ - /// The tx order - tx_order: u64, - /// The tx order signature, it is the signature of the sequencer to commit the tx order. - tx_order_signature: vector, - /// The tx accumulator root after the tx is append to the accumulator. - tx_accumulator_root: vector, - /// The timestamp of the sequencer when the tx is sequenced, in millisecond. - tx_timestamp: u64, /// Frozen subtree roots of the accumulator. tx_accumulator_frozen_subtree_roots: vector>, @@ -35,39 +22,19 @@ module rooch_framework::transaction { tx_accumulator_num_nodes: u64, } - #[deprecated] public fun tx_order(self: &TransactionSequenceInfo): u64 { self.tx_order } - #[deprecated] public fun tx_order_signature(self: &TransactionSequenceInfo): vector { self.tx_order_signature } - #[deprecated] public fun tx_accumulator_root(self: &TransactionSequenceInfo): vector { self.tx_accumulator_root } - #[deprecated] public fun tx_timestamp(self: &TransactionSequenceInfo): u64 { self.tx_timestamp } - - public fun get_tx_order(self: &TransactionSequenceInfoV2): u64 { - self.tx_order - } - - public fun get_tx_order_signature(self: &TransactionSequenceInfoV2): vector { - self.tx_order_signature - } - - public fun get_tx_accumulator_root(self: &TransactionSequenceInfoV2): vector { - self.tx_accumulator_root - } - - public fun get_tx_timestamp(self: &TransactionSequenceInfoV2): u64 { - self.tx_timestamp - } } \ No newline at end of file diff --git a/frameworks/rooch-framework/sources/transaction_validator.move b/frameworks/rooch-framework/sources/transaction_validator.move index 0a75724cab..ae81fbce60 100644 --- a/frameworks/rooch-framework/sources/transaction_validator.move +++ b/frameworks/rooch-framework/sources/transaction_validator.move @@ -17,7 +17,7 @@ module rooch_framework::transaction_validator { use rooch_framework::chain_id; use rooch_framework::transaction_fee; use rooch_framework::gas_coin; - use rooch_framework::transaction::{Self, TransactionSequenceInfoV2}; + use rooch_framework::transaction::{Self, TransactionSequenceInfo}; use rooch_framework::session_validator; use rooch_framework::bitcoin_validator; use rooch_framework::address_mapping; @@ -129,10 +129,10 @@ module rooch_framework::transaction_validator { }; let bitcoin_addr = auth_validator::get_bitcoin_address_from_ctx(); address_mapping::bind_bitcoin_address(sender, bitcoin_addr); - let tx_sequence_info = tx_context::get_attribute(); + let tx_sequence_info = tx_context::get_attribute(); if (option::is_some(&tx_sequence_info)) { let tx_sequence_info = option::extract(&mut tx_sequence_info); - let tx_timestamp = transaction::get_tx_timestamp(&tx_sequence_info); + let tx_timestamp = transaction::tx_timestamp(&tx_sequence_info); let module_signer = module_signer(); timestamp::try_update_global_time(&module_signer, tx_timestamp); };