stacks-network / stacks-core

The Stacks blockchain implementation
https://docs.stacks.co
GNU General Public License v3.0
3.01k stars 672 forks source link

Handling unlock events in Nakamoto #5455

Open obycode opened 1 week ago

obycode commented 1 week ago

When a token unlock occurs in Stacks 2.x, a mint event is attached to the coinbase transaction. This is what the API uses to track these unlocks.

These unlocks are based on Stacks block height, not tenure height or bitcoin block height, so in 3.x, the Stacks block at which an unlock occurs might not have a coinbase transaction, since only the first block in a tenure includes a coinbase now. The stacks-node needs to attach these events somewhere else. In the current implementation, the events are just dropped if the block does not have a coinbase, causing a discrepancy in the API's view of the balances and total supply.

hstove commented 1 week ago

This has to be epoch-gated, right?

obycode commented 1 week ago

I don't think so. I think we can change events without breaking consensus. The API will handle back-filling the missed events on migration, then I think the fixed version could emit all events, including the ones that were previously missed, when booting from genesis.

hstove commented 1 week ago

Ok, so we're not going to actually "include" this TX in a block - we basically want to emit a "phantom" tx with these events (as part of a new_block payload)?

obycode commented 1 week ago

Exactly.

aldur commented 1 week ago

Is this required before we can ship #5446?

obycode commented 1 week ago

It's a separate issue from #5446, but more urgent I'd say.