Skip to content

Commit

Permalink
Merge source branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zurcusa committed Aug 29, 2024
2 parents c9d5ac2 + 238925b commit 43c1900
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,28 @@
import lombok.Getter;
import lombok.ToString;

import java.util.Arrays;
import java.util.Map;

/**
* Represents the light synchronization state in the genesis block.
*
* <p>This class contains the finalized block header, epoch changes, and
* the GRANDPA authority set necessary for light clients to synchronize with the blockchain.</p>
*/
@Getter
@ToString
public class LightSyncState {
private BlockHeader finalizedBlockHeader;
private EpochChanges epochChanges;
private AuthoritySet grandpaAuthoritySet;

/**
* Decodes LightSyncState from a map of hex-encoded strings.
*
* @param lightSyncStateMap A map with keys: "finalizedBlockHeader", "babeEpochChanges", and "grandpaAuthoritySet".
* @return A decoded LightSyncState instance.
* @throws IllegalStateException if any required data is missing.
*/
public static LightSyncState decode(Map<String, String> lightSyncStateMap) {
String header = lightSyncStateMap.get("finalizedBlockHeader");
String epochChanges = lightSyncStateMap.get("babeEpochChanges");
Expand All @@ -38,14 +50,14 @@ public static LightSyncState decode(Map<String, String> lightSyncStateMap) {
LightSyncState lightSyncState = new LightSyncState();
byte[] bytes = StringUtils.hexToBytes(header);
lightSyncState.finalizedBlockHeader = new BlockHeaderReader()
.read(new ScaleCodecReader(bytes));
.read(new ScaleCodecReader(bytes));

byte[] bytes1 = StringUtils.hexToBytes(epochChanges);
lightSyncState.epochChanges = new EpochChangesReader()
.read(new ScaleCodecReader(bytes1));
.read(new ScaleCodecReader(bytes1));

lightSyncState.grandpaAuthoritySet = new AuthoritySetReader()
.read(new ScaleCodecReader(StringUtils.hexToBytes(grandpaAuthoritySet)));
.read(new ScaleCodecReader(StringUtils.hexToBytes(grandpaAuthoritySet)));

return lightSyncState;
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/limechain/sync/warpsync/WarpSyncMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ public void start() {
this.warpSyncAction = new RpcFallbackAction();
}

// new Thread(() -> {
while (this.warpSyncAction.getClass() != FinishedAction.class) {
this.handleState();
this.nextState();
}
new Thread(() -> {
while (this.warpSyncAction.getClass() != FinishedAction.class) {
this.handleState();
this.nextState();
}

finishWarpSync();
// }).start();
finishWarpSync();
}).start();
}

public void stop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public void handle(WarpSyncMachine sync) {
throw new MissingObjectException("No response received.");
}

log.log(Level.INFO, "Successfully received fragments from peer");
log.log(Level.INFO, "Successfully received response from peer");
if (resp.getFragments().length == 0) {
log.log(Level.WARNING, "No fragments received.");
log.log(Level.WARNING, "The response contained no fragments - the peer is up to date.");
return;
}
warpSyncState.setWarpSyncFragmentsFinished(resp.isFinished());
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/limechain/utils/json/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;

@Log
public class ObjectMapper {
Expand Down Expand Up @@ -52,7 +51,6 @@ private Field findField(Class<?> clazz, String fieldName) {
if (failOnUnknownField) {
throw new IllegalStateException("Field " + fieldName + " does not exist in " + clazz.getName());
} else {
log.log(Level.FINE, "Field " + fieldName + " does not exist in " + clazz.getName());
return null;
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@
<script src="https://unpkg.com/@libp2p/bootstrap/dist/index.min.js"></script>
<script src="https://unpkg.com/@libp2p/ping/dist/index.min.js"></script>
<script src="https://unpkg.com/@chainsafe/libp2p-gossipsub/dist/index.min.js"></script>
<script src="https://unpkg.com/@libp2p/interface-libp2p/dist/index.min.js"></script>
<script src="https://unpkg.com/it-protobuf-stream/dist/index.min.js"></script>
<!-- <script src="" defer></script>-->
<script src="https://unpkg.com/libp2p/dist/index.min.js"></script>
<script src="https://unpkg.com/it-pipe/dist/index.min.js"></script>
<script src="https://unpkg.com/it-pb-stream/dist/index.min.js"></script>
<script src=""></script>
<script type="text/javascript" charset="utf-8" src="js/blake2b.js"></script>
<script type="text/javascript" charset="utf-8" src="js/ed25519.js"></script>
<script type="text/javascript" charset="utf-8" src="js/fruzhin.js"></script>
<script type="text/javascript" charset="utf-8" src="js/http.js"></script>
<script type="text/javascript" charset="utf-8" src="js/fruzhin.js"></script>
</head>
<body>
<script>
Expand Down

0 comments on commit 43c1900

Please sign in to comment.