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
22 changes: 22 additions & 0 deletions protocol/core/shell.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package core

import (
"encoding/binary"
"errors"
tz "github.com/ecadlabs/gotez/v2"
"github.com/ecadlabs/gotez/v2/encoding"
)
Expand All @@ -16,6 +18,26 @@ type ShellHeader struct {
Context *tz.ContextHash `json:"context"`
}

// GetRoundFromTenderbakeBlock extracts the round from a Tenderbake block fitness
func GetRoundFromTenderbakeBlock(data tz.Bytes) (uint32, error) {
/* FITNESS=
(<fitness_length(4)> not in gotez)
<version_len(4)><version(1)>
<level_len(4)><level(4)>
<locked_round_len(4)><locked_round(0 OR 4)>
<predecessor_round_len(4)><predecessor_round(4)>
<round_len(4)><round(4)> */

if len(data) < 4 {
return 0, errors.New("data too short to extract round")
}
// The fitness data has been stripped from its prefixed length
// The round value is always the 4 last bytes
round := binary.BigEndian.Uint32(data[len(data)-4:])

return round, nil
}

type BlockMetadataHeader struct {
TestChainStatus TestChainStatus `json:"test_chain_status"`
MaxOperationsTTL int32 `json:"max_operations_ttl"`
Expand Down
8 changes: 7 additions & 1 deletion protocol/proto_022_PsRiotum/sign_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ type BlockSignRequest struct {

func (r *BlockSignRequest) GetChainID() *tz.ChainID { return r.Chain }
func (r *BlockSignRequest) GetLevel() int32 { return r.BlockHeader.Level }
func (r *BlockSignRequest) GetRound() int32 { return r.BlockHeader.PayloadRound }
func (r *BlockSignRequest) GetRound() int32 {
round, err := core.GetRoundFromTenderbakeBlock(r.BlockHeader.Fitness)
if err != nil {
fmt.Println("Error: ", err)
}
return int32(round)
}
func (*BlockSignRequest) SignRequestKind() string { return "block" }

type ConsensusSignRequest[T core.OperationContents] struct {
Expand Down
Loading