Skip to content

Instantly share code, notes, and snippets.

@kushti
Created January 8, 2023 19:19
Show Gist options
  • Save kushti/7990c53bacb248c46ea297305d8ceeef to your computer and use it in GitHub Desktop.
Save kushti/7990c53bacb248c46ea297305d8ceeef to your computer and use it in GitHub Desktop.
fromSnapshot functions removed from UtxoState (not used now)
def fromSnapshot(prover: BatchAVLProver[Digest32, HF],
settings: ErgoSettings) = {
val stateDir = ErgoState.stateDir(settings)
stateDir.mkdirs()
val constants = StateConstants(settings)
val store = new LDBVersionedStore(stateDir, initialKeepVersions = constants.keepVersions)
val version = store.get(bestVersionKey).map(w => bytesToVersion(w))
.getOrElse(ErgoState.genesisStateVersion)
val persistentProver: PersistentBatchAVLProver[Digest32, HF] = {
val np = NodeParameters(keySize = 32, valueSize = None, labelSize = 32)
val storage: VersionedLDBAVLStorage[Digest32, HF] = new VersionedLDBAVLStorage(store, np)(Algos.hash)
PersistentBatchAVLProver.create(prover, storage).get
}
new UtxoState(persistentProver, version, store, constants)
}
// todo: do we need to restore from disk?
def fromLatestSnapshot(settings: ErgoSettings): Try[UtxoState] = {
val snapshotsDb = SnapshotsDb.create(settings)
fromLatestSnapshot(settings, snapshotsDb)
}
// todo: do we need to restore from disk?
def fromLatestSnapshot(settings: ErgoSettings,
snapshotDb: SnapshotsDb): Try[UtxoState] = Try {
val snapshotsInfo = snapshotDb.readSnapshotsInfo
val (h, manifestId) = snapshotsInfo.availableManifests.maxBy(_._1)
log.info(s"Reading snapshot from height $h")
val manifest = snapshotDb.readManifest(manifestId).get
val subtreeIds = manifest.subtreesIds
val subtrees = subtreeIds.map(sid => snapshotDb.readSubtree(sid).get)
val serializer = new BatchAVLProverSerializer[Digest32, HF]()(ErgoAlgos.hash)
val prover = serializer.combine(manifest -> subtrees, Algos.hash.DigestSize, None).get
fromSnapshot(prover, settings)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment