Skip to content
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
c55376f
change some tests to use hex encoding for bytes
alan-ssvlabs Jun 14, 2025
ce26ae5
update hex encoding and decoding
alan-ssvlabs Jun 17, 2025
4828afa
update custom unmarshaller for StructureSizeTest
alan-ssvlabs Jun 17, 2025
cb27904
fix state comaprison bugs
alan-ssvlabs Jun 18, 2025
64139e3
fix all bugs in typesgit add .
alan-ssvlabs Jun 18, 2025
c27989c
finish qbft package
alan-ssvlabs Jun 18, 2025
19d9ad6
ssv package stil in progress
alan-ssvlabs Jun 18, 2025
1a9aa9a
fixing ssv
alan-ssvlabs Jun 20, 2025
52806c9
fix forceStop bug
alan-ssvlabs Jun 20, 2025
bc4304f
fix forceStop bug
alan-ssvlabs Jun 20, 2025
ef94d29
ssv TestAll works
alan-ssvlabs Jun 20, 2025
2faa6e7
a working version for ssv
alan-ssvlabs Jun 20, 2025
b7a9a64
types and ssv both working
alan-ssvlabs Jun 21, 2025
ee59ca7
finally a working version for all packages
alan-ssvlabs Jun 21, 2025
049d19f
lint
alan-ssvlabs Jun 21, 2025
a55651b
merge with main
alan-ssvlabs Jun 23, 2025
98af1db
use custom marshallers for types tests marshalling
alan-ssvlabs Jul 1, 2025
a936951
update custom unmarshallers for types tests
alan-ssvlabs Jul 2, 2025
31f20b7
remove hexencoding package from qbft tests encoding and decoding
alan-ssvlabs Jul 2, 2025
3bd357a
remove hexencoding package
alan-ssvlabs Jul 2, 2025
f53c687
fix comments
alan-ssvlabs Jul 9, 2025
427f81c
fix comments
alan-ssvlabs Jul 9, 2025
23ea3ba
fix conflicts
alan-ssvlabs Jul 9, 2025
9681b61
update unmarshaller for Message
alan-ssvlabs Jul 10, 2025
0a36059
generate jsons
GalRogozinski Jul 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Message struct {
```

#### Partial Signature Message
Used for pre and post consensus sigantures for collecting partial BN signatures and then reconstructing them
Used for pre and post consensus signatures for collecting partial BN signatures and then reconstructing them
```go
type PartialSignatureMessage struct {
Type PartialSigMsgType
Expand Down
79 changes: 79 additions & 0 deletions qbft/json_testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package qbft

import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"strings"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -39,6 +41,18 @@ func (c *Controller) GetRoot() ([32]byte, error) {
return ret, nil
}

// UnmarshalJSON is a custom JSON unmarshaller for Controller
func (c *Controller) UnmarshalJSON(data []byte) error {
type ControllerAlias Controller
aux := &struct {
*ControllerAlias
}{
ControllerAlias: (*ControllerAlias)(c),
}

return json.Unmarshal(data, aux)
}

// Instance
func (i *Instance) Encode() ([]byte, error) {
return json.Marshal(i)
Expand Down Expand Up @@ -126,3 +140,68 @@ func (c *MsgContainer) GetRoot() ([32]byte, error) {
ret := sha256.Sum256(marshaledRoot)
return ret, nil
}

// Message
func (m *Message) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"MsgType": m.MsgType,
"Height": m.Height,
"Round": m.Round,
"Identifier": m.Identifier,
"Root": hex.EncodeToString(m.Root[:]),
"DataRound": m.DataRound,
"RoundChangeJustification": m.RoundChangeJustification,
"PrepareJustification": m.PrepareJustification,
})
}

func (m *Message) UnmarshalJSON(data []byte) error {
type Alias Message
aux := &struct {
Root string `json:"Root"`
*Alias
}{
Alias: (*Alias)(m),
}

if err := json.Unmarshal(data, &aux); err != nil {
return err
}

if aux.Root != "" {
if bytes, err := hex.DecodeString(aux.Root); err == nil {
if len(bytes) != 32 {
return errors.New("Root must be exactly 32 bytes")
}
copy(m.Root[:], bytes)
return nil
}
}

return nil
}

// Value type for hex encoding json

type Value [32]byte

func (r *Value) MarshalJSON() ([]byte, error) {
return json.Marshal(hex.EncodeToString(r[:]))
}

func (r *Value) UnmarshalJSON(data []byte) error {
hexStr := hexStringFromJSON(data)
bytes, err := hex.DecodeString(hexStr)
if err != nil {
return errors.Wrap(err, "failed to decode Value")
}
copy(r[:], bytes)
return nil
}

// helpers

// hexStringFromJSON trims surrounding quotes from a JSON string value.
func hexStringFromJSON(data []byte) string {
return strings.TrimSuffix(strings.TrimPrefix(string(data), "\""), "\"")
}
2 changes: 1 addition & 1 deletion qbft/spectest/generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func writeJsonStateComparison(name, testType string, post interface{}) {
}
log.Printf("writing state comparison json: %s\n", name)

byts, err := json.MarshalIndent(post, "", " ")
byts, err := json.MarshalIndent(post, "", " ")
if err != nil {
panic(err.Error())
}
Expand Down
Loading