Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Antelope Spring #143

Merged
merged 25 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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
4 changes: 3 additions & 1 deletion codec/antelope/hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import "github.com/pinax-network/firehose-antelope/types/pb/sf/antelope/type/v1"
type Hydrator interface {
// HydrateBlock decodes the received Deep Mind AcceptedBlock data structure against the
// correct struct for this version of EOSIO supported by this hydrator.
HydrateBlock(block *pbantelope.Block, input []byte) error
HydrateBlock(block *pbantelope.Block, input []byte, version string) error

// DecodeTransactionTrace decodes the received Deep Mind AppliedTransaction data structure against the
// correct struct for this version of EOSIO supported by this hydrator.
DecodeTransactionTrace(input []byte, opts ...ConversionOption) (*pbantelope.TransactionTrace, error)

DecodeFinalityData(input []byte) (*pbantelope.FinalityData, error)
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,35 @@ func SignaturesToDEOS(in []ecc.Signature) (out []string) {
}
return
}

func FinalityDataToDEOS(in *FinalityData) *pbantelope.FinalityData {

res := &pbantelope.FinalityData{
MajorVersion: in.MajorVersion,
MinorVersion: in.MinorVersion,
ActiveFinalizerPolicyGeneration: in.ActiveFinalizerPolicyGeneration,
FinalOnStrongQcBlockNum: in.FinalOnStrongQCBlockNum,
ActionMroot: in.ActionMroot,
BaseDigest: in.BaseDigest,
}

if in.ProposedFinalizerPolicy != nil {
finalizerPolicy := &pbantelope.FinalizerPolicy{
Generation: in.ProposedFinalizerPolicy.Generation,
Threshold: in.ProposedFinalizerPolicy.Threshold,
Finalizers: nil,
}

finalizers := make([]*pbantelope.FinalizerAuthority, 0, len(finalizerPolicy.Finalizers))
for _, finalizer := range finalizerPolicy.Finalizers {
finalizers = append(finalizers, &pbantelope.FinalizerAuthority{
Description: finalizer.Description,
Weight: finalizer.Weight,
PublicKey: finalizer.PublicKey,
})
}
finalizerPolicy.Finalizers = finalizers
}

return res
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package antelope

import (
"errors"
"fmt"
"github.com/pinax-network/firehose-antelope/codec/antelope"

Expand All @@ -11,21 +12,25 @@ import (

func NewHydrator(parentLogger *zap.Logger) *Hydrator {
return &Hydrator{
logger: parentLogger.With(zap.String("antelope", "3.1.x")),
logger: parentLogger.With(zap.String("antelope", "leap v5")),
}
}

type Hydrator struct {
logger *zap.Logger
}

func (h *Hydrator) HydrateBlock(block *pbantelope.Block, input []byte) error {
h.logger.Debug("hydrating block from bytes")
func (h *Hydrator) HydrateBlock(block *pbantelope.Block, input []byte, version string) error {
h.logger.Debug("hydrating block from bytes", zap.String("version", version))

if version != "v1" {
return fmt.Errorf("unsupported version: %s", version)
}

blockState := &BlockState{}
err := unmarshalBinary(input, blockState)
if err != nil {
return fmt.Errorf("unmarshalling binary block state (3.1.x): %w", err)
return fmt.Errorf("unmarshalling binary block state (leap v5): %w", err)
}

signedBlock := blockState.SignedBlock
Expand Down Expand Up @@ -93,6 +98,10 @@ func (h *Hydrator) DecodeTransactionTrace(input []byte, opts ...antelope.Convers
return TransactionTraceToDEOS(h.logger, trxTrace, opts...), nil
}

func (h *Hydrator) DecodeFinalityData(input []byte) (*pbantelope.FinalityData, error) {
return nil, errors.New("finality not supported in pre spring versions")
}

func unmarshalBinary(data []byte, v interface{}) error {
decoder := eos.NewDecoder(data)
decoder.DecodeActions(false)
Expand Down
27 changes: 27 additions & 0 deletions codec/antelope/v3.1/types.go → codec/antelope/leap_v5/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ type SignedBlock struct {
BlockExtensions []*eos.Extension `json:"block_extensions"`
}

// FinalityData
//
// File hierarchy:
//
// - https://github.com/AntelopeIO/spring/blob/main/libraries/chain/include/eosio/chain/block_state.hpp#L61
type FinalityData struct {
MajorVersion uint32 `json:"major_version"`
MinorVersion uint32 `json:"minor_version"`
ActiveFinalizerPolicyGeneration uint32 `json:"active_finalizer_policy_generation"`
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"`
}

type FinalizerPolicy struct {
Generation uint32 `json:"generation"`
Threshold uint64 `json:"threshold"`
Finalizers []*FinalizerAuthority `json:"finalizers"`
}

type FinalizerAuthority struct {
Description string `json:"description"`
Weight uint64 `json:"weight"`
PublicKey string `json:"public_key"`
}

// TransactionTrace
//
// File hierarchy:
Expand Down
File renamed without changes.
Loading
Loading