Skip to content

Commit

Permalink
add proposer_policy, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fschoell committed Jul 14, 2024
1 parent d17fc1e commit 0d4658e
Show file tree
Hide file tree
Showing 8 changed files with 1,986 additions and 2,252 deletions.
61 changes: 0 additions & 61 deletions codec/antelope/eos_to_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ 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 @@ -163,60 +156,6 @@ func ExtensionsToDEOS(in []*eos.Extension) (out []*pbantelope.Extension) {
return
}

func BlockHeaderExtensionsToDEOS(in []*eos.Extension) ([]*pbantelope.BlockHeaderExtension, error) {

res := make([]*pbantelope.BlockHeaderExtension, 0, len(in))
for _, extension := range in {

ext, err := extension.AsBlockHeaderExtension("EOS")
if err != nil {
return nil, fmt.Errorf("unable to convert to block header extension: %w", err)
}

switch ext.TypeID() {

case eos.EOS_ProtocolFeatureActivation:
pfaExtension := ext.(*eos.ProtocolFeatureActivationExtension)
res = append(res, &pbantelope.BlockHeaderExtension{
Extension: &pbantelope.BlockHeaderExtension_ProtocolFeatureActivationExtension{
ProtocolFeatureActivationExtension: &pbantelope.ProtocolFeatureActivationExtension{
ProtocolFeatures: checksumsToBytesSlices(pfaExtension.FeatureDigests),
},
},
})

case eos.EOS_ProducerScheduleChangeExtension:
pscExtension := ext.(*eos.ProducerScheduleChangeExtension)
res = append(res, &pbantelope.BlockHeaderExtension{
Extension: &pbantelope.BlockHeaderExtension_ProducerScheduleChangeExtension{
ProducerScheduleChangeExtension: &pbantelope.ProducerScheduleChangeExtension{
ProducerSchedule: ProducerAuthorityScheduleToDEOS(&eos.ProducerAuthoritySchedule{
Version: pscExtension.Version,
Producers: pscExtension.Producers,
}),
},
},
})

default:
return nil, fmt.Errorf("unknown extension type: %v", extension.Type)
}
}

return res, nil
}

//func QuorumCertificateToDEOS(qc eos.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
7 changes: 7 additions & 0 deletions codec/antelope/spring_v1/eos_to_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,10 @@ func FinalityDataToDEOS(in *FinalityData) *pbantelope.FinalityData {

return res
}

