mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-22 06:41:41 +01:00
Remove prevHash from StateHash classes (the prevHash was only used for display.
For creating the hash we take the hash from the previous element. By removing it we safe about 3 MB on data) Add isSelfCreated field to DaoStateHash (indicates if we have created the hash by ourself or if we have received it from a peer -> will be part of later commits)
This commit is contained in:
parent
1abe68637d
commit
1f929926cc
19 changed files with 85 additions and 105 deletions
|
@ -274,7 +274,7 @@ public class BlindVoteStateMonitoringService implements DaoSetupService, DaoStat
|
|||
byte[] combined = ArrayUtils.addAll(prevHash, serializedBlindVotes);
|
||||
byte[] hash = Hash.getSha256Ripemd160hash(combined);
|
||||
|
||||
BlindVoteStateHash myBlindVoteStateHash = new BlindVoteStateHash(blockHeight, hash, prevHash, blindVotes.size());
|
||||
BlindVoteStateHash myBlindVoteStateHash = new BlindVoteStateHash(blockHeight, hash, blindVotes.size());
|
||||
BlindVoteStateBlock blindVoteStateBlock = new BlindVoteStateBlock(myBlindVoteStateHash);
|
||||
blindVoteStateBlockChain.add(blindVoteStateBlock);
|
||||
blindVoteStateHashChain.add(myBlindVoteStateHash);
|
||||
|
|
|
@ -310,7 +310,7 @@ public class DaoStateMonitoringService implements DaoSetupService, DaoStateListe
|
|||
byte[] combined = ArrayUtils.addAll(prevHash, stateAsBytes);
|
||||
byte[] hash = Hash.getSha256Ripemd160hash(combined);
|
||||
|
||||
DaoStateHash myDaoStateHash = new DaoStateHash(height, hash, prevHash);
|
||||
DaoStateHash myDaoStateHash = new DaoStateHash(height, hash, true);
|
||||
DaoStateBlock daoStateBlock = new DaoStateBlock(myDaoStateHash);
|
||||
daoStateBlockChain.add(daoStateBlock);
|
||||
daoStateHashChain.add(myDaoStateHash);
|
||||
|
|
|
@ -275,7 +275,7 @@ public class ProposalStateMonitoringService implements DaoSetupService, DaoState
|
|||
}
|
||||
byte[] combined = ArrayUtils.addAll(prevHash, serializedProposals);
|
||||
byte[] hash = Hash.getSha256Ripemd160hash(combined);
|
||||
ProposalStateHash myProposalStateHash = new ProposalStateHash(blockHeight, hash, prevHash, proposals.size());
|
||||
ProposalStateHash myProposalStateHash = new ProposalStateHash(blockHeight, hash, proposals.size());
|
||||
ProposalStateBlock proposalStateBlock = new ProposalStateBlock(myProposalStateHash);
|
||||
proposalStateBlockChain.add(proposalStateBlock);
|
||||
proposalStateHashChain.add(myProposalStateHash);
|
||||
|
|
|
@ -29,8 +29,8 @@ public final class BlindVoteStateHash extends StateHash {
|
|||
@Getter
|
||||
private final int numBlindVotes;
|
||||
|
||||
public BlindVoteStateHash(int cycleStartBlockHeight, byte[] hash, byte[] prevHash, int numBlindVotes) {
|
||||
super(cycleStartBlockHeight, hash, prevHash);
|
||||
public BlindVoteStateHash(int cycleStartBlockHeight, byte[] hash, int numBlindVotes) {
|
||||
super(cycleStartBlockHeight, hash);
|
||||
this.numBlindVotes = numBlindVotes;
|
||||
}
|
||||
|
||||
|
@ -43,14 +43,12 @@ public final class BlindVoteStateHash extends StateHash {
|
|||
return protobuf.BlindVoteStateHash.newBuilder()
|
||||
.setHeight(height)
|
||||
.setHash(ByteString.copyFrom(hash))
|
||||
.setPrevHash(ByteString.copyFrom(prevHash))
|
||||
.setNumBlindVotes(numBlindVotes).build();
|
||||
}
|
||||
|
||||
public static BlindVoteStateHash fromProto(protobuf.BlindVoteStateHash proto) {
|
||||
return new BlindVoteStateHash(proto.getHeight(),
|
||||
proto.getHash().toByteArray(),
|
||||
proto.getPrevHash().toByteArray(),
|
||||
proto.getNumBlindVotes());
|
||||
}
|
||||
|
||||
|
|
|
@ -18,12 +18,14 @@
|
|||
package bisq.core.dao.monitoring.model;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DaoStateBlock extends StateBlock<DaoStateHash> {
|
||||
public DaoStateBlock(DaoStateHash myDaoStateHash) {
|
||||
super(myDaoStateHash);
|
||||
}
|
||||
|
||||
public boolean isSelfCreated() {
|
||||
return myStateHash.isSelfCreated();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,17 @@ package bisq.core.dao.monitoring.model;
|
|||
import com.google.protobuf.ByteString;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public final class DaoStateHash extends StateHash {
|
||||
public DaoStateHash(int height, byte[] hash, byte[] prevHash) {
|
||||
super(height, hash, prevHash);
|
||||
// If we have built the hash by ourself opposed to that we got delivered the hash from seed nodes or resources
|
||||
private final boolean isSelfCreated;
|
||||
|
||||
public DaoStateHash(int height, byte[] hash, boolean isSelfCreated) {
|
||||
super(height, hash);
|
||||
this.isSelfCreated = isSelfCreated;
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,12 +44,18 @@ public final class DaoStateHash extends StateHash {
|
|||
return protobuf.DaoStateHash.newBuilder()
|
||||
.setHeight(height)
|
||||
.setHash(ByteString.copyFrom(hash))
|
||||
.setPrevHash(ByteString.copyFrom(prevHash)).build();
|
||||
.setIsSelfCreated(isSelfCreated)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static DaoStateHash fromProto(protobuf.DaoStateHash proto) {
|
||||
return new DaoStateHash(proto.getHeight(),
|
||||
proto.getHash().toByteArray(),
|
||||
proto.getPrevHash().toByteArray());
|
||||
return new DaoStateHash(proto.getHeight(), proto.getHash().toByteArray(), proto.getIsSelfCreated());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DaoStateHash{" +
|
||||
"\r\n isSelfCreated=" + isSelfCreated +
|
||||
"\r\n} " + super.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ public final class ProposalStateHash extends StateHash {
|
|||
@Getter
|
||||
private final int numProposals;
|
||||
|
||||
public ProposalStateHash(int cycleStartBlockHeight, byte[] hash, byte[] prevHash, int numProposals) {
|
||||
super(cycleStartBlockHeight, hash, prevHash);
|
||||
public ProposalStateHash(int cycleStartBlockHeight, byte[] hash, int numProposals) {
|
||||
super(cycleStartBlockHeight, hash);
|
||||
this.numProposals = numProposals;
|
||||
}
|
||||
|
||||
|
@ -43,14 +43,12 @@ public final class ProposalStateHash extends StateHash {
|
|||
return protobuf.ProposalStateHash.newBuilder()
|
||||
.setHeight(height)
|
||||
.setHash(ByteString.copyFrom(hash))
|
||||
.setPrevHash(ByteString.copyFrom(prevHash))
|
||||
.setNumProposals(numProposals).build();
|
||||
}
|
||||
|
||||
public static ProposalStateHash fromProto(protobuf.ProposalStateHash proto) {
|
||||
return new ProposalStateHash(proto.getHeight(),
|
||||
proto.getHash().toByteArray(),
|
||||
proto.getPrevHash().toByteArray(),
|
||||
proto.getNumProposals());
|
||||
}
|
||||
|
||||
|
|
|
@ -56,10 +56,6 @@ public abstract class StateBlock<T extends StateHash> {
|
|||
return myStateHash.getHash();
|
||||
}
|
||||
|
||||
public byte[] getPrevHash() {
|
||||
return myStateHash.getPrevHash();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StateBlock{" +
|
||||
|
|
|
@ -40,13 +40,10 @@ import lombok.extern.slf4j.Slf4j;
|
|||
public abstract class StateHash implements PersistablePayload, NetworkPayload {
|
||||
protected final int height;
|
||||
protected final byte[] hash;
|
||||
// For first block the prevHash is an empty byte array
|
||||
protected final byte[] prevHash;
|
||||
|
||||
StateHash(int height, byte[] hash, byte[] prevHash) {
|
||||
StateHash(int height, byte[] hash) {
|
||||
this.height = height;
|
||||
this.hash = hash;
|
||||
this.prevHash = prevHash;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -67,7 +64,6 @@ public abstract class StateHash implements PersistablePayload, NetworkPayload {
|
|||
return "StateHash{" +
|
||||
"\n height=" + height +
|
||||
",\n hash=" + Utilities.bytesAsHexString(hash) +
|
||||
",\n prevHash=" + Utilities.bytesAsHexString(prevHash) +
|
||||
"\n}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2495,6 +2495,9 @@ dao.monitor.proposals=Proposals state
|
|||
dao.monitor.blindVotes=Blind votes state
|
||||
|
||||
dao.monitor.table.peers=Peers
|
||||
dao.monitor.table.hashCreator=Hash creator
|
||||
dao.monitor.table.hashCreator.self=Self
|
||||
dao.monitor.table.hashCreator.peer=Peer
|
||||
dao.monitor.table.conflicts=Conflicts
|
||||
dao.monitor.state=Status
|
||||
dao.monitor.requestAlHashes=Request all hashes
|
||||
|
|
|
@ -36,10 +36,9 @@ import lombok.extern.slf4j.Slf4j;
|
|||
@Getter
|
||||
@EqualsAndHashCode
|
||||
public abstract class StateBlockListItem<StH extends StateHash, StB extends StateBlock<StH>> {
|
||||
private final StateBlock<StH> stateBlock;
|
||||
protected final StateBlock<StH> stateBlock;
|
||||
private final Supplier<String> height;
|
||||
private final String hash;
|
||||
private final String prevHash;
|
||||
private final String numNetworkMessages;
|
||||
private final String numMisMatches;
|
||||
private final boolean isInSync;
|
||||
|
@ -58,7 +57,6 @@ public abstract class StateBlockListItem<StH extends StateHash, StB extends Stat
|
|||
Res.get("dao.monitor.table.cycleBlockHeight", cycleIndexSupplier.getAsInt() + 1,
|
||||
String.valueOf(stateBlock.getHeight())))::get;
|
||||
hash = Utilities.bytesAsHexString(stateBlock.getHash());
|
||||
prevHash = stateBlock.getPrevHash().length > 0 ? Utilities.bytesAsHexString(stateBlock.getPrevHash()) : "-";
|
||||
numNetworkMessages = String.valueOf(stateBlock.getPeersMap().size());
|
||||
int size = stateBlock.getInConflictMap().size();
|
||||
numMisMatches = String.valueOf(size);
|
||||
|
|
|
@ -38,7 +38,6 @@ public abstract class StateInConflictListItem<T extends StateHash> {
|
|||
private final String peerAddressString;
|
||||
private final String height;
|
||||
private final String hash;
|
||||
private final String prevHash;
|
||||
private final T stateHash;
|
||||
|
||||
protected StateInConflictListItem(String peerAddress, T stateHash, int cycleIndex,
|
||||
|
@ -52,7 +51,5 @@ public abstract class StateInConflictListItem<T extends StateHash> {
|
|||
cycleIndex + 1,
|
||||
String.valueOf(stateHash.getHeight()));
|
||||
hash = Utilities.bytesAsHexString(stateHash.getHash());
|
||||
prevHash = stateHash.getPrevHash().length > 0 ?
|
||||
Utilities.bytesAsHexString(stateHash.getPrevHash()) : "-";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,8 +177,6 @@ public abstract class StateMonitorView<StH extends StateHash,
|
|||
|
||||
protected abstract String getPeersTableHeader();
|
||||
|
||||
protected abstract String getPrevHashTableHeader();
|
||||
|
||||
protected abstract String getHashTableHeader();
|
||||
|
||||
protected abstract String getBlockHeightTableHeader();
|
||||
|
@ -353,31 +351,6 @@ public abstract class StateMonitorView<StH extends StateHash,
|
|||
tableView.getColumns().add(column);
|
||||
|
||||
|
||||
column = new AutoTooltipTableColumn<>(getPrevHashTableHeader());
|
||||
column.setMinWidth(120);
|
||||
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
|
||||
column.setCellFactory(
|
||||
new Callback<>() {
|
||||
|
||||
@Override
|
||||
public TableCell<BLI, BLI> call(TableColumn<BLI,
|
||||
BLI> column) {
|
||||
return new TableCell<>() {
|
||||
@Override
|
||||
public void updateItem(final BLI item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null)
|
||||
setText(item.getPrevHash());
|
||||
else
|
||||
setText("");
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
column.setComparator(Comparator.comparing(BLI::getPrevHash));
|
||||
tableView.getColumns().add(column);
|
||||
|
||||
|
||||
column = new AutoTooltipTableColumn<>(getPeersTableHeader());
|
||||
column.setMinWidth(80);
|
||||
column.setMaxWidth(column.getMinWidth());
|
||||
|
@ -402,6 +375,7 @@ public abstract class StateMonitorView<StH extends StateHash,
|
|||
column.setComparator(Comparator.comparing(e -> e.getStateBlock().getPeersMap().size()));
|
||||
tableView.getColumns().add(column);
|
||||
|
||||
|
||||
column = new AutoTooltipTableColumn<>(getConflictsTableHeader());
|
||||
column.setMinWidth(80);
|
||||
column.setMaxWidth(column.getMinWidth());
|
||||
|
@ -543,30 +517,6 @@ public abstract class StateMonitorView<StH extends StateHash,
|
|||
conflictTableView.getColumns().add(column);
|
||||
|
||||
|
||||
column = new AutoTooltipTableColumn<>(getPrevHashTableHeader());
|
||||
column.setMinWidth(120);
|
||||
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
|
||||
column.setCellFactory(
|
||||
new Callback<>() {
|
||||
@Override
|
||||
public TableCell<CLI, CLI> call(
|
||||
TableColumn<CLI, CLI> column) {
|
||||
return new TableCell<>() {
|
||||
@Override
|
||||
public void updateItem(final CLI item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null)
|
||||
setText(item.getPrevHash());
|
||||
else
|
||||
setText("");
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
column.setComparator(Comparator.comparing(CLI::getPrevHash));
|
||||
conflictTableView.getColumns().add(column);
|
||||
|
||||
|
||||
column = new AutoTooltipTableColumn<>("");
|
||||
column.setMinWidth(120);
|
||||
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
|
||||
|
|
|
@ -149,11 +149,6 @@ public class BlindVoteStateMonitorView extends StateMonitorView<BlindVoteStateHa
|
|||
return Res.get("dao.monitor.table.peers");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPrevHashTableHeader() {
|
||||
return Res.get("dao.monitor.blindVote.table.prev");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHashTableHeader() {
|
||||
return Res.get("dao.monitor.blindVote.table.hash");
|
||||
|
|
|
@ -21,6 +21,7 @@ import bisq.desktop.main.dao.monitor.StateBlockListItem;
|
|||
|
||||
import bisq.core.dao.monitoring.model.DaoStateBlock;
|
||||
import bisq.core.dao.monitoring.model.DaoStateHash;
|
||||
import bisq.core.locale.Res;
|
||||
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
|
@ -35,4 +36,10 @@ class DaoStateBlockListItem extends StateBlockListItem<DaoStateHash, DaoStateBlo
|
|||
DaoStateBlockListItem(DaoStateBlock stateBlock, IntSupplier cycleIndexSupplier) {
|
||||
super(stateBlock, cycleIndexSupplier);
|
||||
}
|
||||
|
||||
String hashCreator() {
|
||||
return ((DaoStateBlock) stateBlock).isSelfCreated() ?
|
||||
Res.get("dao.monitor.table.hashCreator.self") :
|
||||
Res.get("dao.monitor.table.hashCreator.peer");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package bisq.desktop.main.dao.monitor.daostate;
|
||||
|
||||
import bisq.desktop.common.view.FxmlView;
|
||||
import bisq.desktop.components.AutoTooltipTableColumn;
|
||||
import bisq.desktop.main.dao.monitor.StateMonitorView;
|
||||
import bisq.desktop.main.overlays.popups.Popup;
|
||||
import bisq.desktop.util.FormBuilder;
|
||||
|
@ -40,10 +41,18 @@ import bisq.common.util.Utilities;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import javafx.scene.control.TableCell;
|
||||
import javafx.scene.control.TableColumn;
|
||||
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
|
||||
import javafx.collections.ListChangeListener;
|
||||
|
||||
import javafx.util.Callback;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -60,7 +69,6 @@ public class DaoStateMonitorView extends StateMonitorView<DaoStateHash, DaoState
|
|||
// Constructor, lifecycle
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@Inject
|
||||
private DaoStateMonitorView(DaoStateService daoStateService,
|
||||
DaoFacade daoFacade,
|
||||
|
@ -160,11 +168,6 @@ public class DaoStateMonitorView extends StateMonitorView<DaoStateHash, DaoState
|
|||
return Res.get("dao.monitor.table.peers");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPrevHashTableHeader() {
|
||||
return Res.get("dao.monitor.daoState.table.prev");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHashTableHeader() {
|
||||
return Res.get("dao.monitor.daoState.table.hash");
|
||||
|
@ -202,6 +205,35 @@ public class DaoStateMonitorView extends StateMonitorView<DaoStateHash, DaoState
|
|||
daoStateMonitoringService.requestHashesFromGenesisBlockHeight(peerAddress);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createColumns() {
|
||||
super.createColumns();
|
||||
|
||||
TableColumn<DaoStateBlockListItem, DaoStateBlockListItem> column = new AutoTooltipTableColumn<>(Res.get("dao.monitor.table.hashCreator"));
|
||||
column.setMinWidth(90);
|
||||
column.setMaxWidth(column.getMinWidth());
|
||||
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
|
||||
column.setCellFactory(
|
||||
new Callback<>() {
|
||||
@Override
|
||||
public TableCell<DaoStateBlockListItem, DaoStateBlockListItem> call(
|
||||
TableColumn<DaoStateBlockListItem, DaoStateBlockListItem> column) {
|
||||
return new TableCell<>() {
|
||||
@Override
|
||||
public void updateItem(final DaoStateBlockListItem item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null)
|
||||
setText(item.hashCreator());
|
||||
else
|
||||
setText("");
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
column.setComparator(Comparator.comparing(e -> e.getStateBlock().getPeersMap().size()));
|
||||
tableView.getColumns().add(2, column);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
|
|
|
@ -147,11 +147,6 @@ public class ProposalStateMonitorView extends StateMonitorView<ProposalStateHash
|
|||
return Res.get("dao.monitor.table.peers");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPrevHashTableHeader() {
|
||||
return Res.get("dao.monitor.proposal.table.prev");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHashTableHeader() {
|
||||
return Res.get("dao.monitor.proposal.table.hash");
|
||||
|
|
|
@ -41,7 +41,7 @@ public class DaoStateBlockListItemTest {
|
|||
|
||||
@Test
|
||||
public void testEqualsAndHashCode() {
|
||||
var block = new DaoStateBlock(new DaoStateHash(0, new byte[0], new byte[0]));
|
||||
var block = new DaoStateBlock(new DaoStateHash(0, new byte[0], true));
|
||||
var item1 = new DaoStateBlockListItem(block, newSupplier(1));
|
||||
var item2 = new DaoStateBlockListItem(block, newSupplier(2));
|
||||
var item3 = new DaoStateBlockListItem(block, newSupplier(1));
|
||||
|
|
|
@ -2382,20 +2382,21 @@ message DaoStateStore {
|
|||
message DaoStateHash {
|
||||
int32 height = 1;
|
||||
bytes hash = 2;
|
||||
bytes prev_hash = 3;
|
||||
bytes prev_hash = 3 [deprecated = true];
|
||||
bool is_self_created = 4;
|
||||
}
|
||||
|
||||
message ProposalStateHash {
|
||||
int32 height = 1;
|
||||
bytes hash = 2;
|
||||
bytes prev_hash = 3;
|
||||
bytes prev_hash = 3 [deprecated = true];
|
||||
int32 num_proposals = 4;
|
||||
}
|
||||
|
||||
message BlindVoteStateHash {
|
||||
int32 height = 1;
|
||||
bytes hash = 2;
|
||||
bytes prev_hash = 3;
|
||||
bytes prev_hash = 3 [deprecated = true];
|
||||
int32 num_blind_votes = 4;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue