Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: burn-block-height inside of at-block #5524

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jbencin
Copy link
Contributor

@jbencin jbencin commented Dec 2, 2024

Description

Fix burn-block-height keyword inside of at-block context. See hirosystems/clarinet#1615 for details

Applicable issues

Additional info (benefits, drawbacks, caveats)

I'm a little unsure of this this part

.or_else(|_| self.get_index_block_header_hash(cur_stacks_height - 1))?

I had to do this so unit tests would pass, but we get the expected behavior in Clarinet:

(define-read-only (get-burn (height uint))
    (let
        (
            (id (unwrap! (get-stacks-block-info? id-header-hash height) (err 1)))
        )
        (at-block id
            (ok { burn-block-height: burn-block-height, stacks-block-height: stacks-block-height })
        )
    )
)
> ::advance_burn_chain_tip 100
new burn height: 101
new stacks height: 101
> ::advance_chain_tip 100
new burn height: 101
new stacks height: 201
> (contract-call? .contract-0 get-burn u1)
(ok { burn-block-height: u1, stacks-block-height: u1 })
> (contract-call? .contract-0 get-burn u100)
(ok { burn-block-height: u100, stacks-block-height: u100 })
> (contract-call? .contract-0 get-burn u101)
(ok { burn-block-height: u101, stacks-block-height: u101 })
> (contract-call? .contract-0 get-burn u102)
(ok { burn-block-height: u101, stacks-block-height: u102 })
> (contract-call? .contract-0 get-burn u200)
(ok { burn-block-height: u101, stacks-block-height: u200 })
> ::advance_burn_chain_tip 1
new burn height: 102
new stacks height: 202
> ::advance_burn_chain_tip 1
new burn height: 103
new stacks height: 203
> (contract-call? .contract-0 get-burn u202)
(ok { burn-block-height: u102, stacks-block-height: u202 })
> (contract-call? .contract-0 get-burn u203)
(err 1)

Checklist

  • Test coverage for new or modified code paths
  • Changelog is updated
  • Required documentation changes (e.g., docs/rpc/openapi.yaml and rpc-endpoints.md for v2 endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo
  • New integration test(s) added to bitcoin-tests.yml

@jbencin jbencin changed the title fix:: burn-block-height inside of at-block fix: burn-block-height inside of at-block Dec 2, 2024
@obycode
Copy link
Contributor

obycode commented Dec 9, 2024

NOTE: We need to include this in a release before 3.1 activates, or else it will require an additional hard-fork.

The or_else that @jbencin is concerned about is due to the fact that the info is not written into the database until the first block of the tenure is mined. We ran into a similar situation with the implementation for get-burn-block-info? and decided to just leave it such that it is unable to retrieve burn block info for the current block in the first block of a tenure.

@kantai do you have any thoughts for a better way to handle this?

@kantai
Copy link
Member

kantai commented Dec 9, 2024

@kantai do you have any thoughts for a better way to handle this?

Right — I think the best thing to do might be to add an instance variable to the underlying store like “current burn block” — this would be set to the burn view when block processing begins. The at-block call would then handle looking up the burn view at the at-block target, and set the current burn block at that point, resetting it on return.

This would be a bit more complicated, but it would separate the logic for setting burn block height between at block and normal operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants