-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added BeefyConsensusMessage and BeefyConsensusMessageFormat, im…
…plemented scale reading. Introduced beefy consensus message processing in addBlockToTree() method (without implementation of the handler).
- Loading branch information
Hristiyan Mitov
committed
Feb 20, 2025
1 parent
4f6dcf8
commit fa338e5
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...n/java/com/limechain/network/protocol/beefy/messages/consensus/BeefyConsensusMessage.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,16 @@ | ||
package com.limechain.network.protocol.beefy.messages.consensus; | ||
|
||
import lombok.Data; | ||
|
||
import java.math.BigInteger; | ||
import java.util.List; | ||
|
||
@Data | ||
public class BeefyConsensusMessage { | ||
private BeefyConsensusMessageFormat format; | ||
private List<byte[]> authorityPublicKeys; | ||
private BigInteger authoritySetId; | ||
private BigInteger disabledAuthority; | ||
// The 32-byte Merkle Mountain Range (MMR) root payload hash. | ||
private byte[] mmrRootHash; | ||
} |
23 changes: 23 additions & 0 deletions
23
.../com/limechain/network/protocol/beefy/messages/consensus/BeefyConsensusMessageFormat.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,23 @@ | ||
package com.limechain.network.protocol.beefy.messages.consensus; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum BeefyConsensusMessageFormat { | ||
BEEFY_CHANGED_AUTHORITIES(1), BEEFY_ON_DISABLED(2), BEEFY_MMR_ROOT(3); | ||
|
||
private final int format; | ||
|
||
BeefyConsensusMessageFormat(int format) { | ||
this.format = format; | ||
} | ||
|
||
public static BeefyConsensusMessageFormat fromFormat(byte format) { | ||
for (BeefyConsensusMessageFormat messageFormat : values()) { | ||
if (messageFormat.getFormat() == format) { | ||
return messageFormat; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown beefy consensus message format: " + format); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../com/limechain/network/protocol/beefy/messages/consensus/BeefyConsensusMessageReader.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,45 @@ | ||
package com.limechain.network.protocol.beefy.messages.consensus; | ||
|
||
import io.emeraldpay.polkaj.scale.ScaleCodecReader; | ||
import io.emeraldpay.polkaj.scale.ScaleReader; | ||
import io.emeraldpay.polkaj.scale.reader.ListReader; | ||
import io.emeraldpay.polkaj.scale.reader.UInt64Reader; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class BeefyConsensusMessageReader implements ScaleReader<BeefyConsensusMessage> { | ||
|
||
private static final BeefyConsensusMessageReader INSTANCE = new BeefyConsensusMessageReader(); | ||
|
||
public static BeefyConsensusMessageReader getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public BeefyConsensusMessage read(ScaleCodecReader reader) { | ||
|
||
BeefyConsensusMessage beefyConsensusMessage = new BeefyConsensusMessage(); | ||
BeefyConsensusMessageFormat format = BeefyConsensusMessageFormat.fromFormat(reader.readByte()); | ||
beefyConsensusMessage.setFormat(format); | ||
|
||
switch (format) { | ||
case BEEFY_CHANGED_AUTHORITIES -> { | ||
List<byte[]> authorityPublicKeys = new ListReader<>( | ||
rdr -> rdr.readByteArray(33)).read(reader); | ||
beefyConsensusMessage.setAuthorityPublicKeys(authorityPublicKeys); | ||
beefyConsensusMessage.setAuthoritySetId(new UInt64Reader().read(reader)); | ||
} | ||
case BEEFY_ON_DISABLED -> { | ||
beefyConsensusMessage.setDisabledAuthority(new UInt64Reader().read(reader)); | ||
} | ||
case BEEFY_MMR_ROOT -> { | ||
beefyConsensusMessage.setMmrRootHash(reader.readUint256()); | ||
} | ||
} | ||
|
||
return beefyConsensusMessage; | ||
} | ||
} |
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