mirror of
https://github.com/luxfi/chains.git
synced 2026-09-24 00:26:00 +00:00
Accept marked the block accepted and moved lastAccepted before writing anything, then issued a Put per nullifier and per output, each returning early. A failure partway left some notes spent and some outputs created under a tip the chain had already advanced. Worse, the spent-nullifier cache advanced as it went, and MarkNullifierSpent refuses a nullifier it already holds — so the block that failed could never be applied again. The chain was stuck at that height holding notes it believed spent with no block recording the spend. Everything a block writes — nullifiers, outputs, the state root — now stages through the store's view and commits in one batch with the block and the tip. On failure the view is rolled back and the three caches are rebuilt from what committed, so the block can simply be applied again. The DAG vertex had the same defect and goes through the same store. That is why the store's Block is not the engine's block interface: a vertex has several parents and no timestamp, so it cannot satisfy it, and it changes state exactly the same way. The store is generic in what a chain tracks, so Propose, Open and Block hand back the chain's own type and no caller asserts. Also here: genesis is seeded through Seed, which commits on its own, because a staged allocation would ride on whichever block landed first and vanish from a chain that never accepted one. StateTree.Finalize records the root before holding it, rather than after. Restoring the original Accept fails the atomicity test; removing the cache rebuild fails it on the line that says the cache must agree with the database.
16 lines
363 B
Go
16 lines
363 B
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package zkvm
|
|
|
|
import (
|
|
"github.com/luxfi/chains/chain"
|
|
"github.com/luxfi/ids"
|
|
)
|
|
|
|
// VMID is the unique identifier for ZKVM (Z-Chain)
|
|
var VMID = ids.ID{'z', 'k', 'v', 'm'}
|
|
|
|
// Factory creates Z-Chain VM instances.
|
|
type Factory = chain.Factory[VM]
|