-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
BEEFY consensus message scale classes #786
Changes from 1 commit
fa338e5
43d58b6
e37302d
7528398
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} |
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); | ||
} | ||
} |
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; | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each digest is added separately in the header. This means we can have more than one digest per type. With the current implementation we use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you create a constant for that 33, it feels like a magic number right now.