Skip to content

Commit

Permalink
Incorporate other feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Hess <matt.hess@swirldslabs.com>
  • Loading branch information
mhess-swl committed Apr 27, 2023
1 parent d24c369 commit 2b04114
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.hedera.node.app.info.InfoDaggerModule;
import com.hedera.node.app.metrics.MetricsDaggerModule;
import com.hedera.node.app.service.mono.ServicesApp;
import com.hedera.node.app.service.mono.cache.CacheModule;
import com.hedera.node.app.service.mono.config.ConfigModule;
import com.hedera.node.app.service.mono.context.ContextModule;
import com.hedera.node.app.service.mono.context.annotations.BootstrapProps;
Expand Down Expand Up @@ -112,8 +111,7 @@
InfoDaggerModule.class,
ThrottleModule.class,
SolvencyModule.class,
TokenServiceModule.class,
CacheModule.class
TokenServiceModule.class
})
public interface HederaApp extends ServicesApp {
/* Needed by ServicesState */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.hedera.node.app.service.mono;

import com.hedera.node.app.service.mono.cache.CacheModule;
import com.hedera.node.app.service.mono.cache.EntityMapWarmer;
import com.hedera.node.app.service.mono.config.ConfigModule;
import com.hedera.node.app.service.mono.context.ContextModule;
Expand Down Expand Up @@ -123,8 +122,7 @@
ExpiryModule.class,
LastStepModule.class,
ProcessLogicModule.class,
FeeCalculatorModule.class,
CacheModule.class
FeeCalculatorModule.class
})
public interface ServicesApp {
/* Needed by ServicesState */
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.bouncycastle.util.encoders.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -54,6 +56,7 @@
* <p>This class is geared towards accounts, unique tokens (NFTs), and token relations, but could
* also be enhanced for other types.
*/
@Singleton
public class EntityMapWarmer {

private static final Logger log = LoggerFactory.getLogger(EntityMapWarmer.class);
Expand All @@ -64,9 +67,14 @@ public class EntityMapWarmer {
private final Supplier<AccountStorageAdapter> accountsStorageAdapter;
private final Supplier<UniqueTokenMapAdapter> nftsAdapter;
private final Supplier<TokenRelStorageAdapter> tokenRelsAdapter;

private final boolean acctsOnDisk;
private final boolean nftsOnDisk;
private final boolean tokenRelsOnDisk;
private final ThreadPoolExecutor threadpool;

private EntityMapWarmer(
@Inject
EntityMapWarmer(
Supplier<AccountStorageAdapter> accountsStorageAdapter,
Supplier<UniqueTokenMapAdapter> nftsAdapter,
Supplier<TokenRelStorageAdapter> tokenRelsAdapter,
Expand All @@ -93,6 +101,9 @@ private EntityMapWarmer(
this.nftsAdapter = nftsAdapter;
this.tokenRelsAdapter = tokenRelsAdapter;
this.threadpool = threadpool;
this.acctsOnDisk = accountsStorageAdapter.get().areOnDisk();
this.nftsOnDisk = nftsAdapter.get().isVirtual();
this.tokenRelsOnDisk = tokenRelsAdapter.get().areOnDisk();
}

public static EntityMapWarmer getInstance(
Expand Down Expand Up @@ -121,19 +132,16 @@ public void warmCache(Round round) {
// "warmTokenObjs" as in "warm the token and its associated token relation objects"
// for both the sending and receiving accounts
private void warmTokenObjs(AccountID sender, AccountID receiver, long tokenNum, long senderSerialNum) {
if (accountsStorageAdapter.get().areOnDisk()
&& nftsAdapter.get().isVirtual()
&& tokenRelsAdapter.get().areOnDisk()) {

if (acctsOnDisk && nftsOnDisk && tokenRelsOnDisk) {
threadpool.execute(() -> {
// Sender:
final var acctMap = accountsStorageAdapter.get().getOnDiskAccounts();
final OnDiskAccount account =
final OnDiskAccount senderAcct =
Objects.requireNonNull(acctMap).get(EntityNumVirtualKey.from(EntityNum.fromAccountId(sender)));
if (account != null) {
final var headNum = account.getHeadNftTokenNum();
if (senderAcct != null) {
final var headNum = senderAcct.getHeadNftTokenNum();
if (headNum != 0) {
final var headSerialNum = account.getHeadNftSerialNum();
final var headSerialNum = senderAcct.getHeadNftSerialNum();
final var nftMap = nftsAdapter.get().getOnDiskNfts();
Objects.requireNonNull(nftMap).warm(new UniqueTokenKey(headNum, headSerialNum));
}
Expand Down Expand Up @@ -193,14 +201,14 @@ private void warmTokenObjs(AccountID sender, AccountID receiver, long tokenNum,
log.debug(
"no-op 'warm' not called on any token objects due to non-matching config:"
+ " accounts on disk = {}, nfts on disk = {}, tokenRels on disk = {}",
accountsStorageAdapter.get().areOnDisk(),
nftsAdapter.get().isVirtual(),
tokenRelsAdapter.get().areOnDisk());
acctsOnDisk,
nftsOnDisk,
tokenRelsOnDisk);
}
}

private void warmAccount(AccountID account) {
if (accountsStorageAdapter.get().areOnDisk()) {
if (acctsOnDisk) {
threadpool.execute(() -> {
final var acctMap = accountsStorageAdapter.get().getOnDiskAccounts();
Objects.requireNonNull(acctMap).warm(EntityNumVirtualKey.from(EntityNum.fromAccountId(account)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.hedera.node.app.service.mono.utils.EntityNum;
import com.hedera.node.app.service.mono.utils.EntityNumPair;
import com.hedera.node.app.service.mono.utils.MiscUtils;
import com.hederahashgraph.api.proto.java.AccountID;
import com.swirlds.common.io.streams.SerializableDataInputStream;
import com.swirlds.common.io.streams.SerializableDataOutputStream;
import com.swirlds.virtualmap.VirtualLongKey;
Expand Down Expand Up @@ -51,6 +52,11 @@ public static EntityNumVirtualKey fromPair(final EntityNumPair num) {
return new EntityNumVirtualKey(num.value());
}

public static EntityNumVirtualKey fromAccountId(AccountID acct) {
final var entityNum = EntityNum.fromAccountId(acct);
return EntityNumVirtualKey.from(entityNum);
}

public EntityNumVirtualKey() {
this(-1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import com.hederahashgraph.api.proto.java.AccountID;
import com.swirlds.common.io.streams.SerializableDataInputStream;
import com.swirlds.common.io.streams.SerializableDataOutputStream;
import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -212,4 +213,12 @@ void serializeUsingSerializableDataOutputStreamWorks() throws IOException {
void canGetEntityNumUsingLongValue() {
assertEquals(subject, fromLong(longKey));
}

@Test
void canGetEntityNumUsingAccountId() {
assertEquals(
subject,
EntityNumVirtualKey.fromAccountId(
AccountID.newBuilder().setAccountNum(longKey).build()));
}
}

0 comments on commit 2b04114

Please sign in to comment.