ENT-11386: Using NodeAttachmentService instead of fat interface ServiceHub. (#7670)

This commit is contained in:
Suhas Krishna Srivastava 2024-02-01 17:19:52 +05:30 committed by GitHub
parent 50a6f2f495
commit a95b854b1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 16 additions and 16 deletions

View File

@ -1201,7 +1201,7 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
override lateinit var networkParameters: NetworkParameters
init {
this@AbstractNode.attachments.servicesForResolution = this
this@AbstractNode.attachments.nodeVerificationSupport = this
}
fun start(myInfo: NodeInfo, networkParameters: NetworkParameters) {

View File

@ -32,7 +32,7 @@ import net.corda.core.internal.entries
import net.corda.core.internal.isUploaderTrusted
import net.corda.core.internal.readFully
import net.corda.core.internal.utilities.ZipBombDetector
import net.corda.core.node.ServicesForResolution
import net.corda.core.internal.verification.NodeVerificationSupport
import net.corda.core.node.services.AttachmentId
import net.corda.core.node.services.vault.AttachmentQueryCriteria
import net.corda.core.node.services.vault.AttachmentSort
@ -90,7 +90,7 @@ class NodeAttachmentService @JvmOverloads constructor(
) : AttachmentStorageInternal, SingletonSerializeAsToken() {
// This is to break the circular dependency.
lateinit var servicesForResolution: ServicesForResolution
lateinit var nodeVerificationSupport: NodeVerificationSupport
companion object {
private val log = contextLogger()
@ -390,7 +390,7 @@ class NodeAttachmentService @JvmOverloads constructor(
private fun increaseDefaultVersionIfWhitelistedAttachment(contractClassNames: List<ContractClassName>, contractVersionFromFile: Int, attachmentId: AttachmentId) =
if (contractVersionFromFile == DEFAULT_CORDAPP_VERSION) {
val versions = contractClassNames.mapNotNull { servicesForResolution.networkParameters.whitelistedContractImplementations[it]?.indexOf(attachmentId) }
val versions = contractClassNames.mapNotNull { nodeVerificationSupport.networkParameters.whitelistedContractImplementations[it]?.indexOf(attachmentId) }
.filter { it >= 0 }.map { it + 1 } // +1 as versions starts from 1 not 0
val max = versions.maxOrNull()
if (max != null && max > contractVersionFromFile) {
@ -416,7 +416,7 @@ class NodeAttachmentService @JvmOverloads constructor(
// set the hash field of the new attachment record.
val bytes = inputStream.readFully()
require(!ZipBombDetector.scanZip(ByteArrayInputStream(bytes), servicesForResolution.networkParameters.maxTransactionSize.toLong())) {
require(!ZipBombDetector.scanZip(ByteArrayInputStream(bytes), nodeVerificationSupport.networkParameters.maxTransactionSize.toLong())) {
"The attachment is too large and exceeds both max transaction size and the maximum allowed compression ratio"
}
val id = bytes.sha256()

View File

@ -10,8 +10,8 @@ import net.corda.core.crypto.SecureHash;
import net.corda.core.identity.AbstractParty;
import net.corda.core.identity.CordaX500Name;
import net.corda.core.identity.Party;
import net.corda.core.internal.verification.NodeVerificationSupport;
import net.corda.core.messaging.DataFeed;
import net.corda.core.node.ServicesForResolution;
import net.corda.core.node.services.AttachmentStorage;
import net.corda.core.node.services.IdentityService;
import net.corda.core.node.services.Vault;
@ -97,9 +97,9 @@ public class VaultQueryJavaTests {
vaultFiller = new VaultFiller(services, DUMMY_NOTARY);
vaultService = services.getVaultService();
storage = new NodeAttachmentService(new MetricRegistry(), new TestingNamedCacheFactory(100), database);
ServicesForResolution serviceForResolution = mock(ServicesForResolution.class);
((NodeAttachmentService) storage).servicesForResolution = serviceForResolution;
doReturn(testNetworkParameters()).when(serviceForResolution).getNetworkParameters();
NodeVerificationSupport nodeVerificationSupport = mock(NodeVerificationSupport.class);
((NodeAttachmentService) storage).nodeVerificationSupport = nodeVerificationSupport;
doReturn(testNetworkParameters()).when(nodeVerificationSupport).getNetworkParameters();
}
@After

View File

@ -6,7 +6,7 @@ import net.corda.core.internal.AttachmentTrustCalculator
import net.corda.core.internal.AttachmentTrustInfo
import net.corda.core.internal.hash
import net.corda.core.internal.read
import net.corda.core.node.ServicesForResolution
import net.corda.core.internal.verification.NodeVerificationSupport
import net.corda.coretesting.internal.rigorousMock
import net.corda.node.services.persistence.NodeAttachmentService
import net.corda.nodeapi.internal.persistence.CordaPersistence
@ -47,7 +47,7 @@ class AttachmentTrustCalculatorTest {
private lateinit var database: CordaPersistence
private lateinit var storage: NodeAttachmentService
private lateinit var attachmentTrustCalculator: AttachmentTrustCalculator
private val services = rigorousMock<ServicesForResolution>().also {
private val nodeVerificationSupport = rigorousMock<NodeVerificationSupport>().also {
doReturn(testNetworkParameters()).whenever(it).networkParameters
}
private val cacheFactory = TestingNamedCacheFactory()
@ -61,7 +61,7 @@ class AttachmentTrustCalculatorTest {
it.start()
}
}
storage.servicesForResolution = services
storage.nodeVerificationSupport = nodeVerificationSupport
attachmentTrustCalculator = NodeAttachmentTrustCalculator(storage, database, cacheFactory)
}

View File

@ -19,7 +19,7 @@ import net.corda.core.internal.cordapp.CordappImpl.Companion.DEFAULT_CORDAPP_VER
import net.corda.core.internal.hash
import net.corda.core.internal.read
import net.corda.core.internal.readFully
import net.corda.core.node.ServicesForResolution
import net.corda.core.internal.verification.NodeVerificationSupport
import net.corda.core.node.services.AttachmentId
import net.corda.core.node.services.vault.AttachmentQueryCriteria.AttachmentsQueryCriteria
import net.corda.core.node.services.vault.AttachmentSort
@ -84,7 +84,7 @@ class NodeAttachmentServiceTest {
private lateinit var database: CordaPersistence
private lateinit var storage: NodeAttachmentService
private lateinit var devModeStorage: NodeAttachmentService
private val services = rigorousMock<ServicesForResolution>().also {
private val nodeVerificationSupport = rigorousMock<NodeVerificationSupport>().also {
doReturn(testNetworkParameters()).whenever(it).networkParameters
}
@ -105,13 +105,13 @@ class NodeAttachmentServiceTest {
it.start()
}
}
storage.servicesForResolution = services
storage.nodeVerificationSupport = nodeVerificationSupport
devModeStorage = NodeAttachmentService(MetricRegistry(), TestingNamedCacheFactory(), database, true).also {
database.transaction {
it.start()
}
}
devModeStorage.servicesForResolution = services
devModeStorage.nodeVerificationSupport = nodeVerificationSupport
}
@After