Skip to content

Commit

Permalink
rework decoding block extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
fschoell committed Jun 18, 2024
1 parent 6d20d4a commit 63cf1e9
Show file tree
Hide file tree
Showing 9 changed files with 1,059 additions and 829 deletions.
57 changes: 38 additions & 19 deletions codec/antelope/eos_to_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,38 +166,57 @@ func ExtensionsToDEOS(in []*eos.Extension) (out []*pbantelope.Extension) {
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)
}
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.BlockExtension{
Extension: &pbantelope.BlockExtension_AdditionalBlockSignatureExtension{
AdditionalBlockSignatureExtension: &pbantelope.AdditionalBlockSignatureExtensions{
Signatures: SignaturesToDEOS(additionalBlockSignatureExtension.Signatures),
Extension: &pbantelope.BlockExtension_ProtocolFeatureActivationExtension{
ProtocolFeatureActivationExtension: &pbantelope.ProtocolFeatureActivationExtension{
ProtocolFeatures: checksumsToBytesSlices(pfaExtension.FeatureDigests),
},
},
})

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)
}
case eos.EOS_ProducerScheduleChangeExtension:
pscExtension := ext.(*eos.ProducerScheduleChangeExtension)
res = append(res, &pbantelope.BlockExtension{
Extension: &pbantelope.BlockExtension_ProducerScheduleChangeExtension{
ProducerScheduleChangeExtension: &pbantelope.ProducerScheduleChangeExtension{
ProducerSchedule: ProducerAuthorityScheduleToDEOS(&eos.ProducerAuthoritySchedule{
Version: pscExtension.Version,
Producers: pscExtension.Producers,
}),
},
},
})

case eos.EOS_AdditionalBlockSignatureExtension:
absExtension := ext.(*eos.AdditionalBlockSignatureExtension)
res = append(res, &pbantelope.BlockExtension{
Extension: &pbantelope.BlockExtension_AdditionalBlockSignatureExtension{
AdditionalBlockSignatureExtension: &pbantelope.AdditionalBlockSignatureExtension{
Signatures: SignaturesToDEOS(absExtension.Signatures),
},
},
})

case eos.EOS_QuorumCertificateExtension:
qcExtension := ext.(*eos.QuorumCertificateExtension)
res = append(res, &pbantelope.BlockExtension{
Extension: &pbantelope.BlockExtension_QuorumCertificateExtension{
QuorumCertificateExtension: &pbantelope.QuorumCertificateExtension{
Qc: QuorumCertificateToDEOS(quorumCertificateExtension.QuorumCertificate),
Qc: QuorumCertificateToDEOS(qcExtension.QuorumCertificate),
},
},
})

default:
return nil, fmt.Errorf("unknown extension type: %v", extension.Type)
}
Expand All @@ -206,7 +225,7 @@ func BlockExtensionsToDEOS(in []*eos.Extension) ([]*pbantelope.BlockExtension, e
return res, nil
}

