Skip to content

Commit

Permalink
add Transaction::StateCheckpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
msmouse authored and bors-diem committed Feb 17, 2022
1 parent 875a183 commit a7c8f77
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/types/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use move_core_types::{
};
use move_resource_viewer::MoveValueAnnotator;

use crate::transaction::ModuleBundlePayload;
use crate::transaction::{ModuleBundlePayload, StateCheckpointTransaction};
use anyhow::{ensure, format_err, Result};
use serde_json::Value;
use std::{
Expand Down Expand Up @@ -87,6 +87,12 @@ impl<'a, R: MoveResolver + ?Sized> MoveConverter<'a, R> {
(info, payload, events).into()
}
BlockMetadata(txn) => (&txn, info).into(),
StateCheckpoint => {
Transaction::StateCheckpointTransaction(StateCheckpointTransaction {
info,
timestamp: timestamp.into(),
})
}
})
}

Expand Down
12 changes: 12 additions & 0 deletions api/types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub enum Transaction {
UserTransaction(Box<UserTransaction>),
GenesisTransaction(GenesisTransaction),
BlockMetadataTransaction(BlockMetadataTransaction),
StateCheckpointTransaction(StateCheckpointTransaction),
}

impl Transaction {
Expand All @@ -113,6 +114,7 @@ impl Transaction {
Transaction::BlockMetadataTransaction(txn) => txn.timestamp.0,
Transaction::PendingTransaction(_) => 0,
Transaction::GenesisTransaction(_) => 0,
Transaction::StateCheckpointTransaction(txn) => txn.timestamp.0,
}
}

Expand All @@ -122,6 +124,7 @@ impl Transaction {
Transaction::BlockMetadataTransaction(txn) => txn.info.success,
Transaction::PendingTransaction(_txn) => false,
Transaction::GenesisTransaction(txn) => txn.info.success,
Transaction::StateCheckpointTransaction(txn) => txn.info.success,
}
}

Expand All @@ -135,6 +138,7 @@ impl Transaction {
Transaction::BlockMetadataTransaction(txn) => txn.info.vm_status.clone(),
Transaction::PendingTransaction(_txn) => "pending".to_owned(),
Transaction::GenesisTransaction(txn) => txn.info.vm_status.clone(),
Transaction::StateCheckpointTransaction(txn) => txn.info.vm_status.clone(),
}
}

Expand All @@ -146,6 +150,7 @@ impl Transaction {
bail!("pending transaction does not have TransactionInfo")
}
Transaction::GenesisTransaction(txn) => &txn.info,
Transaction::StateCheckpointTransaction(txn) => &txn.info,
})
}
}
Expand Down Expand Up @@ -258,6 +263,13 @@ pub struct UserTransaction {
pub timestamp: U64,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct StateCheckpointTransaction {
#[serde(flatten)]
pub info: TransactionInfo,
pub timestamp: U64,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct UserTransactionRequest {
pub sender: Address,
Expand Down
2 changes: 2 additions & 0 deletions diem-move/diem-vm/src/adapter_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ pub enum PreprocessedTransaction {
BlockMetadata(BlockMetadata),
WriteSet(Box<SignatureCheckedTransaction>),
InvalidSignature,
StateCheckpoint,
}

/// Check the signature (if any) of a transaction. If the signature is OK, the result
Expand All @@ -288,6 +289,7 @@ pub(crate) fn preprocess_transaction<A: VMAdapter>(txn: Transaction) -> Preproce
_ => PreprocessedTransaction::UserTransaction(Box::new(checked_txn)),
}
}
Transaction::StateCheckpoint => PreprocessedTransaction::StateCheckpoint,
}
}

Expand Down
9 changes: 9 additions & 0 deletions diem-move/diem-vm/src/diem_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,15 @@ impl VMAdapter for DiemVM {
discard_error_vm_status(VMStatus::Error(StatusCode::INVALID_SIGNATURE));
(vm_status, output, None)
}
PreprocessedTransaction::StateCheckpoint => {
let output = TransactionOutput::new(
WriteSet::default(),
Vec::new(),
0,
TransactionStatus::Keep(KeptVMStatus::Executed),
);
(VMStatus::Executed, output, Some("state_checkpoint".into()))
}
})
}
}
Expand Down
1 change: 1 addition & 0 deletions diem-move/diem-vm/src/read_write_set_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ impl<'a, R: MoveResolver> ReadWriteSetAnalysis<'a, R> {
PreprocessedTransaction::WriteSet(_) | PreprocessedTransaction::WaypointWriteSet(_) => {
bail!("Unsupported writeset transaction")
}
PreprocessedTransaction::StateCheckpoint => Ok((vec![], vec![])),
}
}

Expand Down
1 change: 1 addition & 0 deletions diem-move/e2e-tests-replay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ fn replay_trace<P: AsRef<Path>>(
replayer.data_store.add_write_set(res.write_set());
}
}
Transaction::StateCheckpoint => {}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions execution/executor/src/components/apply_chunk_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ pub fn process_write_set(
}
TransactionPayload::WriteSet(_) => (),
},
Transaction::StateCheckpoint => {}
}

let mut account_state = Default::default();
Expand Down
1 change: 1 addition & 0 deletions json-rpc/src/tests/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,7 @@ fn test_get_transactions() {
}
_ => panic!("Returned value doesn't match!"),
},
Transaction::StateCheckpoint => {}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions json-rpc/types/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,8 @@ pub enum TransactionDataView {
script_bytes: BytesView,
script: ScriptView,
},
#[serde(rename = "statecheckpoint")]
StateCheckpoint {},
#[serde(rename = "unknown")]
#[serde(other)]
UnknownTransaction,
Expand Down Expand Up @@ -1176,6 +1178,7 @@ impl From<Transaction> for TransactionDataView {
script,
}
}
Transaction::StateCheckpoint => TransactionDataView::StateCheckpoint {},
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions testsuite/generate-format/tests/staged/consensus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ Transaction:
BlockMetadata:
NEWTYPE:
TYPENAME: BlockMetadata
3:
StateCheckpoint: UNIT
TransactionArgument:
ENUM:
0:
Expand Down
2 changes: 2 additions & 0 deletions testsuite/generate-format/tests/staged/diem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ Transaction:
BlockMetadata:
NEWTYPE:
TYPENAME: BlockMetadata
3:
StateCheckpoint: UNIT
TransactionArgument:
ENUM:
0:
Expand Down
6 changes: 6 additions & 0 deletions types/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,10 @@ pub enum Transaction {

/// Transaction to update the block metadata resource at the beginning of a block.
BlockMetadata(BlockMetadata),

/// Transaction to let the executor update the global state tree and record the root hash
/// in the TransactionInfo
StateCheckpoint,
}

impl Transaction {
Expand All @@ -1523,6 +1527,8 @@ impl Transaction {
Transaction::GenesisTransaction(_write_set) => String::from("genesis"),
// TODO: display proper information for client
Transaction::BlockMetadata(_block_metadata) => String::from("block_metadata"),
// TODO: display proper information for client
Transaction::StateCheckpoint => String::from("state_checkpoint"),
}
}
}
Expand Down

0 comments on commit a7c8f77

Please sign in to comment.