Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ lint:

generate-ssz:
rm -f types/builder_encoding.go types/signing_encoding.go types/common_encoding.go
sszgen --path types --include ../go-ethereum/common/hexutil --objs Eth1Data,BeaconBlockHeader,SignedBeaconBlockHeader,ProposerSlashing,Checkpoint,AttestationData,IndexedAttestation,AttesterSlashing,Attestation,Deposit,VoluntaryExit,SyncAggregate,ExecutionPayloadHeader,VersionedExecutionPayloadHeader,BlindedBeaconBlockBody,BlindedBeaconBlock,RegisterValidatorRequestMessage,BuilderBid,SignedBuilderBid,SigningData,ForkData,Transactions,BidTraceMessage,BuilderSubmitBlockRequestMessage,BuilderSubmitBlockResponseMessage
sszgen --path types --include ../go-ethereum/common/hexutil --objs Eth1Data,BeaconBlockHeader,SignedBeaconBlockHeader,ProposerSlashing,Checkpoint,AttestationData,IndexedAttestation,AttesterSlashing,Attestation,Deposit,VoluntaryExit,SyncAggregate,ExecutionPayloadHeader,VersionedExecutionPayloadHeader,BlindedBeaconBlockBody,BlindedBeaconBlock,SignedBlindedBeaconBlock,RegisterValidatorRequestMessage,BuilderBid,SignedBuilderBid,SigningData,ForkData,Transactions,BidTraceMessage,BuilderSubmitBlockRequestMessage,BuilderSubmitBlockResponseMessage

cover:
go test -coverprofile=/tmp/go-sim-lb.cover.tmp ./...
Expand Down
105 changes: 104 additions & 1 deletion types/builder_encoding.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions types/encoding_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package types

import (
"encoding/json"
"os"
"testing"

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

func BenchmarkJSONvsSSZEncoding(b *testing.B) {
var err error
jsonFile, err := os.Open("../testdata/signed-blinded-beacon-block-with-deposit.json")
require.NoError(b, err)
defer jsonFile.Close()
signedBlindedBeaconBlock := new(SignedBlindedBeaconBlock)
require.NoError(b, DecodeJSON(jsonFile, &signedBlindedBeaconBlock))
signedBlindedBeaconBlockJSONBytes, err := json.Marshal(signedBlindedBeaconBlock)
require.NoError(b, err)
signedBlindedBeaconBlockSSZBytes, err := signedBlindedBeaconBlock.MarshalSSZ()
require.NoError(b, err)

b.Run("Encode JSON", func(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err = json.Marshal(signedBlindedBeaconBlock)
require.NoError(b, err)
}
})

b.Run("Encode SSZ", func(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err = signedBlindedBeaconBlock.MarshalSSZ()
require.NoError(b, err)
}
})

b.Run("Decode JSON", func(b *testing.B) {
_blindedBeaconBlock := new(SignedBlindedBeaconBlock)
for n := 0; n < b.N; n++ {
err = json.Unmarshal(signedBlindedBeaconBlockJSONBytes, _blindedBeaconBlock)
require.NoError(b, err)
}
})

b.Run("Decode SSZ", func(b *testing.B) {
_blindedBeaconBlock := new(SignedBlindedBeaconBlock)
for n := 0; n < b.N; n++ {
err = _blindedBeaconBlock.UnmarshalSSZ(signedBlindedBeaconBlockSSZBytes)
require.NoError(b, err)
}
})
}