Skip to content

Commit

Permalink
refactor: remove deprecated LocalStorage bean.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zurcusa committed Aug 14, 2024
1 parent 7f6289c commit 9cfe9fe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 41 deletions.
9 changes: 3 additions & 6 deletions src/main/java/com/limechain/network/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.limechain.config.HostConfig;
import com.limechain.network.kad.KademliaService;
import com.limechain.rpc.server.AppBean;
import com.limechain.storage.LocalStorage;
import com.limechain.sync.warpsync.WarpSyncState;
import lombok.Getter;
import lombok.extern.java.Log;
Expand Down Expand Up @@ -39,18 +38,16 @@ public class Network {
*
* @param chainService chain specification information containing boot nodes
* @param hostConfig host configuration containing current network
* @param repository database repository
*/
public Network(ChainService chainService, HostConfig hostConfig, LocalStorage repository) {
public Network(ChainService chainService, HostConfig hostConfig) {
this.bootNodes = chainService.getChainSpec().getBootNodes();
this.chain = hostConfig.getChain();
// this.connectionManager = ConnectionManager.getInstance();
this.initializeProtocols(chainService, hostConfig, repository);
this.initializeProtocols(chainService, hostConfig);
}

private void initializeProtocols(ChainService chainService,
HostConfig hostConfig,
LocalStorage repository) {
HostConfig hostConfig) {

//
// String chainId = chainService.getChainSpec().getProtocolId();
Expand Down
30 changes: 9 additions & 21 deletions src/main/java/com/limechain/rpc/server/CommonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.limechain.config.HostConfig;
import com.limechain.config.SystemInfo;
import com.limechain.network.Network;
import com.limechain.storage.LocalStorage;
import com.limechain.storage.block.SyncState;
import com.limechain.sync.warpsync.WarpSyncMachine;
import com.limechain.sync.warpsync.WarpSyncState;
Expand All @@ -22,7 +21,6 @@ public class CommonConfig {
public static void start() {
getBean(SystemInfo.class);
getBean(HostConfig.class);
getBean(LocalStorage.class);
getBean(WarpSyncMachine.class);
}

Expand All @@ -35,16 +33,12 @@ protected static Object getBean(Class<?> beanClass) {
HostConfig hostConfig = hostConfig();
beans.put(beanClass, hostConfig);
return hostConfig;
case "KVRepository":
LocalStorage repository = repository((HostConfig) getBean(HostConfig.class));
beans.put(beanClass, repository);
return repository;
case "ChainService":
ChainService chainService = chainService((HostConfig) getBean(HostConfig.class));
beans.put(beanClass, chainService);
return chainService;
case "SyncState":
SyncState syncState = syncState((LocalStorage) getBean(LocalStorage.class));
SyncState syncState = syncState();
beans.put(beanClass, syncState);
return syncState;
case "SystemInfo":
Expand All @@ -53,12 +47,12 @@ protected static Object getBean(Class<?> beanClass) {
return systemInfo;
case "Network":
Network network = network((ChainService) getBean(ChainService.class),
(HostConfig) getBean(HostConfig.class), (LocalStorage) getBean(LocalStorage.class));
(HostConfig) getBean(HostConfig.class));
beans.put(beanClass, network);
return network;
case "WarpSyncState":
WarpSyncState warpSyncState = warpSyncState((Network) getBean(Network.class),
(SyncState) getBean(SyncState.class), (LocalStorage) getBean(LocalStorage.class));
(SyncState) getBean(SyncState.class));
beans.put(beanClass, warpSyncState);
return warpSyncState;
case "WarpSyncMachine":
Expand All @@ -77,30 +71,24 @@ private static HostConfig hostConfig() {
return new HostConfig();
}

private static LocalStorage repository(HostConfig hostConfig) {
return null;//DBInitializer.initialize(hostConfig.getChain());
}

private static ChainService chainService(HostConfig hostConfig) {
return new ChainService(hostConfig);
}

private static SyncState syncState(LocalStorage repository) {
return new SyncState(repository);
private static SyncState syncState() {
return new SyncState();
}

private static SystemInfo systemInfo(HostConfig hostConfig, SyncState syncState) {
return new SystemInfo(hostConfig, syncState);
}

private static Network network(ChainService chainService, HostConfig hostConfig,
LocalStorage repository) {
return new Network(chainService, hostConfig, repository);
private static Network network(ChainService chainService, HostConfig hostConfig) {
return new Network(chainService, hostConfig);
}

private static WarpSyncState warpSyncState(Network network, SyncState syncState,
LocalStorage repository) {
return new WarpSyncState(syncState, network, repository);
private static WarpSyncState warpSyncState(Network network, SyncState syncState) {
return new WarpSyncState(syncState, network);
}

private static WarpSyncMachine warpSyncMachine(Network network, ChainService chainService, SyncState syncState,
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/com/limechain/storage/block/SyncState.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
@Log
public class SyncState {

private final LocalStorage repository;
private BigInteger lastFinalizedBlockNumber;
private final BigInteger startingBlock;
private final Hash256 genesisBlockHash;
Expand All @@ -30,9 +29,8 @@ public class SyncState {
private BigInteger latestRound;
private BigInteger setId;

public SyncState(LocalStorage repository) {
public SyncState() {
this.genesisBlockHash = GenesisBlockHash.POLKADOT;
this.repository = repository;

loadState();
this.startingBlock = this.lastFinalizedBlockNumber;
Expand All @@ -41,16 +39,11 @@ public SyncState(LocalStorage repository) {
private void loadState() {
this.lastFinalizedBlockNumber = LocalStorage.find(
DBConstants.LAST_FINALIZED_BLOCK_NUMBER, BigInteger.class).orElse(BigInteger.ZERO);
System.out.println(lastFinalizedBlockHash);
this.lastFinalizedBlockHash = new Hash256(LocalStorage.find(
DBConstants.LAST_FINALIZED_BLOCK_HASH, byte[].class).orElse(genesisBlockHash.getBytes()));
System.out.println(lastFinalizedBlockHash);
this.authoritySet = LocalStorage.find(DBConstants.AUTHORITY_SET, Authority[].class).orElse(new Authority[0]);
System.out.println(Arrays.toString(authoritySet));
this.latestRound = LocalStorage.find(DBConstants.LATEST_ROUND, BigInteger.class).orElse(BigInteger.ONE);
System.out.println(latestRound);
this.setId = LocalStorage.find(DBConstants.SET_ID, BigInteger.class).orElse(BigInteger.ZERO);
System.out.println(setId);
}

public void persistState() {
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/limechain/sync/warpsync/WarpSyncState.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.limechain.chain.lightsyncstate.Authority;
import com.limechain.network.Network;
import com.limechain.storage.LocalStorage;
import com.limechain.storage.block.SyncState;
import com.limechain.tuple.Pair;
import lombok.Getter;
Expand All @@ -25,7 +24,6 @@ public class WarpSyncState {

private final SyncState syncState;
private final Network network;
private final LocalStorage db;

@Getter
private boolean warpSyncFragmentsFinished;
Expand All @@ -36,20 +34,18 @@ public class WarpSyncState {
private final PriorityQueue<Pair<BigInteger, Authority[]>> scheduledAuthorityChanges;


public WarpSyncState(SyncState syncState, Network network, LocalStorage db) {
public WarpSyncState(SyncState syncState, Network network) {
this(syncState,
network,
db,
new HashSet<>(),
new PriorityQueue<>(Comparator.comparing(Pair::getValue0)));
}

public WarpSyncState(SyncState syncState, Network network, LocalStorage db,
public WarpSyncState(SyncState syncState, Network network,
Set<BigInteger> scheduledRuntimeUpdateBlocks,
PriorityQueue<Pair<BigInteger, Authority[]>> scheduledAuthorityChanges) {
this.syncState = syncState;
this.network = network;
this.db = db;
this.scheduledRuntimeUpdateBlocks = scheduledRuntimeUpdateBlocks;
this.scheduledAuthorityChanges = scheduledAuthorityChanges;
}
Expand Down

0 comments on commit 9cfe9fe

Please sign in to comment.