func ProposerPolicyToDEOS(in *ProposerPolicy) *pbantelope.ProposerPolicy {
return &pbantelope.ProposerPolicy{
ActiveTime: timestamppb.New(in.ActiveTime.Time),
ProposerSchedule: antelope.ProducerAuthorityScheduleToDEOS(in.ProducerSchedule),
}
}
24 changes: 10 additions & 14 deletions codec/antelope/spring_v1/hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ func (h *Hydrator) HydrateBlock(block *pbantelope.Block, input []byte, version s
block.Header = antelope.BlockHeaderToDEOS(&signedBlock.BlockHeader)
block.BlockExtensions = antelope.ExtensionsToDEOS(signedBlock.BlockExtensions)

decodedBlockHeaderExtensions, err := antelope.BlockHeaderExtensionsToDEOS(signedBlock.BlockHeader.HeaderExtensions)
if err != nil {
h.logger.Debug("failed to decode block header extensions", zap.Error(err))
} else {
block.Header.DecodedHeaderExtensions = decodedBlockHeaderExtensions
}

block.DposIrreversibleBlocknum = blockState.DPoSIrreversibleBlockNum
block.DposProposedIrreversibleBlocknum = blockState.DPoSProposedIrreversibleBlockNum
block.BlockrootMerkle = antelope.BlockrootMerkleToDEOS(blockState.BlockrootMerkle)
Expand Down Expand Up @@ -102,13 +95,6 @@ func (h *Hydrator) HydrateBlock(block *pbantelope.Block, input []byte, version s
block.Header = antelope.BlockHeaderToDEOS(&signedBlock.BlockHeader)
block.BlockExtensions = antelope.ExtensionsToDEOS(signedBlock.BlockExtensions)

decodedBlockHeaderExtensions, err := antelope.BlockHeaderExtensionsToDEOS(signedBlock.BlockHeader.HeaderExtensions)
if err != nil {
h.logger.Debug("failed to decode block header extensions", zap.Error(err))
} else {
block.Header.DecodedHeaderExtensions = decodedBlockHeaderExtensions
}

block.UnfilteredTransactionCount = uint32(len(signedBlock.Transactions))
for idx, transaction := range signedBlock.Transactions {
deosTransaction := TransactionReceiptToDEOS(transaction)
Expand Down Expand Up @@ -157,6 +143,16 @@ func (h *Hydrator) DecodeFinalityData(input []byte) (*pbantelope.FinalityData, e
return FinalityDataToDEOS(finalityData), nil
}

func (h *Hydrator) DecodeProposerPolicy(input []byte) (*pbantelope.ProposerPolicy, error) {

proposerPolicy := &ProposerPolicy{}
if err := unmarshalBinary(input, proposerPolicy); err != nil {
return nil, fmt.Errorf("unmarshalling binary proposer policy: %w", err)
}

return ProposerPolicyToDEOS(proposerPolicy), nil
}

func unmarshalBinary(data []byte, v interface{}) error {
decoder := eos.NewDecoder(data)
decoder.DecodeActions(false)
Expand Down
5 changes: 5 additions & 0 deletions codec/antelope/spring_v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ type FinalizerAuthority struct {
PublicKey string `json:"public_key"`
}

type ProposerPolicy struct {
ActiveTime eos.BlockTimestamp `json:"active_time"`
ProducerSchedule *eos.ProducerAuthoritySchedule `json:"proposer_schedule"`
}

// TransactionTrace
//
// File hierarchy:
Expand Down
8 changes: 4 additions & 4 deletions codec/consolereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,11 @@ func (ctx *parseCtx) readAcceptedBlock(line string) (*pbantelope.Block, error) {

// Line format:
//
// ACCEPTED_BLOCK_V2 ${block_id} ${block_num} ${lib} ${block_state_hex} ${finality_data_hex}
// ACCEPTED_BLOCK_V2 ${block_id} ${block_num} ${lib} ${blk} ${finality_data_hex} ${proposer_policy} ${finalizer_policy_with_string_key}
func (ctx *parseCtx) readAcceptedBlockV2(line string) (*pbantelope.Block, error) {
chunks := strings.SplitN(line, " ", 6)
if len(chunks) != 6 {
return nil, fmt.Errorf("expected 6 fields, got %d", len(chunks))
chunks := strings.SplitN(line, " ", 8)
if len(chunks) != 8 {
return nil, fmt.Errorf("expected 8 fields, got %d", len(chunks))
}

blockNum, err := strconv.ParseInt(chunks[2], 10, 64)
Expand Down
29 changes: 7 additions & 22 deletions proto/sf/antelope/type/v1/type.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ message Block {
string producer_signature = 5;
repeated Extension block_extensions = 7;

// repeated BlockExtension decoded_block_extensions = 63;

uint32 dpos_proposed_irreversible_blocknum = 8;
uint32 dpos_irreversible_blocknum = 9;
BlockRootMerkle blockroot_merkle = 11;
Expand All @@ -51,6 +49,7 @@ message Block {
// the LIB post-Savanna activation, pre-Savanna this is found in dpos_irreversible_blocknum
uint32 finality_lib = 61;
FinalityData finality_data = 62;
ProposerPolicy proposer_policy = 63;

repeated RlimitOp rlimit_ops = 19;

Expand Down Expand Up @@ -179,7 +178,7 @@ message Block {
// See BlockSigningAuthority for further details
BlockSigningAuthority valid_block_signing_authority_v2 = 30;

// This repleaces the old type `ProducerSchedule` for the `active_schedule`
// This replaces the old type `ProducerSchedule` for the `active_schedule`
// field. This was only a type change in EOSIO 2.0, the field's name remained
// the same.
//
Expand Down Expand Up @@ -238,25 +237,6 @@ message FinalizerAuthority {
string public_key = 3;
}

message AdditionalBlockSignatureExtension {
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 Expand Up @@ -320,6 +300,11 @@ message ProducerAuthority {
BlockSigningAuthority block_signing_authority = 2;
}

message ProposerPolicy {
google.protobuf.Timestamp active_time = 1;
ProducerAuthoritySchedule proposer_schedule = 2;
}

// Present in EOSIO 2.x only
//
// This represents the signatures that were used to signed the block. Previously,
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 - Thu Jun 13 15:55:26 CEST 2024 - work
streamingfast/firehose-antelope/proto revision: a391939
generate.sh - Sun Jul 14 17:31:31 CEST 2024 - work
streamingfast/firehose-antelope/proto revision: ae61561
Loading

0 comments on commit 0d4658e

Please sign in to comment.