Skip to content

Commit

Permalink
feat: add hash image validaiton on profile deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
aleortega committed Oct 10, 2024
1 parent 7bed01c commit 93b9cfa
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
2 changes: 1 addition & 1 deletion content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@dcl/catalyst-api-specs": "^3.3.0",
"@dcl/catalyst-contracts": "^4.4.2",
"@dcl/catalyst-storage": "^4.2.0",
"@dcl/content-validator": "^5.6.1",
"@dcl/content-validator": "https://sdk-team-cdn.decentraland.org/@dcl/content-validator/branch/feat/hash-validaitons-on-profiles/dcl-content-validator-5.6.2-11280139091.commit-5a94e5c.tgz",
"@dcl/crypto": "^3.4.5",
"@dcl/hashing": "^3.0.4",
"@dcl/schemas": "^14.0.0",
Expand Down
1 change: 1 addition & 0 deletions content/src/logic/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export async function retryFailedDeploymentExecution(
for (const failedDeployment of failedDeployments) {
// Build Deployment from other servers
const { entityId, entityType, authChain } = failedDeployment

if (authChain) {
logs.debug(`Will retry to deploy entity`, { entityId, entityType })
try {
Expand Down
34 changes: 33 additions & 1 deletion content/src/service/validations/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { createItemChecker, createL1Checker, createL2Checker } from '../../logic
import { AppComponents } from '../../types'
import { createThirdPartyItemChecker } from '../../logic/third-party-item-checker'
import { createThirdPartyContractRegistry } from '../../logic/third-party-contract-registry'
import { hashV0, hashV1 } from '@dcl/hashing'
import { Readable } from 'stream'

const createEthereumProvider = (httpProvider: HTTPProvider): EthereumProvider => {
const reqMan = new RequestManager(httpProvider)
Expand All @@ -46,6 +48,35 @@ const createEthereumProvider = (httpProvider: HTTPProvider): EthereumProvider =>
export async function createExternalCalls(
components: Pick<AppComponents, 'storage' | 'authenticator' | 'env' | 'logs'>
): Promise<ExternalCalls> {
async function calculateFilesHashes(
files: Map<string, Uint8Array>
): Promise<Map<string, { calculatedHash: string; buffer: Uint8Array }>> {
const resultMap = new Map<string, { calculatedHash: string; buffer: Uint8Array }>()
// const hashes = await components.storage.existMultiple(Array.from(files.values()).map((file) => file.toString()))
// iterate each file
for (const [key, value] of files.entries()) {
if (await components.storage.exist(key)) {
const contentFile = await components.storage.retrieve(key)
if (contentFile) {
const streamContent = await contentFile?.asStream()
const calculatedHash = key.startsWith('Qm') ? await hashV0(streamContent) : await hashV1(streamContent)
resultMap.set(key, { calculatedHash, buffer: value })
} else {
const temporalFileName = `${key}-${Date.now()}`
await components.storage.storeStream(temporalFileName, Readable.from(value))
const streamContent = await (await components.storage.retrieve(temporalFileName))!.asStream()
resultMap.set(key, {
calculatedHash: key.startsWith('Qm') ? await hashV0(streamContent) : await hashV1(streamContent),
buffer: value
})
await components.storage.delete([temporalFileName])
}
}
}

return resultMap
}

return {
isContentStoredAlready: (hashes) => components.storage.existMultiple(hashes),
fetchContentFileSize: async (hash) => {
Expand All @@ -60,7 +91,8 @@ export async function createExternalCalls(
ownerAddress: (auditInfo) => Authenticator.ownerAddress(auditInfo.authChain),
isAddressOwnedByDecentraland: (address: string) => components.authenticator.isAddressOwnedByDecentraland(address),
validateSignature: (entityId, auditInfo, timestamp) =>
components.authenticator.validateSignature(entityId, auditInfo.authChain, timestamp)
components.authenticator.validateSignature(entityId, auditInfo.authChain, timestamp),
calculateFilesHashes
}
}

Expand Down
34 changes: 18 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,24 @@
dependencies:
ethers "^5.6.8"

"@dcl/content-validator@^5.6.1":
version "5.6.1"
resolved "https://registry.npmjs.org/@dcl/content-validator/-/content-validator-5.6.1.tgz"
integrity sha512-KFJNtKaxy01mp6N/IRP0DnhV7PxDJ3T0F32vifYGiuZeyYBg6Ya7i1KN1fMpsMRXQllk3BEE4MPJo+dcKujD2w==
"@dcl/content-validator@https://sdk-team-cdn.decentraland.org/@dcl/content-validator/branch/feat/hash-validaitons-on-profiles/dcl-content-validator-5.6.2-11277644723.commit-42539a2.tgz":
version "5.6.2-11277644723.commit-42539a2"
resolved "https://sdk-team-cdn.decentraland.org/@dcl/content-validator/branch/feat/hash-validaitons-on-profiles/dcl-content-validator-5.6.2-11277644723.commit-42539a2.tgz#73285c411682674dbda9bb9baeacb7602849ca63"
dependencies:
"@dcl/block-indexer" "^1.1.2"
"@dcl/content-hash-tree" "^1.1.4"
"@dcl/hashing" "^3.0.4"
"@dcl/schemas" "^13.2.1"
"@dcl/urn-resolver" "^3.6.0"
"@well-known-components/interfaces" "^1.4.3"
"@well-known-components/thegraph-component" "^1.6.0"
ms "^2.1.3"
p-queue "^6.6.2"
sharp "0.32.6"

"@dcl/content-validator@https://sdk-team-cdn.decentraland.org/@dcl/content-validator/branch/feat/hash-validaitons-on-profiles/dcl-content-validator-5.6.2-11280139091.commit-5a94e5c.tgz":
version "5.6.2-11280139091.commit-5a94e5c"
resolved "https://sdk-team-cdn.decentraland.org/@dcl/content-validator/branch/feat/hash-validaitons-on-profiles/dcl-content-validator-5.6.2-11280139091.commit-5a94e5c.tgz#c035da80e7450c4a1efe8e6dcca7580513580373"
dependencies:
"@dcl/block-indexer" "^1.1.2"
"@dcl/content-hash-tree" "^1.1.4"
Expand Down Expand Up @@ -419,18 +433,6 @@
ajv-errors "^3.0.0"
ajv-keywords "^5.1.0"

"@dcl/snapshots-fetcher@^9.0.3":
version "9.0.3"
resolved "https://registry.npmjs.org/@dcl/snapshots-fetcher/-/snapshots-fetcher-9.0.3.tgz"
integrity sha512-IQutxo1bHCDuINFnMfU8fORTMIXfVdwRSdh3mVrpk7PepgPdbvXRHFXvnPF7KL8onkKbsHLLTma0QeaT84IPRw==
dependencies:
"@dcl/catalyst-storage" "^4.0.0"
"@dcl/hashing" "^3.0.3"
"@dcl/schemas" "^9.1.1"
"@well-known-components/interfaces" "^1.4.0"
"@well-known-components/metrics" "^2.0.0"
p-queue "^6.6.2"

"@dcl/snapshots-fetcher@https://sdk-team-cdn.decentraland.org/@dcl/snapshots-fetcher/branch/fix/remove-sv-after-retry/dcl-snapshots-fetcher-9.0.4-11275876250.commit-35f0cc4.tgz":
version "9.0.4-11275876250.commit-35f0cc4"
resolved "https://sdk-team-cdn.decentraland.org/@dcl/snapshots-fetcher/branch/fix/remove-sv-after-retry/dcl-snapshots-fetcher-9.0.4-11275876250.commit-35f0cc4.tgz#2e3ab55db3b67e3207932e8f413664b5960a0ccf"
Expand Down

0 comments on commit 93b9cfa

Please sign in to comment.