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

Removed empty asset scripts #3887

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions node/src/main/scala/com/wavesplatform/database/Caches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ abstract class Caches extends Blockchain with Storage {
for (((address, _), (entry, _)) <- updatedDataWithNodes) stateHash.addDataEntry(address, entry.entry)
for ((address, lease) <- leaseBalances) stateHash.addLeaseBalance(address, lease.in, lease.out)
for ((address, script) <- snapshot.accountScriptsByAddress) stateHash.addAccountScript(address, script.map(_.script))
for ((asset, script) <- snapshot.assetScripts) stateHash.addAssetScript(asset, script.map(_.script))
for ((asset, script) <- snapshot.assetScripts) stateHash.addAssetScript(asset, Some(script.script))
for ((asset, _) <- snapshot.assetStatics) if (!snapshot.assetScripts.contains(asset)) stateHash.addAssetScript(asset, None)
for ((leaseId, lease) <- snapshot.leaseStates) stateHash.addLeaseStatus(leaseId, lease.isActive)
for ((assetId, sponsorship) <- snapshot.sponsorships) stateHash.addSponsorship(assetId, sponsorship.minFee)
for ((alias, address) <- snapshot.aliases) stateHash.addAlias(address, alias.name)
Expand Down Expand Up @@ -352,7 +353,7 @@ abstract class Caches extends Blockchain with Storage {
for ((alias, address) <- snapshot.aliases) aliasCache.put(Alias.create(alias.name).explicitGet(), Some(address))
leaseBalanceCache.putAll(leaseBalances.asJava)
scriptCache.putAll(snapshot.accountScriptsByAddress.asJava)
assetScriptCache.putAll(snapshot.assetScripts.asJava)
assetScriptCache.putAll(snapshot.assetScripts.view.mapValues(Some(_)).toMap.asJava)
accountDataCache.putAll(updatedDataWithNodes.map { case (key, (value, _)) => (key, value) }.asJava)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ class RocksDBWriter(

for ((asset, script) <- snapshot.assetScripts) {
expiredKeys ++= updateHistory(rw, Keys.assetScriptHistory(asset), threshold, Keys.assetScript(asset))
if (script.isDefined) rw.put(Keys.assetScript(asset)(height), script)
rw.put(Keys.assetScript(asset)(height), Some(script))
}

if (height % BlockStep == 1) {
Expand Down
15 changes: 5 additions & 10 deletions node/src/main/scala/com/wavesplatform/state/StateSnapshot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ case class StateSnapshot(
assetStatics: VectorMap[IssuedAsset, AssetStatic] = VectorMap(),
assetVolumes: Map[IssuedAsset, AssetVolumeInfo] = Map(),
assetNamesAndDescriptions: Map[IssuedAsset, AssetInfo] = Map(),
assetScripts: Map[IssuedAsset, Option[AssetScriptInfo]] = Map(),
assetScripts: Map[IssuedAsset, AssetScriptInfo] = Map(),
sponsorships: Map[IssuedAsset, SponsorshipValue] = Map(),
leaseStates: Map[ByteStr, LeaseDetails] = Map(),
aliases: Map[Alias, Address] = Map(),
Expand Down Expand Up @@ -57,7 +57,7 @@ case class StateSnapshot(
S.AssetNameAndDescription(asset.id.toByteString, info.name.toStringUtf8, info.description.toStringUtf8, info.lastUpdatedAt)
}.toSeq,
assetScripts.map { case (asset, script) =>
S.AssetScript(asset.id.toByteString, script.fold(ByteString.EMPTY)(_.script.bytes().toByteString))
S.AssetScript(asset.id.toByteString, script.script.bytes().toByteString)
}.toSeq,
aliases.map { case (alias, address) => S.Alias(address.toByteString, alias.name) }.toSeq,
orderFills.map { case (orderId, VolumeAndFee(volume, fee)) =>
Expand Down Expand Up @@ -148,14 +148,9 @@ object StateSnapshot {
.map(b => b.address.toAddress -> LeaseBalance(b.in, b.out))
.toMap

val assetScripts: Map[IssuedAsset, Option[AssetScriptInfo]] =
val assetScripts: Map[IssuedAsset, AssetScriptInfo] =
pbSnapshot.assetScripts.map { s =>
val info =
if (s.script.isEmpty)
None
else
Some(AssetScriptInfo(ScriptReader.fromBytes(s.script.toByteArray).explicitGet(), 0))
s.assetId.toIssuedAssetId -> info
s.assetId.toIssuedAssetId -> AssetScriptInfo(ScriptReader.fromBytes(s.script.toByteArray).explicitGet(), 0)
}.toMap

val assetStatics: VectorMap[IssuedAsset, AssetStatic] =
Expand Down Expand Up @@ -257,7 +252,7 @@ object StateSnapshot {
orderFills: Map[ByteStr, VolumeAndFee] = Map(),
issuedAssets: VectorMap[IssuedAsset, NewAssetInfo] = VectorMap(),
updatedAssets: Map[IssuedAsset, Ior[AssetInfo, AssetVolumeInfo]] = Map(),
assetScripts: Map[IssuedAsset, Option[AssetScriptInfo]] = Map(),
assetScripts: Map[IssuedAsset, AssetScriptInfo] = Map(),
sponsorships: Map[IssuedAsset, Sponsorship] = Map(),
leaseStates: Map[ByteStr, LeaseDetails] = Map(),
aliases: Map[Alias, Address] = Map(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ object TxStateSnapshotHashBuilder {
}

for {
(asset, sv) <- snapshot.assetScripts
script = sv.map(_.script)
} addEntry(KeyType.AssetScript, asset.id.arr)(script.fold(Array.emptyByteArray)(_.bytes().arr))
(asset, scriptInfo) <- snapshot.assetScripts
} addEntry(KeyType.AssetScript, asset.id.arr)(scriptInfo.script.bytes().arr)

snapshot.leaseStates.foreach { case (leaseId, details) =>
addEntry(KeyType.LeaseStatus, leaseId.arr)(booleanToBytes(details.isActive))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ object AssetTransactionsDiffs {
_ <- checkSize(blockchain, tx.script)
snapshot <- StateSnapshot.build(
blockchain,
assetScripts = Map(tx.asset -> script.map(AssetScriptInfo.tupled)),
assetScripts = script.fold(Map[IssuedAsset, AssetScriptInfo]()) { case (script, complexity) =>
Map(tx.asset -> AssetScriptInfo(script, complexity))
},
portfolios = Map(tx.sender.toAddress -> Portfolio(-tx.fee.value))
)
} yield snapshot
Expand Down Expand Up @@ -120,7 +122,9 @@ object AssetTransactionsDiffs {
_ <- checkEstimationOverflow(blockchain, script)
snapshot <- StateSnapshot.build(
blockchain,
assetScripts = Map(asset -> script.map(AssetScriptInfo.tupled)),
assetScripts = script.fold(Map[IssuedAsset, AssetScriptInfo]()) { case (script, complexity) =>
Map(asset -> AssetScriptInfo(script, complexity))
},
issuedAssets = VectorMap(asset -> NewAssetInfo(assetStatic, assetInfo, assetVolume)),
portfolios = VectorMap(tx.sender.toAddress -> Portfolio.build(-tx.fee.value, asset, tx.quantity.value))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,7 @@ object InvokeDiffsCommon {
StateSnapshot.build(
blockchain,
portfolios = Map(pk.toAddress -> Portfolio(assets = VectorMap(asset -> issue.quantity))),
issuedAssets = VectorMap(asset -> NewAssetInfo(staticInfo, info, volumeInfo)),
assetScripts = Map(asset -> None)
issuedAssets = VectorMap(asset -> NewAssetInfo(staticInfo, info, volumeInfo))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ case class SnapshotBlockchain(
override def assetScript(asset: IssuedAsset): Option[AssetScriptInfo] =
maybeSnapshot
.flatMap(_.assetScripts.get(asset))
.getOrElse(inner.assetScript(asset))
.orElse(inner.assetScript(asset))

override def assetDescription(asset: IssuedAsset): Option[AssetDescription] =
SnapshotBlockchain.assetDescription(asset, snapshot, height, inner)
Expand Down Expand Up @@ -267,7 +267,7 @@ object SnapshotBlockchain {
volume.get.isReissuable,
volume.get.volume,
info.get.lastUpdatedAt,
script.flatten,
script,
sponsorship.getOrElse(0),
static.nft,
assetNum,
Expand All @@ -285,7 +285,7 @@ object SnapshotBlockchain {
description = info.map(_.description).getOrElse(d.description),
lastUpdatedAt = info.map(_.lastUpdatedAt).getOrElse(d.lastUpdatedAt),
sponsorship = sponsorship.getOrElse(d.sponsorship),
script = script.getOrElse(d.script)
script = script.orElse(d.script)
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object SnapshotOps {
orderFills(blockchain),
s.leaseStates,
s.accountScripts,
s.assetScripts,
s.assetScripts.view.mapValues(Some(_)).toMap,
s.accountData,
s.sponsorships,
scriptsRun = 0,
Expand Down Expand Up @@ -94,7 +94,7 @@ object SnapshotOps {
diff.orderFills,
diff.issuedAssets,
diff.updatedAssets,
diff.assetScripts,
diff.assetScripts.collect { case (asset, Some(info)) => (asset, info) },
diff.sponsorship,
diff.leaseState,
diff.aliases,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class StateSnapshotProtoTest extends PropSpec {
IssuedAsset(ByteStr.fromBytes(2, 2, 2)) -> AssetInfo("name2", "desc2", Height @@ 999)
),
Map(
IssuedAsset(ByteStr.fromBytes(1, 1, 1)) -> None,
IssuedAsset(ByteStr.fromBytes(2, 2, 2)) -> Some(AssetScriptInfo(TestCompiler(V6).compileAsset("this != this"), 0))
IssuedAsset(ByteStr.fromBytes(2, 2, 2)) -> AssetScriptInfo(TestCompiler(V6).compileAsset("this != this"), 0)
),
Map(
IssuedAsset(ByteStr.fromBytes(1, 1, 1)) -> SponsorshipValue(99999),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class StateSnapshotStorageTest extends PropSpec with WithDomain {
asset -> AssetInfo(issueTx.name, issueTx.description, Height(d.solidStateHeight + 2))
),
assetScripts = Map(
asset -> Some(AssetScriptInfo(script, 0))
asset -> AssetScriptInfo(script, 0)
)
)
)
Expand Down Expand Up @@ -288,7 +288,7 @@ class StateSnapshotStorageTest extends PropSpec with WithDomain {
(senderAddress, Waves) -> (d.balance(senderAddress) - 1.waves)
),
assetScripts = Map(
asset -> Some(AssetScriptInfo(script, 0))
asset -> AssetScriptInfo(script, 0)
)
)
)
Expand Down Expand Up @@ -332,9 +332,6 @@ class StateSnapshotStorageTest extends PropSpec with WithDomain {
assetNamesAndDescriptions = Map(
dAppAssetId -> AssetInfo("name", "description", Height(height))
),
assetScripts = Map(
dAppAssetId -> None
),
leaseStates = Map(
leaseId -> LeaseDetails(dAppPk, senderAddress, 123, Active, invokeId, height)
),
Expand Down