Skip to content

Commit

Permalink
update legacy block format
Browse files Browse the repository at this point in the history
  • Loading branch information
fschoell committed Jun 10, 2024
1 parent f4c088a commit bea5885
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion codec/antelope/spring_v1/hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (h *Hydrator) HydrateBlock(block *pbantelope.Block, input []byte, version s
block.Number = blockState.BlockNum
// Version 1: Added the total counts (ExecutedInputActionCount, ExecutedTotalActionCount,
// TransactionCount, TransactionTraceCount)
block.Version = 1
block.Version = 2
block.Header = antelope.BlockHeaderToDEOS(&signedBlock.BlockHeader)
block.BlockExtensions = antelope.ExtensionsToDEOS(signedBlock.BlockExtensions)
block.DposIrreversibleBlocknum = blockState.DPoSIrreversibleBlockNum
Expand Down
8 changes: 4 additions & 4 deletions codec/antelope/spring_v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ type LegacyBlockState struct {
// From 'struct block_header_state_legacy'
BlockID eos.Checksum256 `json:"id"`
Header *eos.SignedBlockHeader `json:"header,omitempty"`
ActivatedProtocolFeatures *eos.ProtocolFeatureActivationSet `json:"activated_protocol_features,omitempty" eos:"optional"`
PendingSchedule *eos.PendingSchedule `json:"pending_schedule"`
ActivatedProtocolFeatures *eos.ProtocolFeatureActivationSet `json:"activated_protocol_features,omitempty"`
AdditionalSignatures []ecc.Signature `json:"additional_signatures"`

SignedBlock *SignedBlock `json:"block,omitempty" eos:"optional"`
SignedBlock *SignedBlock `json:"block,omitempty"`
Validated bool `json:"validated"`
ActionMrootSavanna eos.Checksum256 `json:"action_mroot_savanna,omitempty" eos:"optional"`
}
Expand All @@ -51,8 +51,8 @@ type FinalityData struct {
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"`
ActionMroot eos.Checksum160 `json:"action_mroot"`
BaseDigest eos.Checksum160 `json:"base_digest"`
ProposedFinalizerPolicy *FinalizerPolicy `json:"proposed_finalizer_policy" eos:"optional"`
}

Expand Down
40 changes: 27 additions & 13 deletions codec/antelope/spring_v1/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,39 @@ package antelope

import (
"encoding/hex"
"encoding/json"
"fmt"
"strings"
pbantelope "github.com/pinax-network/firehose-antelope/types/pb/sf/antelope/type/v1"
"github.com/streamingfast/logging"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/require"
)

func TestFinalityDataDecoding(t *testing.T) {
bytes, err := hex.DecodeString(strings.ReplaceAll(finalityDataInput1, "\n", ""))
require.NoError(t, err)
//func TestFinalityDataDecoding(t *testing.T) {
// bytes, err := hex.DecodeString(strings.ReplaceAll(finalityDataInput1, "\n", ""))
// require.NoError(t, err)
//
// finalityData := &FinalityData{}
// require.NoError(t, unmarshalBinary(bytes, finalityData), err)
//
// finalityJson, err := json.Marshal(finalityData)
// require.NoError(t, err)
//
// fmt.Println(string(finalityJson))
//}

func TestDecodeAcceptedBlockV1(t *testing.T) {

finalityData := &FinalityData{}
require.NoError(t, unmarshalBinary(bytes, finalityData), err)
zlog := logging.NewTestLogger(t)

finalityJson, err := json.Marshal(finalityData)
require.NoError(t, err)
hydrator := NewHydrator(zlog.Instance())
block := &pbantelope.Block{}

fmt.Println(string(finalityJson))
data, err := hex.DecodeString(blockDataInput1)
assert.NoError(t, err)

err = hydrator.HydrateBlock(block, data, "v1")
assert.NoError(t, err)
}

var blockDataInput1 = `e11a0000441a00009c190000020000001500af49aae5e9b2390001000000010002e65e41cb9ee12e23af44d32c337788253765eee9cd5c5b39900bf22e6d39dab1010050956a785eda983b00010000000100028d316c09c917eecbd8da03a695029a63dc3a4294c75c254af7d00078709b11070100708d3ad7445a993b0001000000010002fc35aa95c03e0e75553f2dc670e476e7cbceb0bd9962dd637629e307e63663360100e0159c545eb5554400010000000100027488fb8ad5080f9ff609501b1b392858061e9cc4d7a7e98f8c1dcfb076c613ab01007055c6d2343fa75e00010000000100032aeec24bd317fffed0cd787efaf3cd8b7454fcf1dc3be8d4d6b0d6d337282eca01007015a7d5c4e82e650001000000010003de2988ea5bf8c7d01283f127e9f7a9b3d40fb95a618e78975e210995fcfbff49010080b53499565aab6b000100000001000383a91696b1538d01f80a7ffabc105aa4eb0a2e69798585c07112e37f2c982e760100c0684a91facba66e00010000000100030865d02cc3433ac84a94f3834ca39e0cc54446ab3da13e29d3cfc2cc9341c8d501008055cc5767055d740001000000010002f19818348f231392e0e77ee0d30424f16f213fa44d143efb0944a9e698e6d1c401008019bd8b4d57a57e00010000000100037fbdb976fea057a5cbb6cb72229f02f36c02635e98ee4ccf555b4c34cc8fbf380100a0229bfa4d37a98b0001000000010002e90bbadddf5f7e944c2abb3b93560d6617da4ff8e98a2f3f995b809d84cddf97010090dd39e6aa98b38b00010000000100029d65a2751be09a3dcd5df1ed634c13fb11c4a9e31f726a4435d74b9f75c63dd60100701573f92ae672a300010000000100038b9c2183652437df1294edc1654a7fc3885e9ff849678be67ce79082a566b36401007055c694dea4e9ad00010000000100027c30a8443026f4c518fb1659aa6e41f15a21b44c075cd98e88e0939ece61d9060100802f8d144ddab2af0001000000010003d09cdc55b989bf3c1b728dc39f049fffe1eb88376b5eeee7ab3ee9fbf382cb260100a022338a4d770dc50001000000010002f19e790aaf9335cf1ab21a32aa986e4c30ec1360f8e69e2e39ea28af606813df0100701437935e955cc50001000000010002c004a5f66932f3bdc28029071b982c23ab78ed17018bbeec277b9cb8e2d507540100a0a09918638c31c60001000000010003d322a86189958f2ac52029908b02b8c0ae2262eae21d44b3c1c29ad1e4cb018f0100a0a2695ce97854cb0001000000010002d5d8e44856678a456b05e0359b8925bc4cda9191fd71b95a3550764c51ed3bc801001039cd53458755cb00010000000100039579e7254e9dc8f4be4e91f4faced3861e2cae56163bee1cdc0ab302ecc7c9da0100a0f0a5cdb71c8de200010000000100026be42a9296f30dd30f72c714591a7ced3b8307ac575f0353848b2643c5999061010007d2f5bea301ce5d9b661bfacfac566e7a1abcf731b823dcd45d51e3dc80dea6d573ccb6a36460260df67bbc3e8cd925a7bcd653192a4969d38c3dcae676a4b1f554593c8adc631e9be2eb39fffa42f321dafd951df40d9bdc956b18a7dbdaf74af3176f3dba642d799c14f4aa21452a015c660e567701ce68c4b2abd11e2223847e878fd7b5381f7626b6581c8c5ad7e69a69a760bafbaae8c80cd27b204a51bff289f7c2bfd3af6198d62bbc1a37eddd5ce227ae60608842b3e75e23c638ca3b6ed4d170c3a2ea0904758c4df0761f9945f011baf921e64975e5362ef220f17ae01a0000000000001600af49aae5e9b2398c1a000050956a785eda983b981a0000708d3ad7445a993ba41a0000e0159c545eb55544b01a00007055c6d2343fa75ebc1a00007015a7d5c4e82e65c81a000080b53499565aab6bd41a0000c0684a91facba66ee01a00008055cc5767055d74e11a00008019bd8b4d57a57efc1900000000a8c7a8c8a67e74020000a0229bfa4d37a98b081a000090dd39e6aa98b38b141a0000701573f92ae672a3201a00007055c694dea4e9ad2c1a0000802f8d144ddab2af381a0000a022338a4d770dc5441a0000701437935e955cc5501a0000a0a09918638c31c65c1a0000a0a2695ce97854cb681a00001039cd53458755cb741a0000a0f0a5cdb71c8de2801a00001500af49aae5e9b239e419000050956a785eda983bf0190000708d3ad7445a993bfc190000e0159c545eb55544081a00007055c6d2343fa75e141a00007015a7d5c4e82e65201a000080b53499565aab6b2c1a0000c0684a91facba66e381a00008055cc5767055d74381a00008019bd8b4d57a57e54190000a0229bfa4d37a98b6019000090dd39e6aa98b38b6c190000701573f92ae672a3781900007055c694dea4e9ad84190000802f8d144ddab2af90190000a022338a4d770dc59c190000701437935e955cc5a8190000a0a09918638c31c6b4190000a0a2695ce97854cbc01900001039cd53458755cbcc190000a0f0a5cdb71c8de2d81900000001000000010002f19818348f231392e0e77ee0d30424f16f213fa44d143efb0944a9e698e6d1c401009d010101010101010101010101010202020202020202020202020303030303030303030303030404040404040404040404040505050505050505050505050606060606060606060606060707070707070707070707070808080808080808080808080909090909090909090909090a0a0a0a0a0a0a0a0a0a0a0a0b0b0b0b0b0b0b0b0b0b0b0b0c0c0c0c0c0c0c0c0c0c0c0c0d0d0d0d0d0d0d0d0d0d0d0d0e00001ae16b06b22691ded60159bc0519c9615d5967e66ed5aebd335f50ed80467cc0e85b8055cc5767055d74f00000001ae0a93b63afbaffe8c893e2cb74765904171ad547b454f0f405b656b1220000000000000000000000000000000000000000000000000000000000000000f219ff05b60b17239b8a9ab4e604788a5c2fab3540977497f0644a0cad4f611a02000000000000207b8438dd4a5bacc0af221fc6812479f8d7976a8bd044ee1907e287a5038de2ce34b8bc7b68df6b68724a2533cc6d743ec386a82f24fec5d332d02913334371e673020000470db4c649d0b734d38fe8822608a561c26cd3c67af6613f7ced9eb39d8092a60200000000011709e86cb0accf8d81c9e85d34bea4b925ae936626d00c984e4691186891f5bc160ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd1a99a59d87e06e09ec5b028a9cbb7749b4a5ad8819004365d02dc4379a8b72412652f5f96006294109b3dd0bbde63693f55324af452b799ee137a81a905eed25299dcb6af692324b899b39f16d5a530a33062804e41f09dc97e9f156b447670735c2186cc36f7bb4aeaf4487b36e57039ccf45a9136aa856a5d569ecca55ef2b4a90c00d55454dc5b059055ca213579c6ea856967712a56017487886a4d4cc0f4e7bf348da00a945489b2a681749eb56f5de00b900014e137ddae39f48f69d674fca8bd82bbd181e714e283f83e1b45d95ca5af40fb89ad3977b653c448f78c25443fcf88330c586bc0e5f3dee10e7f63c76c00249c87fe4fbf7f38c082006b463320dd4a58212e4d32d1f58926b73ca33a247326c2a5e9fd39268d2384e011a68dcaa34c0517d19666e6b33add67351d8c5f69e999ca1e37931bc410a2974286bcb40a24e49c26d0a60513b6aeb8551d264e4717f306b81a37a5afb3b47cedc8ba52fe7a3956c5cd3a656a3174b931d3bb2abb45578befc59f283ecd816a405ad9e3d8f650687709fd68f4b90b41f7d825a365b02c23a636cef88ac2ac00c43bcd2a26394b36614fd4894241d3c451ab0f6fd110958c3423073621a70826e99c3a6138c5061cf291310887c0b5c71fcaffeab90d5deb50d3b9e687cead45071cbe0fafc8fcc6cc998395e9b6de6ebd94644467b1b4a97ec126005df07013c52d528b9f6e9693f45ed277af93474fd473ce7d831dae2180cca35d907bd10cb40e0fb64b1085cc5538970158d05a009c24e276fb94e1a0bf6a528b48fbc4ff526ef43112c6543b88db2283a2e077278c315ae2c84719a8b25f25cc88565fbea99f0af56d2c5a48d60a4a5b5c903edfb7db3a736a94ed589d0b797df33ff9d3e1dfce57d2331667353a0eac6b4209b67b843a7262a848af0a49a6e2fa9f6584eb400017cc0e85b8055cc5767055d74f00000001ae0a93b63afbaffe8c893e2cb74765904171ad547b454f0f405b656b1220000000000000000000000000000000000000000000000000000000000000000f219ff05b60b17239b8a9ab4e604788a5c2fab3540977497f0644a0cad4f611a02000000000000207b8438dd4a5bacc0af221fc6812479f8d7976a8bd044ee1907e287a5038de2ce34b8bc7b68df6b68724a2533cc6d743ec386a82f24fec5d332d02913334371e6000001012396c6e56d3b68643acde62d4c6efc894a7913a724179d2346c30eb6a4b4864f`

var finalityDataInput1 = `01000000000000000100000050f3c0f34771e2f2b8fcd27547f21fba504fa64708222d41336af632c19b1a887ab43c9132eb17408027d834d2c51e44fd4d51d82a09123f8a728c8a65109872`

0 comments on commit bea5885

Please sign in to comment.