func QuorumCertificateToDEOS(qc QuorumCertificate) *pbantelope.QuorumCertificate {
func QuorumCertificateToDEOS(qc eos.QuorumCertificate) *pbantelope.QuorumCertificate {
return &pbantelope.QuorumCertificate{
BlockNum: qc.BlockNum,
Data: &pbantelope.ValidQuorumCertificate{
Expand Down
4 changes: 2 additions & 2 deletions codec/antelope/spring_v1/hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (h *Hydrator) HydrateBlock(block *pbantelope.Block, input []byte, version s
if err != nil {
return fmt.Errorf("unmarshalling block extensions (spring v2): %w", err)
}
block.BlockExtensionsV2 = parsedBlockExtensions
block.DecodedBlockExtensions = parsedBlockExtensions

block.DposIrreversibleBlocknum = blockState.DPoSIrreversibleBlockNum
block.DposProposedIrreversibleBlocknum = blockState.DPoSProposedIrreversibleBlockNum
Expand Down Expand Up @@ -103,7 +103,7 @@ func (h *Hydrator) HydrateBlock(block *pbantelope.Block, input []byte, version s
if err != nil {
return fmt.Errorf("unmarshalling block extensions (spring v2): %w", err)
}
block.BlockExtensionsV2 = parsedBlockExtensions
block.DecodedBlockExtensions = parsedBlockExtensions

block.UnfilteredTransactionCount = uint32(len(signedBlock.Transactions))
for idx, transaction := range signedBlock.Transactions {
Expand Down
20 changes: 0 additions & 20 deletions codec/antelope/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package antelope

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

"github.com/eoscanada/eos-go"
Expand Down Expand Up @@ -112,22 +111,3 @@ 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"`
}
19 changes: 19 additions & 0 deletions codec/antelope/types_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package antelope

import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/eoscanada/eos-go"
"testing"
"unicode/utf8"

Expand Down Expand Up @@ -44,3 +48,18 @@ func TestLimitConsoleLengthConversionOption(t *testing.T) {
})
}
}

func TestBlockExtensionsToDEOS(t *testing.T) {

qcBytes, err := hex.DecodeString("af2d12000115fffb1f00c001999edd942be650f36390b24240a943850ea5afbb4dd5e246320a2569eca245b489b600cf12529bd4f313e8d9f3fe9812910e0ed0092e214dd1042d4caf10fc4ed261a854482bc2a46e32999ef69f07eb8c791a72a6f848cfea9c98f1a72ed500b8c513b133d6cc5efb990b212968e69442d2e063473ad32f9407b978098c18b40aa6ef7fa68dd9b679c16052943e4e0a3f81887c4513ba45e9484b37f4d86b919e401ab6f9d2da679c285f7724f9fdf0a640ac2d9b814a722ccab0943c181a07")
assert.NoError(t, err)

res := &eos.QuorumCertificateExtension{}
err = eos.NewDecoder(qcBytes).Decode(res)
assert.NoError(t, err)

fmt.Println(res.QuorumCertificate.ValidQuorumCertificate.BlsAggregateSignature.String())

resJson, _ := json.Marshal(&res)
fmt.Println(string(resJson))
}
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ require (
github.com/chzyer/readline v1.5.1 // indirect
github.com/cilium/ebpf v0.9.1 // indirect
github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 // indirect
Expand Down Expand Up @@ -127,6 +129,7 @@ require (
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mostynb/go-grpc-compression v1.2.3 // indirect
Expand Down Expand Up @@ -224,6 +227,7 @@ require (
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
lukechampine.com/blake3 v1.1.7 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
Expand All @@ -235,3 +239,5 @@ replace (
github.com/graph-gophers/graphql-go => github.com/streamingfast/graphql-go v0.0.0-20210204202750-0e485a040a3c
github.com/jhump/protoreflect => github.com/streamingfast/protoreflect v0.0.0-20231205191344-4b629d20ce8d
)

replace github.com/eoscanada/eos-go => github.com/pinax-network/eos-go v0.0.0-20240613115143-71a2bb038d07
16 changes: 14 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50 h1:DBmgJDC9dTfkVyGgipamEh2BpGYxScCH1TOF1LL1cXc=
github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50/go.mod h1:5e1+Vvlzido69INQaVO6d87Qn543Xr6nooe9Kz7oBFM=
github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ=
github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJF7HpyG8M=
github.com/consensys/gnark-crypto v0.12.1/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY=
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
Expand Down Expand Up @@ -223,8 +227,6 @@ github.com/envoyproxy/go-control-plane v0.12.0/go.mod h1:ZBTaoJ23lqITozF0M6G4/Ir
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
github.com/eoscanada/eos-go v0.10.3-0.20231109144819-59afdfa3a37d h1:vK5PijzcJaUPOhgWvY9lL99H9t3lrRNHx2IDHqS0ILc=
github.com/eoscanada/eos-go v0.10.3-0.20231109144819-59afdfa3a37d/go.mod h1:L3avCf8OkDrjlUeNy9DdoV67TCmDNj2dSlc5Xp3DNNk=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
Expand Down Expand Up @@ -355,6 +357,7 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o=
github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw=
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand Down Expand Up @@ -437,6 +440,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8=
github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg=
github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM=
Expand Down Expand Up @@ -478,6 +483,9 @@ github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJ
github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY=
github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU=
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -527,6 +535,8 @@ github.com/paulbellamy/ratecounter v0.2.0/go.mod h1:Hfx1hDpSGoqxkVVpBi/IlYD7kChl
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pinax-network/eos-go v0.0.0-20240613115143-71a2bb038d07 h1:FvZJ992WCrv9lWPqwpgmWI0EdV91zGjzfisM2QZi7f0=
github.com/pinax-network/eos-go v0.0.0-20240613115143-71a2bb038d07/go.mod h1:Wqe3BDXKvJ2tNIQ0UQyzhTaneP85GgLp6IqOSNXfn2Q=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -1220,6 +1230,8 @@ lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU=
rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=
Expand Down
18 changes: 14 additions & 4 deletions proto/sf/antelope/type/v1/type.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ message Block {
string producer_signature = 5;
repeated Extension block_extensions = 7;

repeated BlockExtension block_extensions_v2 = 63;
repeated BlockExtension decoded_block_extensions = 63;

uint32 dpos_proposed_irreversible_blocknum = 8;
uint32 dpos_irreversible_blocknum = 9;
Expand Down Expand Up @@ -240,12 +240,22 @@ message FinalizerAuthority {

message BlockExtension {
oneof extension {
AdditionalBlockSignatureExtensions additional_block_signature_extension = 1;
QuorumCertificateExtension quorum_certificate_extension = 2;
ProtocolFeatureActivationExtension protocol_feature_activation_extension = 1;
ProducerScheduleChangeExtension producer_schedule_change_extension = 2;
AdditionalBlockSignatureExtension additional_block_signature_extension = 3;
QuorumCertificateExtension quorum_certificate_extension = 4;
}
}

message AdditionalBlockSignatureExtensions {
message ProtocolFeatureActivationExtension {
repeated bytes protocol_features = 1;
}

message ProducerScheduleChangeExtension {
ProducerAuthoritySchedule producer_schedule = 1;
}

message AdditionalBlockSignatureExtension {
repeated string signatures = 1;
}

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 10:13:42 CEST 2024 - work
streamingfast/firehose-antelope/proto revision: a30acda
generate.sh - Thu Jun 13 13:51:04 CEST 2024 - work
streamingfast/firehose-antelope/proto revision: 94e461c
Loading

0 comments on commit 63cf1e9

Please sign in to comment.