Skip to content

Commit

Permalink
[Clean] [break] Cleanup transaction sequence info compatible code (#2534
Browse files Browse the repository at this point in the history
)

* cleanup transaction sequence info compatible code

* rerelease framework v8 and skip compatibility check
  • Loading branch information
baichuan3 committed Aug 29, 2024
1 parent 4194c16 commit 9843719
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 219 deletions.
5 changes: 0 additions & 5 deletions crates/rooch-pipeline-processor/src/actor/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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;
Expand Down
111 changes: 3 additions & 108 deletions crates/rooch-types/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,56 +66,8 @@ impl From<AuthenticatorInfo> for Vec<u8> {
}
}

///`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<u8>,
/// 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<AccumulatorInfo>,
/// 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<TransactionSequenceInfo> 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,
Expand All @@ -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<H256>,
/// 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,
}

Expand Down Expand Up @@ -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 {
Expand All @@ -195,60 +144,6 @@ impl MoveStructState for TransactionSequenceInfo {
}
}

// Implement custom Deserialize for TransactionSequenceInfo
impl<'de> Deserialize<'de> for TransactionSequenceInfo {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
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<S>(self, mut seq: S) -> Result<Self::Value, S::Error>
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 {
Expand Down
Binary file modified frameworks/framework-release/released/8/stdlib
Binary file not shown.
74 changes: 4 additions & 70 deletions frameworks/rooch-framework/doc/transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


<pre><code></code></pre>
Expand All @@ -28,32 +23,18 @@


<pre><code>#[data_struct]
#[deprecated]
<b>struct</b> <a href="transaction.md#0x3_transaction_TransactionSequenceInfo">TransactionSequenceInfo</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>



<a name="0x3_transaction_TransactionSequenceInfoV2"></a>

## Struct `TransactionSequenceInfoV2`



<pre><code>#[data_struct]
<b>struct</b> <a href="transaction.md#0x3_transaction_TransactionSequenceInfoV2">TransactionSequenceInfoV2</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>



<a name="0x3_transaction_tx_order"></a>

## Function `tx_order`



<pre><code>#[deprecated]
<b>public</b> <b>fun</b> <a href="transaction.md#0x3_transaction_tx_order">tx_order</a>(self: &<a href="transaction.md#0x3_transaction_TransactionSequenceInfo">transaction::TransactionSequenceInfo</a>): u64
<pre><code><b>public</b> <b>fun</b> <a href="transaction.md#0x3_transaction_tx_order">tx_order</a>(self: &<a href="transaction.md#0x3_transaction_TransactionSequenceInfo">transaction::TransactionSequenceInfo</a>): u64
</code></pre>


Expand All @@ -64,8 +45,7 @@



<pre><code>#[deprecated]
<b>public</b> <b>fun</b> <a href="transaction.md#0x3_transaction_tx_order_signature">tx_order_signature</a>(self: &<a href="transaction.md#0x3_transaction_TransactionSequenceInfo">transaction::TransactionSequenceInfo</a>): <a href="">vector</a>&lt;u8&gt;
<pre><code><b>public</b> <b>fun</b> <a href="transaction.md#0x3_transaction_tx_order_signature">tx_order_signature</a>(self: &<a href="transaction.md#0x3_transaction_TransactionSequenceInfo">transaction::TransactionSequenceInfo</a>): <a href="">vector</a>&lt;u8&gt;
</code></pre>


Expand All @@ -76,8 +56,7 @@



<pre><code>#[deprecated]
<b>public</b> <b>fun</b> <a href="transaction.md#0x3_transaction_tx_accumulator_root">tx_accumulator_root</a>(self: &<a href="transaction.md#0x3_transaction_TransactionSequenceInfo">transaction::TransactionSequenceInfo</a>): <a href="">vector</a>&lt;u8&gt;
<pre><code><b>public</b> <b>fun</b> <a href="transaction.md#0x3_transaction_tx_accumulator_root">tx_accumulator_root</a>(self: &<a href="transaction.md#0x3_transaction_TransactionSequenceInfo">transaction::TransactionSequenceInfo</a>): <a href="">vector</a>&lt;u8&gt;
</code></pre>


Expand All @@ -88,50 +67,5 @@



<pre><code>#[deprecated]
<b>public</b> <b>fun</b> <a href="transaction.md#0x3_transaction_tx_timestamp">tx_timestamp</a>(self: &<a href="transaction.md#0x3_transaction_TransactionSequenceInfo">transaction::TransactionSequenceInfo</a>): u64
</code></pre>



<a name="0x3_transaction_get_tx_order"></a>

## Function `get_tx_order`



<pre><code><b>public</b> <b>fun</b> <a href="transaction.md#0x3_transaction_get_tx_order">get_tx_order</a>(self: &<a href="transaction.md#0x3_transaction_TransactionSequenceInfoV2">transaction::TransactionSequenceInfoV2</a>): u64
</code></pre>



<a name="0x3_transaction_get_tx_order_signature"></a>

## Function `get_tx_order_signature`



<pre><code><b>public</b> <b>fun</b> <a href="transaction.md#0x3_transaction_get_tx_order_signature">get_tx_order_signature</a>(self: &<a href="transaction.md#0x3_transaction_TransactionSequenceInfoV2">transaction::TransactionSequenceInfoV2</a>): <a href="">vector</a>&lt;u8&gt;
</code></pre>



<a name="0x3_transaction_get_tx_accumulator_root"></a>

## Function `get_tx_accumulator_root`



<pre><code><b>public</b> <b>fun</b> <a href="transaction.md#0x3_transaction_get_tx_accumulator_root">get_tx_accumulator_root</a>(self: &<a href="transaction.md#0x3_transaction_TransactionSequenceInfoV2">transaction::TransactionSequenceInfoV2</a>): <a href="">vector</a>&lt;u8&gt;
</code></pre>



<a name="0x3_transaction_get_tx_timestamp"></a>

## Function `get_tx_timestamp`



<pre><code><b>public</b> <b>fun</b> <a href="transaction.md#0x3_transaction_get_tx_timestamp">get_tx_timestamp</a>(self: &<a href="transaction.md#0x3_transaction_TransactionSequenceInfoV2">transaction::TransactionSequenceInfoV2</a>): u64
<pre><code><b>public</b> <b>fun</b> <a href="transaction.md#0x3_transaction_tx_timestamp">tx_timestamp</a>(self: &<a href="transaction.md#0x3_transaction_TransactionSequenceInfo">transaction::TransactionSequenceInfo</a>): u64
</code></pre>
33 changes: 0 additions & 33 deletions frameworks/rooch-framework/sources/transaction.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

module rooch_framework::transaction {

#[deprecated]
#[data_struct]
struct TransactionSequenceInfo has copy, drop, store{
/// The tx order
Expand All @@ -14,18 +13,6 @@ module rooch_framework::transaction {
tx_accumulator_root: vector<u8>,
/// 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<u8>,
/// The tx accumulator root after the tx is append to the accumulator.
tx_accumulator_root: vector<u8>,
/// 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<vector<u8>>,
Expand All @@ -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<u8> {
self.tx_order_signature
}

#[deprecated]
public fun tx_accumulator_root(self: &TransactionSequenceInfo): vector<u8> {
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<u8> {
self.tx_order_signature
}

public fun get_tx_accumulator_root(self: &TransactionSequenceInfoV2): vector<u8> {
self.tx_accumulator_root
}

public fun get_tx_timestamp(self: &TransactionSequenceInfoV2): u64 {
self.tx_timestamp
}
}
6 changes: 3 additions & 3 deletions frameworks/rooch-framework/sources/transaction_validator.move
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<TransactionSequenceInfoV2>();
let tx_sequence_info = tx_context::get_attribute<TransactionSequenceInfo>();
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<TransactionValidatorPlaceholder>();
timestamp::try_update_global_time(&module_signer, tx_timestamp);
};
Expand Down

0 comments on commit 9843719

Please sign in to comment.