diff --git a/src/main/java/com/limechain/network/Network.java b/src/main/java/com/limechain/network/Network.java index 5117c1bfd..8abe59c6a 100644 --- a/src/main/java/com/limechain/network/Network.java +++ b/src/main/java/com/limechain/network/Network.java @@ -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; @@ -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(); diff --git a/src/main/java/com/limechain/rpc/server/CommonConfig.java b/src/main/java/com/limechain/rpc/server/CommonConfig.java index 5e3b24642..45ae13095 100644 --- a/src/main/java/com/limechain/rpc/server/CommonConfig.java +++ b/src/main/java/com/limechain/rpc/server/CommonConfig.java @@ -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; @@ -22,7 +21,6 @@ public class CommonConfig { public static void start() { getBean(SystemInfo.class); getBean(HostConfig.class); - getBean(LocalStorage.class); getBean(WarpSyncMachine.class); } @@ -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": @@ -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": @@ -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, diff --git a/src/main/java/com/limechain/storage/block/SyncState.java b/src/main/java/com/limechain/storage/block/SyncState.java index a105b818d..7022d3536 100644 --- a/src/main/java/com/limechain/storage/block/SyncState.java +++ b/src/main/java/com/limechain/storage/block/SyncState.java @@ -20,7 +20,6 @@ @Log public class SyncState { - private final LocalStorage repository; private BigInteger lastFinalizedBlockNumber; private final BigInteger startingBlock; private final Hash256 genesisBlockHash; @@ -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; @@ -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() { diff --git a/src/main/java/com/limechain/sync/warpsync/WarpSyncState.java b/src/main/java/com/limechain/sync/warpsync/WarpSyncState.java index 4cac1e689..e1edf1bb6 100644 --- a/src/main/java/com/limechain/sync/warpsync/WarpSyncState.java +++ b/src/main/java/com/limechain/sync/warpsync/WarpSyncState.java @@ -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; @@ -25,7 +24,6 @@ public class WarpSyncState { private final SyncState syncState; private final Network network; - private final LocalStorage db; @Getter private boolean warpSyncFragmentsFinished; @@ -36,20 +34,18 @@ public class WarpSyncState { private final PriorityQueue> 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 scheduledRuntimeUpdateBlocks, PriorityQueue> scheduledAuthorityChanges) { this.syncState = syncState; this.network = network; - this.db = db; this.scheduledRuntimeUpdateBlocks = scheduledRuntimeUpdateBlocks; this.scheduledAuthorityChanges = scheduledAuthorityChanges; }