Skip to content

Commit

Permalink
Add new TransactionPayload variant for orderless txns
Browse files Browse the repository at this point in the history
Add some comments

Add some more comments

Add more comments

Chaging NestedTransactionPayload to TransactionPayloadV2

Updating struct names

try_into_aptos_core_transaction_payload

Updates in API convert

get_signed_transaction

Add stats key in simulate

stats key in aptos debugger

Committing what I have

Transaction metadata

Added some protobuf changes

More protobuf changes

Indexer grpc convert function

Remove some comments

quorum store changes

Add new session ids

Minor changes
  • Loading branch information
vusirikala committed Nov 7, 2024
1 parent 751c9a3 commit 76eca53
Show file tree
Hide file tree
Showing 23 changed files with 1,179 additions and 350 deletions.
115 changes: 85 additions & 30 deletions api/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ use aptos_types::{
account_address::AccountAddress,
mempool_status::MempoolStatusCode,
transaction::{
EntryFunction, ExecutionStatus, MultisigTransactionPayload, RawTransaction,
RawTransactionWithData, SignedTransaction, TransactionPayload,
EntryFunction, ExecutionStatus, MultisigTransactionPayload, RawTransaction, RawTransactionWithData, Script, SignedTransaction, TransactionExecutable, TransactionPayload, TransactionPayloadV2
},
vm_status::StatusCode,
AptosCoinType, CoinType,
Expand Down Expand Up @@ -1041,6 +1040,35 @@ impl TransactionsApi {
ledger_info: &LedgerInfo,
data: SubmitTransactionPost,
) -> Result<SignedTransaction, SubmitTransactionError> {

let validate_script = |script: &Script| -> Result<(), SubmitTransactionError> {
if script.code().is_empty() {
return Err(SubmitTransactionError::bad_request_with_code(
"Script payload bytecode must not be empty",
AptosErrorCode::InvalidInput,
ledger_info,
));
}

for arg in script.ty_args() {
let arg = MoveType::from(arg);
arg.verify(0)
.context("Transaction script function type arg invalid")
.map_err(|err| {
SubmitTransactionError::bad_request_with_code(
err,
AptosErrorCode::InvalidInput,
ledger_info,
)
})?;
}
Ok(())
};

let validate_entry_function = |entry_function: &EntryFunction| -> Result<(), SubmitTransactionError> {
TransactionsApi::validate_entry_function_payload_format(ledger_info, entry_function)
};

match data {
SubmitTransactionPost::Bcs(data) => {
let signed_transaction: SignedTransaction =
Expand All @@ -1056,41 +1084,16 @@ impl TransactionsApi {
// Verify the signed transaction
match signed_transaction.payload() {
TransactionPayload::EntryFunction(entry_function) => {
TransactionsApi::validate_entry_function_payload_format(
ledger_info,
entry_function,
)?;
validate_entry_function(entry_function)?;
},
TransactionPayload::Script(script) => {
if script.code().is_empty() {
return Err(SubmitTransactionError::bad_request_with_code(
"Script payload bytecode must not be empty",
AptosErrorCode::InvalidInput,
ledger_info,
));
}

for arg in script.ty_args() {
let arg = MoveType::from(arg);
arg.verify(0)
.context("Transaction script function type arg invalid")
.map_err(|err| {
SubmitTransactionError::bad_request_with_code(
err,
AptosErrorCode::InvalidInput,
ledger_info,
)
})?;
}
validate_script(script)?;
},
TransactionPayload::Multisig(multisig) => {
if let Some(payload) = &multisig.transaction_payload {
match payload {
MultisigTransactionPayload::EntryFunction(entry_function) => {
TransactionsApi::validate_entry_function_payload_format(
ledger_info,
entry_function,
)?;
validate_entry_function(entry_function)?;
},
}
}
Expand All @@ -1105,6 +1108,35 @@ impl TransactionsApi {
ledger_info,
))
},
TransactionPayload::V2(TransactionPayloadV2::V1 {
executable,
extra_config,
}) => {
match executable {
TransactionExecutable::Script(script) => {
validate_script(script)?;
if extra_config.is_multisig() {
return Err(SubmitTransactionError::bad_request_with_code(
"Script transaction payload must not be a multisig transaction",
AptosErrorCode::InvalidInput,
ledger_info,
));
}
},
TransactionExecutable::EntryFunction(entry_function) => {
validate_entry_function(entry_function)?;
},
TransactionExecutable::Empty => {
if !extra_config.is_multisig() {
return Err(SubmitTransactionError::bad_request_with_code(
"Empty transaction payload must be a multisig transaction",
AptosErrorCode::InvalidInput,
ledger_info,
));
}
}
}
}
}
// TODO: Verify script args?

Expand Down Expand Up @@ -1422,6 +1454,29 @@ impl TransactionsApi {
"Multisig::unknown".to_string()
}
},
TransactionPayload::V2(TransactionPayloadV2::V1 {
executable,
extra_config,
}) => {
let mut stats_key: String = "V2::".to_string();
if extra_config.is_multisig() {
stats_key += "Multisig::";
};
if extra_config.is_orderless() {
stats_key += "Orderless::";
}
if let TransactionExecutable::Script(_) = executable {
stats_key += format!("Script::{}", txn.committed_hash()).as_str();
} else if let TransactionExecutable::EntryFunction(entry_function) = executable {
stats_key += FunctionStats::function_to_key(
entry_function.module(),
&entry_function.function().into(),
).as_str();
} else if let TransactionExecutable::Empty = executable {
stats_key += "unknown";
};
stats_key
},
};
self.context
.simulate_txn_stats()
Expand Down
Loading

0 comments on commit 76eca53

Please sign in to comment.