Skip to content

Commit

Permalink
Merge pull request #390 from Concordium/retain-events
Browse files Browse the repository at this point in the history
Retain events
  • Loading branch information
abizjak authored Jan 26, 2024
2 parents 144f55b + 0574f68 commit 24b160a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 5 deletions.
7 changes: 5 additions & 2 deletions concordium-std/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

## Unreleased changes

- Fix a bug that caused a linking error when using `concordium_dbg!`.
## concordium-std 9.0.1 (2024-01-26)

- Fix a bug that caused a linking error when using `concordium_dbg!` on some
platforms.
- The error message states that `_debug_print` cannot be found.

## concordium-std 6.0.0 (2024-01-22)
## concordium-std 9.0.0 (2024-01-22)

- Add a `concordium_dbg!` macro and the associated `debug` feature to enable,
together with `cargo concordium`, to emit debug information during contract
Expand Down
2 changes: 1 addition & 1 deletion concordium-std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "concordium-std"
version = "9.0.0"
version = "9.0.1"
authors = ["Concordium <[email protected]>"]
edition = "2021"
rust-version = "1.66"
Expand Down
7 changes: 7 additions & 0 deletions contract-testing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Unreleased changes

## 4.1.0

- Fix a bug in debug output. The events emitted before some contract queries
(such as querying account balance) were not emitted in the debug output. To
fix this, `DebugTraceElement` gets a new variant `Debug` to retain these
events.

## 4.0.0

- Add support for debug output when running smart contracts. This adds a new
Expand Down
2 changes: 1 addition & 1 deletion contract-testing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "concordium-smart-contract-testing"
version = "4.0.0"
version = "4.1.0"
edition = "2021"
rust-version = "1.67"
license = "MPL-2.0"
Expand Down
18 changes: 17 additions & 1 deletion contract-testing/src/invocation/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ macro_rules! exit_ooe {
};
}

impl InvocationData {
/// An internal helper function to construct a [`DebugTraceElement`] from a
/// set of debug events.
pub(crate) fn debug_trace(&self, debug_trace: DebugTracker) -> DebugTraceElement {
DebugTraceElement::Debug {
entrypoint: self.entrypoint.clone(),
address: self.address,
debug_trace,
}
}
}

/// Ok response from the `invoke_entrypoint_initial` method. This is the
/// execution up to either success, failure, or the first interrupt.
///
Expand Down Expand Up @@ -722,13 +734,13 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
kind: v1::InvokeFailure::NonExistentAccount,
},
};

exit_ooe!(
self.remaining_energy.tick_energy(
constants::CONTRACT_INSTANCE_QUERY_ACCOUNT_BALANCE_COST,
),
trace
);
trace_elements.push(invocation_data.debug_trace(trace));
stack.push(Next::Resume {
data: invocation_data,
config,
Expand Down Expand Up @@ -757,6 +769,7 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
),
trace
);
trace_elements.push(invocation_data.debug_trace(trace));
stack.push(Next::Resume {
data: invocation_data,
config,
Expand All @@ -782,6 +795,7 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
trace
);

trace_elements.push(invocation_data.debug_trace(trace));
stack.push(Next::Resume {
data: invocation_data,
config,
Expand Down Expand Up @@ -853,6 +867,7 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
kind: v1::InvokeFailure::NonExistentAccount,
},
};
trace_elements.push(invocation_data.debug_trace(trace));
stack.push(Next::Resume {
data: invocation_data,
config,
Expand Down Expand Up @@ -889,6 +904,7 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
kind: v1::InvokeFailure::NonExistentAccount,
},
};
trace_elements.push(invocation_data.debug_trace(trace));
stack.push(Next::Resume {
data: invocation_data,
config,
Expand Down
32 changes: 32 additions & 0 deletions contract-testing/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ impl ContractInvokeSuccess {
DebugTraceElement::WithFailures {
..
} => None,
DebugTraceElement::Debug {
..
} => None,
})
}

Expand All @@ -575,6 +578,9 @@ impl ContractInvokeSuccess {
DebugTraceElement::WithFailures {
..
} => None,
DebugTraceElement::Debug {
..
} => None,
})
.collect()
}
Expand Down Expand Up @@ -911,6 +917,18 @@ fn debug_events_worker(
self.stack.push(Next::Remaining((true, trace_elements)));
}
}
DebugTraceElement::Debug {
entrypoint,
address,
debug_trace,
} => {
return Some(DebugItem {
address: *address,
entrypoint: entrypoint.as_entrypoint_name(),
debug_trace,
rolled_back: false,
});
}
}
}
}
Expand Down Expand Up @@ -938,6 +956,20 @@ pub enum DebugTraceElement {
energy_used: Energy,
debug_trace: DebugTracker,
},
/// A record of debug events emitted before the interrupt.
/// Contract queries, such as querying account balance or exchange rates do
/// not produce any events visible in the
/// [`Regular`](DebugTraceElement::Regular) trace elements
/// or in the transaction outcomes, but the internal debug information is
/// still useful for debugging.
Debug {
/// The entrypoint that is being executed.
entrypoint: OwnedEntrypointName,
/// The address that is affected.
address: ContractAddress,
/// Events emitted until the interrupt.
debug_trace: DebugTracker,
},
/// One or multiple trace elements that fail. Useful for debugging.
/// This variant also contains additional information, such as the error,
/// entrypoint, and energy usage.
Expand Down

0 comments on commit 24b160a

Please sign in to comment.