Remove PersistableNetworkPayloadList & TradeStatisticsList

The former class is dead code, together with its store service, as they
were only referenced from CorePersistenceProtoResolver::fromProto, the
binding logic and from AppendOnlyDataStoreService by orphaned migration
code. However, migration from the old persisted data was completed long
ago and the store file is no longer being read or written from anywhere
in the codebase.

Also remove the associated PersistableEnvelope proto message type, along
with the TradeStatisticsList message type. The latter is long deprecated
and has no corresponding Java class implementing PersistableEnvelope, so
removing it won't change behaviour (outside the exception message thrown
when attempting to resolve it).
This commit is contained in:
Steven Barclay 2020-04-11 15:07:16 +08:00
parent edc4df1826
commit e5ed365239
No known key found for this signature in database
GPG key ID: 9FED6BF1176D500B
7 changed files with 3 additions and 256 deletions

View file

@ -44,7 +44,6 @@ import bisq.core.user.PreferencesPayload;
import bisq.core.user.UserPayload;
import bisq.network.p2p.peers.peerexchange.PeerList;
import bisq.network.p2p.storage.persistence.PersistableNetworkPayloadList;
import bisq.network.p2p.storage.persistence.SequenceNumberMap;
import bisq.common.config.Config;
@ -102,8 +101,6 @@ public class CorePersistenceProtoResolver extends CoreProtoResolver implements P
this,
new Storage<>(storageDir, this, corruptedDatabaseFilesHandler),
btcWalletService.get());
case TRADE_STATISTICS_LIST:
throw new ProtobufferRuntimeException("TRADE_STATISTICS_LIST is not used anymore");
case ARBITRATION_DISPUTE_LIST:
return ArbitrationDisputeList.fromProto(proto.getArbitrationDisputeList(),
this,
@ -124,8 +121,6 @@ public class CorePersistenceProtoResolver extends CoreProtoResolver implements P
return NavigationPath.fromProto(proto.getNavigationPath());
case PAYMENT_ACCOUNT_LIST:
return PaymentAccountList.fromProto(proto.getPaymentAccountList(), this);
case PERSISTABLE_NETWORK_PAYLOAD_LIST:
return PersistableNetworkPayloadList.fromProto(proto.getPersistableNetworkPayloadList(), this);
case ACCOUNT_AGE_WITNESS_STORE:
return AccountAgeWitnessStore.fromProto(proto.getAccountAgeWitnessStore());
case TRADE_STATISTICS2_STORE:

View file

@ -28,7 +28,6 @@ import bisq.network.p2p.peers.keepalive.KeepAliveManager;
import bisq.network.p2p.peers.peerexchange.PeerExchangeManager;
import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.persistence.AppendOnlyDataStoreService;
import bisq.network.p2p.storage.persistence.PersistableNetworkPayloadListService;
import bisq.network.p2p.storage.persistence.ProtectedDataStoreService;
import bisq.network.p2p.storage.persistence.ResourceDataStoreService;
@ -62,7 +61,6 @@ public class P2PModule extends AppModule {
bind(P2PDataStorage.class).in(Singleton.class);
bind(AppendOnlyDataStoreService.class).in(Singleton.class);
bind(ProtectedDataStoreService.class).in(Singleton.class);
bind(PersistableNetworkPayloadListService.class).in(Singleton.class);
bind(ResourceDataStoreService.class).in(Singleton.class);
bind(RequestDataManager.class).in(Singleton.class);
bind(PeerExchangeManager.class).in(Singleton.class);

View file

@ -38,20 +38,13 @@ import lombok.extern.slf4j.Slf4j;
public class AppendOnlyDataStoreService {
private List<MapStoreService<? extends PersistableEnvelope, PersistableNetworkPayload>> services = new ArrayList<>();
// We do not add PersistableNetworkPayloadListService to the services list as it it deprecated and used only to
// transfer old persisted data to the new data structure.
@SuppressWarnings("deprecation")
private PersistableNetworkPayloadListService persistableNetworkPayloadListService;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@SuppressWarnings("deprecation")
@Inject
public AppendOnlyDataStoreService(PersistableNetworkPayloadListService persistableNetworkPayloadListService) {
this.persistableNetworkPayloadListService = persistableNetworkPayloadListService;
public AppendOnlyDataStoreService() {
}
public void addService(MapStoreService<? extends PersistableEnvelope, PersistableNetworkPayload> service) {
@ -60,19 +53,6 @@ public class AppendOnlyDataStoreService {
public void readFromResources(String postFix) {
services.forEach(service -> service.readFromResources(postFix));
// transferDeprecatedDataStructure();
}
// Only needed for one time converting the old data store to the new ones. Can be removed after next release when we
// are sure that no issues occurred.
private void transferDeprecatedDataStructure() {
// We read the file if it exists in the db folder
persistableNetworkPayloadListService.readStore();
// Transfer the content to the new services
persistableNetworkPayloadListService.getMap().forEach(this::put);
// We are done with the transfer, now let's remove the file
persistableNetworkPayloadListService.removeFile();
}
public Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> getMap() {

View file

@ -1,86 +0,0 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.network.p2p.storage.persistence;
import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import bisq.common.proto.persistable.ThreadedPersistableEnvelope;
import com.google.protobuf.Message;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
// That class wraps a map but is represented in PB as a list to reduce data size (no key).
// PB also does not support a byte array as key and would require some quirks to support such a map (using hex string
// would render our 20 byte keys to 40 bytes as HEX encoded).
// The class name should be map not list but we want to stick with the PB definition name and that cannot be changed
// without breaking backward compatibility.
// TODO at next hard fork we can rename the PB definition and class name.
@Deprecated
@Slf4j
public class PersistableNetworkPayloadList implements ThreadedPersistableEnvelope {
@Getter
private Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = new ConcurrentHashMap<>();
PersistableNetworkPayloadList() {
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
private PersistableNetworkPayloadList(Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map) {
this.map.putAll(map);
}
public Message toProtoMessage() {
// Protobuffer maps don't support bytes as key so we use a hex string
Set<protobuf.PersistableNetworkPayload> values = map.values().stream()
.map(PersistableNetworkPayload::toProtoMessage)
.collect(Collectors.toSet());
return protobuf.PersistableEnvelope.newBuilder()
.setPersistableNetworkPayloadList(protobuf.PersistableNetworkPayloadList.newBuilder()
.addAllItems(values))
.build();
}
public static PersistableNetworkPayloadList fromProto(protobuf.PersistableNetworkPayloadList proto,
PersistenceProtoResolver resolver) {
Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map = new HashMap<>();
proto.getItemsList()
.forEach(e -> {
PersistableNetworkPayload payload = PersistableNetworkPayload.fromProto(e, resolver);
map.put(new P2PDataStorage.ByteArray(payload.getHash()), payload);
});
return new PersistableNetworkPayloadList(map);
}
public boolean containsKey(P2PDataStorage.ByteArray hash) {
return map.containsKey(hash);
}
}

View file

@ -1,126 +0,0 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.network.p2p.storage.persistence;
import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;
import bisq.common.config.Config;
import bisq.common.storage.FileUtil;
import bisq.common.storage.Storage;
import javax.inject.Named;
import javax.inject.Inject;
import java.nio.file.Paths;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import static com.google.common.base.Preconditions.checkArgument;
/**
* Not used anymore. We still need the class for supporting the transfer of th old data structure to the new.
* Can be removed at the next hard fork.
*/
@Deprecated
@Slf4j
public final class PersistableNetworkPayloadListService extends MapStoreService<PersistableNetworkPayloadList, PersistableNetworkPayload> {
private static final String FILE_NAME = "PersistableNetworkPayloadMap";
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public PersistableNetworkPayloadListService(@Named(Config.STORAGE_DIR) File storageDir,
Storage<PersistableNetworkPayloadList> persistableNetworkPayloadMapStorage) {
super(storageDir, persistableNetworkPayloadMapStorage);
}
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
public void removeFile() {
final File file = new File(Paths.get(absolutePathOfStorageDir, getFileName()).toString());
if (file.exists())
log.info("Remove deprecated file " + file.getAbsolutePath());
try {
FileUtil.deleteFileIfExists(file);
} catch (IOException e) {
e.printStackTrace();
log.error(e.toString());
}
}
@Override
public PersistableNetworkPayload putIfAbsent(P2PDataStorage.ByteArray hash, PersistableNetworkPayload payload) {
throw new RuntimeException("putIfAbsent must not be called on deprecated PersistableNetworkPayloadListService");
}
@Override
protected void persist() {
throw new RuntimeException("persist must not be called on deprecated PersistableNetworkPayloadListService");
}
@Override
public PersistableNetworkPayload remove(P2PDataStorage.ByteArray hash) {
throw new RuntimeException("remove must not be called on deprecated PersistableNetworkPayloadListService");
}
@Override
public boolean canHandle(PersistableNetworkPayload payload) {
throw new RuntimeException("isMyPayload must not be called on deprecated PersistableNetworkPayloadListService");
}
@Override
public String getFileName() {
return FILE_NAME;
}
@Override
public Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> getMap() {
return store.getMap();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Protected
///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected PersistableNetworkPayloadList createStore() {
return new PersistableNetworkPayloadList();
}
@Override
protected void readStore() {
super.readStore();
checkArgument(store instanceof PersistableNetworkPayloadList,
"Store is not instance of TradeStatistics2Store. That can happen if the ProtoBuffer " +
"file got changed. We clear the data store and recreated it again.");
}
}

View file

@ -34,7 +34,6 @@ public class AppendOnlyDataStoreServiceFake extends AppendOnlyDataStoreService {
private final Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> map;
public AppendOnlyDataStoreServiceFake() {
super(null);
map = new HashMap<>();
}

View file

@ -1115,7 +1115,7 @@ message PersistableEnvelope {
NavigationPath navigation_path = 5;
TradableList tradable_list = 6;
TradeStatisticsList trade_statistics_list = 7 [deprecated = true]; // Was used in pre v0.6.0 version. Not used anymore.
// TradeStatisticsList trade_statistics_list = 7; // Was used in pre v0.6.0 version. Not used anymore.
ArbitrationDisputeList arbitration_dispute_list = 8;
PreferencesPayload preferences_payload = 9;
@ -1128,10 +1128,7 @@ message PersistableEnvelope {
AccountAgeWitnessStore account_age_witness_store = 13;
TradeStatistics2Store trade_statistics2_store = 14;
// we need to keep id 15 here otherwise the reading of the old data structure would not work anymore.
// can be removed after most people have updated as the reading of the PersistableNetworkPayloadList
// is not mandatory.
PersistableNetworkPayloadList persistable_network_payload_list = 15 [deprecated = true];
// PersistableNetworkPayloadList persistable_network_payload_list = 15; // long deprecated & migration away from it is already done
ProposalStore proposal_store = 16;
TempProposalStore temp_proposal_store = 17;
@ -1178,11 +1175,6 @@ message PersistedEntryMap {
map<string, ProtectedStorageEntry> persisted_entry_map = 1;
}
// deprecated. Not used anymore.
message PersistableNetworkPayloadList {
repeated PersistableNetworkPayload items = 1;
}
// We use a list not a hash map to save disc space. The hash can be calculated from the payload anyway
message AccountAgeWitnessStore {
repeated AccountAgeWitness items = 1;
@ -1239,11 +1231,6 @@ message TradableList {
repeated Tradable tradable = 1;
}
// deprecated Was used in pre v0.6.0 version. Not used anymore but leave it as it is used in PersistableEnvelope
message TradeStatisticsList {
repeated TradeStatistics trade_statistics = 1;
}
message Offer {
enum State {
PB_ERROR = 0;