Skip to content

Commit

Permalink
add parser for block extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
fschoell committed Jun 13, 2024
1 parent 274aa14 commit 94e461c
Show file tree
Hide file tree
Showing 7 changed files with 2,405 additions and 1,859 deletions.
61 changes: 61 additions & 0 deletions codec/antelope/eos_to_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)

type BlockExtensionId uint16

const (
AdditionalBlockSignatureExtensionsId BlockExtensionId = 2
QuorumCertificateExtensionId BlockExtensionId = 3
)

func ActivatedProtocolFeaturesToDEOS(in *eos.ProtocolFeatureActivationSet) *pbantelope.ActivatedProtocolFeatures {
out := &pbantelope.ActivatedProtocolFeatures{}
out.ProtocolFeatures = checksumsToBytesSlices(in.ProtocolFeatures)
Expand Down Expand Up @@ -156,6 +163,60 @@ func ExtensionsToDEOS(in []*eos.Extension) (out []*pbantelope.Extension) {
return
}

func BlockExtensionsToDEOS(in []*eos.Extension) ([]*pbantelope.BlockExtension, error) {

res := make([]*pbantelope.BlockExtension, 0, len(in))

for _, extension := range in {
switch extension.Type {
case uint16(AdditionalBlockSignatureExtensionsId):
additionalBlockSignatureExtension := &AdditionalBlockSignatureExtension{}
err := eos.NewDecoder(extension.Data).Decode(additionalBlockSignatureExtension)
if err != nil {
return nil, fmt.Errorf("failed to decode additional block signature extension: %w", err)
}

res = append(res, &pbantelope.BlockExtension{
Extension: &pbantelope.BlockExtension_AdditionalBlockSignatureExtension{
AdditionalBlockSignatureExtension: &pbantelope.AdditionalBlockSignatureExtensions{
Signatures: SignaturesToDEOS(additionalBlockSignatureExtension.Signatures),
},
},
})

case uint16(QuorumCertificateExtensionId):
quorumCertificateExtension := &QuorumCertificateExtension{}
err := eos.NewDecoder(extension.Data).Decode(quorumCertificateExtension)
if err != nil {
return nil, fmt.Errorf("failed to decode quorum certificate extension: %w", err)
}

res = append(res, &pbantelope.BlockExtension{
Extension: &pbantelope.BlockExtension_QuorumCertificateExtension{
QuorumCertificateExtension: &pbantelope.QuorumCertificateExtension{
Qc: QuorumCertificateToDEOS(quorumCertificateExtension.QuorumCertificate),
},
},
})
default:
return nil, fmt.Errorf("unknown extension type: %v", extension.Type)
}
}

return res, nil
}

func QuorumCertificateToDEOS(qc QuorumCertificate) *pbantelope.QuorumCertificate {
return &pbantelope.QuorumCertificate{
BlockNum: qc.BlockNum,
Data: &pbantelope.ValidQuorumCertificate{
StrongVotes: qc.ValidQuorumCertificate.StrongVotes,
WeakVotes: qc.ValidQuorumCertificate.WeakVotes,
BlsAggregateSignature: qc.ValidQuorumCertificate.BlsAggregateSignature.String(),
},
}
}

func ProducerAuthoritiesToDEOS(producerAuthorities []*eos.ProducerAuthority) (out []*pbantelope.ProducerAuthority) {
if len(producerAuthorities) <= 0 {
return nil
Expand Down
12 changes: 11 additions & 1 deletion codec/antelope/spring_v1/hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func (h *Hydrator) HydrateBlock(block *pbantelope.Block, input []byte, version s
block.Version = 2
block.Header = antelope.BlockHeaderToDEOS(&signedBlock.BlockHeader)
block.BlockExtensions = antelope.ExtensionsToDEOS(signedBlock.BlockExtensions)
parsedBlockExtensions, err := antelope.BlockExtensionsToDEOS(signedBlock.BlockExtensions)
if err != nil {
return fmt.Errorf("unmarshalling block extensions (spring v2): %w", err)
}
block.BlockExtensionsV2 = parsedBlockExtensions

block.DposIrreversibleBlocknum = blockState.DPoSIrreversibleBlockNum
block.DposProposedIrreversibleBlocknum = blockState.DPoSProposedIrreversibleBlockNum
block.BlockrootMerkle = antelope.BlockrootMerkleToDEOS(blockState.BlockrootMerkle)
Expand Down Expand Up @@ -93,7 +99,11 @@ func (h *Hydrator) HydrateBlock(block *pbantelope.Block, input []byte, version s
block.Version = 2
block.Header = antelope.BlockHeaderToDEOS(&signedBlock.BlockHeader)
block.BlockExtensions = antelope.ExtensionsToDEOS(signedBlock.BlockExtensions)
block.ProducerSignature = signedBlock.ProducerSignature.String()
parsedBlockExtensions, err := antelope.BlockExtensionsToDEOS(signedBlock.BlockExtensions)
if err != nil {
return fmt.Errorf("unmarshalling block extensions (spring v2): %w", err)
}
block.BlockExtensionsV2 = parsedBlockExtensions

block.UnfilteredTransactionCount = uint32(len(signedBlock.Transactions))
for idx, transaction := range signedBlock.Transactions {
Expand Down
2 changes: 1 addition & 1 deletion codec/antelope/spring_v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type FinalityData struct {
FinalOnStrongQCBlockNum uint32 `json:"final_on_strong_qc_block_num"`
ActionMroot eos.Checksum256 `json:"action_mroot"`
BaseDigest eos.Checksum256 `json:"base_digest"`
ProposedFinalizerPolicy *FinalizerPolicy `json:"proposed_finalizer_policy" eos:"optional"`
ProposedFinalizerPolicy *FinalizerPolicy `json:"proposed_finalizer_policy,omitempty" eos:"optional"`
}

type FinalizerPolicy struct {
Expand Down
20 changes: 20 additions & 0 deletions codec/antelope/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package antelope

import (
"github.com/eoscanada/eos-go/ecc"
"unicode/utf8"

"github.com/eoscanada/eos-go"
Expand Down Expand Up @@ -111,3 +112,22 @@ func GetPublicKeysFromSignedTransaction(chainID eos.Checksum256, signedTransacti

return publicKeys
}

type AdditionalBlockSignatureExtension struct {
Signatures []ecc.Signature `json:"signatures"`
}

type QuorumCertificateExtension struct {
QuorumCertificate QuorumCertificate `json:"qc"`
}

type QuorumCertificate struct {
BlockNum uint32 `json:"block_num"`
ValidQuorumCertificate ValidQuorumCertificate `json:"data"`
}

type ValidQuorumCertificate struct {
StrongVotes []uint8 `json:"strong_votes" eos:"optional"`
WeakVotes []uint8 `json:"weak_votes" eos:"optional"`
BlsAggregateSignature ecc.Signature `json:"bls_aggregate_signature"`
}
33 changes: 31 additions & 2 deletions proto/sf/antelope/type/v1/type.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ message Block {
BlockHeader header = 4;
string producer_signature = 5;
repeated Extension block_extensions = 7;

repeated BlockExtension block_extensions_v2 = 63;

uint32 dpos_proposed_irreversible_blocknum = 8;
uint32 dpos_irreversible_blocknum = 9;
BlockRootMerkle blockroot_merkle = 11;
Expand All @@ -45,11 +48,10 @@ message Block {
// needs to be converted from Legacy merkle to Savanna merkle
bytes action_mroot_savanna = 60;

// from Spring v1 this field will contain the lib block number in favour of the dpos_proposed_irreversible_blocknum
// the LIB post-Savanna activation, pre-Savanna this is found in dpos_irreversible_blocknum
uint32 finality_lib = 61;
FinalityData finality_data = 62;


repeated RlimitOp rlimit_ops = 19;

// The unfiltered transactions in this block when NO filtering has been applied,
Expand Down Expand Up @@ -155,6 +157,7 @@ message Block {

// This was a single string element representing a public key (eos-go#ecc.PublicKey).
// It has been replaced by `valid_block_signing_authority_v2`.
// deprecated
string block_signing_key = 14;

// This was a list of `{name, publicKey}` elements, each block being signed by a single key,
Expand Down Expand Up @@ -235,6 +238,32 @@ message FinalizerAuthority {
string public_key = 3;
}

message BlockExtension {
oneof extension {
AdditionalBlockSignatureExtensions additional_block_signature_extension = 1;
QuorumCertificateExtension quorum_certificate_extension = 2;
}
}

message AdditionalBlockSignatureExtensions {
repeated string signatures = 1;
}

message QuorumCertificateExtension {
QuorumCertificate qc = 1;
}

message QuorumCertificate {
uint32 block_num = 1;
ValidQuorumCertificate data = 2;
}

message ValidQuorumCertificate {
bytes strong_votes = 1;
bytes weak_votes = 2;
string bls_aggregate_signature = 3;
}

// BlockWithRefs is a lightweight block, with traces and transactions
// purged from the `block` within, and only. It is used in transports
// to pass block data around.
Expand Down
4 changes: 2 additions & 2 deletions types/pb/last_generate.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
generate.sh - Mon Jun 10 15:55:20 CEST 2024 - work
streamingfast/firehose-antelope/proto revision: 7513564
generate.sh - Thu Jun 13 10:13:42 CEST 2024 - work
streamingfast/firehose-antelope/proto revision: a30acda
Loading

0 comments on commit 94e461c

Please sign in to comment.