forked from LimeChain/Fruzhin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve syncing startegies (LimeChain#447)
# Description - What does this PR do? 'Get rid' of the old SyncedState class. Create a new class (SyncState) that holds only relevant information about the current sync state and keeps it in the database. Automatically switch to full sync after warp sync. (Currently starts from the first block, but after trie version 1 implementation will update it to start from the latest warp sync block). Fixes LimeChain#335 ## Checklist: - [x] I have read the [contributing guidelines](../CONTRIBUTING.md). - [x] My PR title matches the [Conventional Commits spec](https://www.conventionalcommits.org/). - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [ ] I have added tests to cover my changes. - [x] All new and existing tests passed.
- Loading branch information
Showing
58 changed files
with
724 additions
and
590 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ updates: | |
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
open-pull-requests-limit: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/main/java/com/limechain/chain/lightsyncstate/Authority.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package com.limechain.chain.lightsyncstate; | ||
|
||
import io.emeraldpay.polkaj.types.Hash256; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.io.Serializable; | ||
import java.math.BigInteger; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class Authority { | ||
private final Hash256 publicKey; | ||
public class Authority implements Serializable { | ||
private final byte[] publicKey; | ||
private final BigInteger weight; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...nnounce/scale/BlockAnnounceHandshake.java → ...unce/messages/BlockAnnounceHandshake.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../com/limechain/network/protocol/blockannounce/messages/BlockAnnounceHandshakeBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.limechain.network.protocol.blockannounce.messages; | ||
|
||
import com.limechain.config.HostConfig; | ||
import com.limechain.network.protocol.blockannounce.NodeRole; | ||
import com.limechain.rpc.server.AppBean; | ||
import com.limechain.storage.block.SyncState; | ||
import io.emeraldpay.polkaj.types.Hash256; | ||
|
||
import java.math.BigInteger; | ||
|
||
public class BlockAnnounceHandshakeBuilder { | ||
|
||
/** | ||
* Creates a Block Announce handshake based on the latest finalized Host state | ||
* | ||
* @return our Block Announce handshake | ||
*/ | ||
public BlockAnnounceHandshake getBlockAnnounceHandshake() { | ||
SyncState syncState = AppBean.getBean(SyncState.class); | ||
HostConfig hostConfig = AppBean.getBean(HostConfig.class); | ||
|
||
Hash256 genesisBlockHash = syncState.getGenesisBlockHash(); | ||
Hash256 lastFinalizedBlockHash = syncState.getLastFinalizedBlockHash(); | ||
BigInteger lastFinalizedBlockNumber = syncState.getLastFinalizedBlockNumber(); | ||
|
||
NodeRole nodeRole = hostConfig.getNodeRole(); | ||
|
||
Hash256 blockHash = lastFinalizedBlockHash == null | ||
? genesisBlockHash | ||
: lastFinalizedBlockHash; | ||
return new BlockAnnounceHandshake( | ||
nodeRole.getValue(), | ||
lastFinalizedBlockNumber, | ||
blockHash, | ||
genesisBlockHash | ||
); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...kannounce/scale/BlockAnnounceMessage.java → ...nounce/messages/BlockAnnounceMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...com/limechain/network/protocol/blockannounce/scale/BlockAnnounceHandshakeScaleReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...com/limechain/network/protocol/blockannounce/scale/BlockAnnounceHandshakeScaleWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...a/com/limechain/network/protocol/blockannounce/scale/BlockAnnounceMessageScaleReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.