clarinet icon indicating copy to clipboard operation
clarinet copied to clipboard

Bug when toggling costs in the console

Open obycode opened this issue 1 year ago • 8 comments

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:

  1. Run clarinet console
  2. Define a public function:
(define-public (foo) (ok true))
  1. Toggle costs on:
::toggle_costs
  1. Call the function
(contract-call? .contract-0 foo)
  1. 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

obycode avatar Aug 16 '23 15:08 obycode

hey @obycode, thanks for opening this issue. is this blocking you for your hackathon?

lgalabru avatar Aug 17 '23 10:08 lgalabru

Nope, just noticed it while testing something out.

obycode avatar Aug 17 '23 11:08 obycode

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.

tippenein avatar Oct 15 '23 16:10 tippenein

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

hugocaillard avatar Oct 27 '23 11:10 hugocaillard

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 avatar Oct 27 '23 15:10 tippenein

@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?

hugocaillard avatar Oct 27 '23 15:10 hugocaillard

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

tippenein avatar Oct 27 '23 15:10 tippenein