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

Various small improvements #4954

Merged
merged 5 commits into from
Dec 15, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,10 @@ public void persistNow(@Nullable Runnable completeHandler) {
// reference to the persistable object.
getWriteToDiskExecutor().execute(() -> writeToDisk(serialized, completeHandler));

log.info("Serializing {} took {} msec", fileName, System.currentTimeMillis() - ts);
long duration = System.currentTimeMillis() - ts;
if (duration > 100) {
log.info("Serializing {} took {} msec", fileName, duration);
}
} catch (Throwable e) {
log.error("Error in saveToFile toProtoMessage: {}, {}", persistable.getClass().getSimpleName(), fileName);
e.printStackTrace();
Expand Down Expand Up @@ -437,7 +440,10 @@ public void writeToDisk(protobuf.PersistableEnvelope serialized, @Nullable Runna
e.printStackTrace();
log.error("Cannot close resources." + e.getMessage());
}
log.info("Writing the serialized {} completed in {} msec", fileName, System.currentTimeMillis() - ts);
long duration = System.currentTimeMillis() - ts;
if (duration > 100) {
log.info("Writing the serialized {} completed in {} msec", fileName, duration);
}
persistenceRequested = false;
if (completeHandler != null) {
UserThread.execute(completeHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public final class Role implements PersistablePayload, NetworkPayload, BondedAss
private final String link;
private final BondedRoleType bondedRoleType;

// Only used as cache
transient private final byte[] hash;

/**
* @param name Full name or nickname
* @param link GitHub account or forum account of user
Expand Down Expand Up @@ -74,6 +77,8 @@ private Role(String uid,
this.name = name;
this.link = link;
this.bondedRoleType = bondedRoleType;

hash = Hash.getSha256Ripemd160hash(toProtoMessage().toByteArray());
}

@Override
Expand All @@ -100,8 +105,7 @@ public static Role fromProto(protobuf.Role proto) {

@Override
public byte[] getHash() {
byte[] bytes = toProtoMessage().toByteArray();
return Hash.getSha256Ripemd160hash(bytes);
return hash;
}

@Override
Expand Down
17 changes: 14 additions & 3 deletions core/src/main/java/bisq/core/offer/Offer.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public enum State {
@Setter
transient private PriceFeedService priceFeedService;

// Used only as cache
@Nullable
@JsonExclude
transient private String currencyCode;


///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
Expand Down Expand Up @@ -346,8 +351,9 @@ public boolean isMyOffer(KeyRing keyRing) {


public Optional<String> getAccountAgeWitnessHashAsHex() {
if (getExtraDataMap() != null && getExtraDataMap().containsKey(OfferPayload.ACCOUNT_AGE_WITNESS_HASH))
return Optional.of(getExtraDataMap().get(OfferPayload.ACCOUNT_AGE_WITNESS_HASH));
Map<String, String> extraDataMap = getExtraDataMap();
if (extraDataMap != null && extraDataMap.containsKey(OfferPayload.ACCOUNT_AGE_WITNESS_HASH))
return Optional.of(extraDataMap.get(OfferPayload.ACCOUNT_AGE_WITNESS_HASH));
else
return Optional.empty();
}
Expand Down Expand Up @@ -421,9 +427,14 @@ public String getCountryCode() {
}

public String getCurrencyCode() {
return offerPayload.getBaseCurrencyCode().equals("BTC") ?
if (currencyCode != null) {
return currencyCode;
}

currencyCode = offerPayload.getBaseCurrencyCode().equals("BTC") ?
offerPayload.getCounterCurrencyCode() :
offerPayload.getBaseCurrencyCode();
return currencyCode;
}

public long getProtocolVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ private enum PaymentMethodMapper {
@Getter
private final Map<String, String> extraDataMap;

// We cache the date object to avoid reconstructing a new Date at each getDate call.
@JsonExclude
private transient final Date dateObj;

public TradeStatistics3(String currency,
long price,
long amount,
Expand Down Expand Up @@ -251,6 +255,8 @@ public TradeStatistics3(String currency,
this.extraDataMap = ExtraDataMapValidator.getValidatedExtraDataMap(extraDataMap);

this.hash = hash == null ? createHash() : hash;

dateObj = new Date(date);
}

public byte[] createHash() {
Expand Down Expand Up @@ -319,7 +325,7 @@ public Capabilities getRequiredCapabilities() {

@Override
public Date getDate() {
return new Date(date);
return dateObj;
}

public long getDateAsLong() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public P2PDataStorage(NetworkNode networkNode,
networkNode.addMessageListener(this);
networkNode.addConnectionListener(this);

this.persistenceManager.initialize(sequenceNumberMap, PersistenceManager.Source.PRIVATE);
this.persistenceManager.initialize(sequenceNumberMap, PersistenceManager.Source.PRIVATE_LOW_PRIO);
}


Expand Down