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

Fix inventory handling #611

Merged
merged 5 commits into from
Dec 22, 2022
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
8 changes: 7 additions & 1 deletion common/src/main/java/bisq/common/data/ByteArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
import com.google.protobuf.ByteString;
import lombok.Getter;

import java.math.BigInteger;
import java.util.Arrays;

@Getter
public final class ByteArray implements Proto {
public final class ByteArray implements Proto, Comparable<ByteArray> {
private final byte[] bytes;

public ByteArray(byte[] bytes) {
Expand Down Expand Up @@ -57,4 +58,9 @@ public int hashCode() {
public String toString() {
return Hex.encode(bytes);
}

@Override
public int compareTo(ByteArray o) {
return new BigInteger(this.getBytes()).compareTo(new BigInteger(o.getBytes()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ private void initialize() {

widthProperty().addListener(widthListener);
heightProperty().addListener(heightListener);
}

UIThread.runOnNextRenderFrame(this::adjustMinHeight);
}

private void adjustMinHeight() {
if (getParent() instanceof Pane) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected void onViewDetached() {
private void addHeaderBox() {
Label headlineLabel = new MultiLineLabel(Res.get("academy.overview.headline"));
headlineLabel.getStyleClass().add("bisq-text-headline-4");
headlineLabel.setMinHeight(35);
headlineLabel.setMinHeight(55);

Label contentLabel = new MultiLineLabel(Res.get("academy.overview.content"));
contentLabel.getStyleClass().add("bisq-text-16");
Expand Down
2 changes: 1 addition & 1 deletion i18n/src/main/resources/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ roles.type.ORACLE.inline=an oracle operator
roles.registration.info=How to become {0}?\n\n\
1. Copy the public key\n\
2. Backup your data directory as your key pair is persisted in that directory.\n\
3. Make a proposal at https://github.com/bisq-network/proposals to become {1} and paste your public key in the proposal.\n\
3. Make a proposal at 'https://github.com/bisq-network/proposals' to become {1} and paste your public key, the user profile name, bot ID and profile ID in the proposal.\n\
4. After your proposal got reviewed and got support from the community, make a DAO proposal for a bonded role.\n\
5. After your DAO proposal got accepted in DAO voting lock up the required BSQ bond.\n\
6. After your bond transaction is confirmed open a GitHub issue at Bisq 2 (https://github.com/bisq-network/bisq2/issues) with your public key, the link to the GitHub proposal and the lockup transaction.\n\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,34 @@

package bisq.network.p2p.services.data.inventory;

import bisq.common.data.ByteArray;
import bisq.common.proto.Proto;
import bisq.network.p2p.services.data.DataRequest;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Getter
@ToString
@EqualsAndHashCode
@Slf4j
public final class Inventory implements Proto {
private final Set<? extends DataRequest> entries;
private final List<? extends DataRequest> entries;
private final int numDropped;

public Inventory(Set<? extends DataRequest> entries, int numDropped) {
this.entries = entries;
public Inventory(Collection<? extends DataRequest> entries, int numDropped) {
this.entries = new ArrayList<>(entries);
this.numDropped = numDropped;

// We need to sort deterministically as the data is used in the proof of work check
this.entries.sort(Comparator.comparing((DataRequest o) -> new ByteArray(o.serialize())));
}

public bisq.network.protobuf.Inventory toProto() {
Expand All @@ -50,9 +56,9 @@ public bisq.network.protobuf.Inventory toProto() {

public static Inventory fromProto(bisq.network.protobuf.Inventory proto) {
List<bisq.network.protobuf.DataRequest> entriesList = proto.getEntriesList();
Set<DataRequest> entries = entriesList.stream()
List<DataRequest> entries = entriesList.stream()
.map(DataRequest::fromProto)
.collect(Collectors.toSet());
.collect(Collectors.toList());
return new Inventory(entries, proto.getNumDropped());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ public Inventory getInventoryFromStore(DataFilter dataFilter, DataStorageService

private Inventory getInventory(DataFilter dataFilter,
Set<? extends Map.Entry<ByteArray, ? extends DataRequest>> entrySet) {
HashSet<? extends DataRequest> result = entrySet.stream()
Set<? extends DataRequest> result = entrySet.stream()
.filter(mapEntry -> !dataFilter.getFilterEntries().contains(getFilterEntry(mapEntry)))
.map(Map.Entry::getValue)
.collect(Collectors.toCollection(HashSet::new));
.collect(Collectors.toSet());
return new Inventory(result, entrySet.size() - result.size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ public static AddAuthenticatedDataRequest from(AuthenticatedDataStorageService s
}

@Getter
protected final AuthenticatedSequentialData authenticatedSequentialData;
private final AuthenticatedSequentialData authenticatedSequentialData;
@Getter
protected final byte[] signature; // 256 bytes
private final byte[] signature; // 256 bytes
@Getter
protected final byte[] ownerPublicKeyBytes; // 294 bytes
private final byte[] ownerPublicKeyBytes; // 294 bytes
@Nullable
transient protected PublicKey ownerPublicKey;
transient private PublicKey ownerPublicKey;

public AddAuthenticatedDataRequest(AuthenticatedSequentialData authenticatedSequentialData, byte[] signature, PublicKey ownerPublicKey) {
this(authenticatedSequentialData,
Expand All @@ -78,10 +78,10 @@ public AddAuthenticatedDataRequest(AuthenticatedSequentialData authenticatedSequ
ownerPublicKey);
}

protected AddAuthenticatedDataRequest(AuthenticatedSequentialData authenticatedSequentialData,
byte[] signature,
byte[] ownerPublicKeyBytes,
PublicKey ownerPublicKey) {
private AddAuthenticatedDataRequest(AuthenticatedSequentialData authenticatedSequentialData,
byte[] signature,
byte[] ownerPublicKeyBytes,
PublicKey ownerPublicKey) {
this.authenticatedSequentialData = authenticatedSequentialData;
this.signature = signature;
this.ownerPublicKeyBytes = ownerPublicKeyBytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public static RefreshAuthenticatedDataRequest from(AuthenticatedDataStorageServi
signature);
}

protected final MetaData metaData;
protected final byte[] hash;
protected final byte[] ownerPublicKeyBytes; // 442 bytes
transient protected final PublicKey ownerPublicKey;
protected final int sequenceNumber;
protected final byte[] signature; // 47 bytes
private final MetaData metaData;
private final byte[] hash;
private final byte[] ownerPublicKeyBytes; // 442 bytes
transient private final PublicKey ownerPublicKey;
private final int sequenceNumber;
private final byte[] signature; // 47 bytes

public RefreshAuthenticatedDataRequest(MetaData metaData,
byte[] hash,
Expand All @@ -72,12 +72,12 @@ public RefreshAuthenticatedDataRequest(MetaData metaData,
signature);
}

protected RefreshAuthenticatedDataRequest(MetaData metaData,
byte[] hash,
byte[] ownerPublicKeyBytes,
PublicKey ownerPublicKey,
int sequenceNumber,
byte[] signature) {
private RefreshAuthenticatedDataRequest(MetaData metaData,
byte[] hash,
byte[] ownerPublicKeyBytes,
PublicKey ownerPublicKey,
int sequenceNumber,
byte[] signature) {
this.metaData = metaData;
this.hash = hash;
this.ownerPublicKeyBytes = ownerPublicKeyBytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public static RemoveAuthenticatedDataRequest from(AuthenticatedDataStorageServic
signature);
}

protected final MetaData metaData;
protected final byte[] hash;
protected final byte[] ownerPublicKeyBytes; // 442 bytes
private final MetaData metaData;
private final byte[] hash;
private final byte[] ownerPublicKeyBytes; // 442 bytes
@Nullable
transient protected PublicKey ownerPublicKey;
protected final int sequenceNumber;
protected final byte[] signature; // 47 bytes
protected final long created;
transient private PublicKey ownerPublicKey;
private final int sequenceNumber;
private final byte[] signature; // 47 bytes
private final long created;

public RemoveAuthenticatedDataRequest(MetaData metaData,
byte[] hash,
Expand All @@ -73,12 +73,12 @@ public RemoveAuthenticatedDataRequest(MetaData metaData,
signature);
}

protected RemoveAuthenticatedDataRequest(MetaData metaData,
byte[] hash,
byte[] ownerPublicKeyBytes,
PublicKey ownerPublicKey,
int sequenceNumber,
byte[] signature) {
private RemoveAuthenticatedDataRequest(MetaData metaData,
byte[] hash,
byte[] ownerPublicKeyBytes,
PublicKey ownerPublicKey,
int sequenceNumber,
byte[] signature) {
this(metaData,
hash,
ownerPublicKeyBytes,
Expand All @@ -88,13 +88,13 @@ protected RemoveAuthenticatedDataRequest(MetaData metaData,
System.currentTimeMillis());
}

protected RemoveAuthenticatedDataRequest(MetaData metaData,
byte[] hash,
byte[] ownerPublicKeyBytes,
PublicKey ownerPublicKey,
int sequenceNumber,
byte[] signature,
long created) {
private RemoveAuthenticatedDataRequest(MetaData metaData,
byte[] hash,
byte[] ownerPublicKeyBytes,
PublicKey ownerPublicKey,
int sequenceNumber,
byte[] signature,
long created) {
this.metaData = metaData;
this.hash = hash;
this.ownerPublicKeyBytes = ownerPublicKeyBytes;
Expand Down