Skip to content

Commit

Permalink
tweak: Imported a LocalTransactionExecutionV1 representative to catch…
Browse files Browse the repository at this point in the history
… issues sooner
  • Loading branch information
dhedey committed Aug 21, 2024
1 parent 11f2cdd commit 78a5bf2
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 164 deletions.

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions radix-engine/src/transaction/system_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,7 @@ pub struct EventSystemStructure {
pub type SubstateSystemStructures =
IndexMap<NodeId, IndexMap<PartitionNumber, IndexMap<SubstateKey, SubstateSystemStructure>>>;

#[derive(Default, Debug, Clone, ScryptoSbor, PartialEq, Eq, ScryptoSborAssertion)]
// This is currently persisted in the node's `LocalTransactionExecution` store,
// so needs to be backwards compatible to avoid breaking the Core API transaction stream.
// This assertion can be removed when `radixdlt-scrypto` is merged into the node,
// because there will be an equivalent assertion against the `LocalTransactionExecution` itself.
#[sbor_assert(backwards_compatible(bottlenose = "FILE:system_structure_v1.txt"))]
#[derive(Default, Debug, Clone, ScryptoSbor, PartialEq, Eq)]
pub struct SystemStructure {
pub substate_system_structures: SubstateSystemStructures,
pub event_system_structures: IndexMap<EventTypeIdentifier, EventSystemStructure>,
Expand Down
1 change: 0 additions & 1 deletion radix-engine/src/transaction/system_structure_v1.txt

This file was deleted.

33 changes: 33 additions & 0 deletions radix-engine/src/transaction/transaction_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1670,3 +1670,36 @@ pub enum FlamegraphError {
CreationError,
DetailedCostBreakdownNotAvailable,
}

#[cfg(test)]
mod tests {
use super::*;

// This is an effective copy of the V1 contents of the local transaction execution store in the node.
// This needs to be decodable!
// By all means introduce _new versions_ of the included types, with conversions between them,
// and we can introduce a higher LocalTransactionExecutionVX in the node.
// But this schema can't change, else we won't be able to decode existing executions in the node.
// NOTE: This is just copied here to catch issues / changes earlier; an identical test exists in the node.
#[derive(ScryptoSbor, ScryptoSborAssertion)]
#[sbor_assert(
backwards_compatible(
bottlenose = "FILE:node_local_transaction_execution_v1_bottlenose.txt",
),
settings(allow_name_changes)
)]
struct LocalTransactionExecutionV1 {
outcome: Result<(), RuntimeError>,
fee_summary: TransactionFeeSummary,
fee_source: FeeSource,
fee_destination: FeeDestination,
engine_costing_parameters: CostingParameters,
transaction_costing_parameters: TransactionCostingParametersReceipt,
application_logs: Vec<(Level, String)>,
state_update_summary: StateUpdateSummary,
global_balance_summary: IndexMap<GlobalAddress, IndexMap<ResourceAddress, BalanceChange>>,
substates_system_structure: Vec<SubstateSystemStructure>,
events_system_structure: IndexMap<EventTypeIdentifier, EventSystemStructure>,
next_epoch: Option<EpochChangeEvent>,
}
}
27 changes: 15 additions & 12 deletions radix-sbor-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,32 +172,35 @@ pub fn scrypto_sbor(input: TokenStream) -> TokenStream {
/// A macro for outputting tests and marker traits to assert that a type has maintained its shape over time.
///
/// There are two types of assertion modes:
/// * "fixed" mode is used to ensure that a type is unchanged.
/// * "backwards_compatible" mode is used when multiple versions of the type are permissible, but
/// * `fixed` mode is used to ensure that a type is unchanged.
/// * `backwards_compatible` mode is used when multiple versions of the type are permissible, but
/// newer versions of the type must be compatible with the older version where they align.
/// This mode (A) ensures that the type's current schema is equivalent to the latest version, and
/// (B) ensures that each of the schemas is a strict extension of the previous mode.
///
/// There is also a "generate" mode which can be used to export the current schema. Upon running the generated test,
/// the schema is either written to a file, or output in a panic message.
/// ## Initial schema generation and regeneration
///
/// ## Initial schema generation
/// To output a generated schema, temporarily add a `generate` parameter or a `regenerate` parameter,
/// after the `fixed` or `backwards_compatible` parameter, and then run the created test.
/// If using Rust Analyzer this can be run from the IDE, or it can be run via `cargo test`.
///
/// To output the generated schema to a file path relative to the source file, add an attribute like this -
/// and then run the test which gets generated. If using Rust Analyzer this can be run from the IDE,
/// or it can be run via `cargo test`.
/// To protect against accidentally doing the wrong thing, `generate` can only be used for initial generation,
/// whereas `regenerate` can only be used for replacing an existing generation.
///
/// If a "FILE:.." path is specified, it will (re)generate that file, else it will output to the console:
/// * In `fixed` mode, this will (re)generate against the given schema location.
/// * In `backwards_compatible` mode, this will (re)generate against the latest schema location (the last in the list).
///
/// The test will then panic to ensure it fails, and can't be left accidentally in (re)generate state.
///
/// ```no_run
/// #[derive(ScryptoSbor, ScryptoSborAssertion)]
/// #[sbor_assert(generate("FILE:MyType-schema-v1.txt"))]
/// #[sbor_assert(fixed("FILE:MyType-schema-v1.txt"), generate)]
/// struct MyType {
/// // ...
/// }
/// ```
///
/// The test should generate the given file and then panic. If you wish to only generate the schema
/// in the panic message, you can with `#[sbor_assert(generate("INLINE"))]`.
///
/// ## Fixed schema verification
///
/// To verify the type's schema is unchanged, do:
Expand Down
Loading

0 comments on commit 78a5bf2

Please sign in to comment.