clarinet
clarinet copied to clipboard
Bug when toggling costs in the console
Describe the bug If I enable cost tracking in the console, then make a contract call, clarinet crashes.
To Reproduce Steps to reproduce the behavior:
- Run
clarinet console
- Define a public function:
(define-public (foo) (ok true))
- Toggle costs on:
::toggle_costs
- Call the function
(contract-call? .contract-0 foo)
- See the crash:
thread 'main' panicked at 'failed to initialize cost tracker: CostComputationFailed("Unchecked(NoSuchDataVariable(\"confirmed-proposal-count\"))")', components/clarity-repl/src/repl/interpreter.rs:461:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expected behavior
I expect this to successfully call the function and return (ok true)
.
Environment (please complete the following information):
- OS (version): macOS (13.5)
- Clarinet version: 1.7.1
hey @obycode, thanks for opening this issue. is this blocking you for your hackathon?
Nope, just noticed it while testing something out.
while looking into #1156 I noticed a similar issue. It seems to be a cost-related error in general
>> (define-public (foo) (ok true))
→ .ST000000000000000000002AMW42H.contract-0 contract successfully stored. Use (contract-call? ...) for invoking the public functions:
>> ::get_costs .contract-0
thread 'main' panicked at 'failed to initialize cost tracker: CostComputationFailed("Unchecked(NoSuchDataVariable(\"confirmed-proposal-count\"))")', components/clarity-repl/src/repl/interpreter.rs:482:18
At a glance it seems to happen in the clarity-vm, rather than the actual interpreter call.
Hey @tippenein Thanks for investigating, I think your comment above and message on Discord put me on the right track.
The clarinet console
can be used in two ways:
- in a project, with a Clarinet.toml, where it would load the manifest and build a valid deployment.
- in standalone (no manifest and some default deployment)
The costs errors only happen in the standalone mode. I think that's because the boot contracts aren't loaded.
These is were we load the default settings: https://github.com/hirosystems/clarinet/blob/2afda6315d7ff9d09e5d4d822f34c5f202ca6dc9/components/clarinet-cli/src/frontend/cli.rs#L1059
I think we could override the Default method for SessionSettings to actually include the minimum required contracts, so at least the costs (maybe as we do here https://github.com/hirosystems/clarinet/blob/2afda6315d7ff9d09e5d4d822f34c5f202ca6dc9/components/clarity-repl/src/bin.rs#L39).
I don't know if cost-voting.clar
is required, it worth a try.
We don't want to include all boot contract because it can take a bit of time to parse and load them
Tried the include_boot_contracts
and unfortunately it didn't work. At least not yet, I'll keep digging into this though, it seems close, but I'm missing something still
@tippenein You get the same error? have you tried changing both
pub include_boot_contracts: Vec<String>,
pub include_costs: bool,
And which boot contract did you include?
Yeah, I tried both and I'm including all the cost related just to see if it works
let settings = repl::SessionSettings {
include_costs: true,
include_boot_contracts: vec![
"costs".into(),
"cost-voting".into(),
"costs-2".into(),
"costs-3".into(),
],
..Default::default()
};
Terminal::new(settings)
if you ::toggle_costs
or call ::get_costs then it seems to always throw the error