From 76f6e5a3a3abdbd6b32c95b662e439db9029174e Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Mon, 23 Feb 2026 11:39:15 +0100 Subject: [PATCH] Decode round from fitness and use it in getround for proposals --- protocol/core/shell.go | 22 +++++++++++++++++++++ protocol/proto_022_PsRiotum/sign_request.go | 8 +++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/protocol/core/shell.go b/protocol/core/shell.go index bf9ed4f..4ab9687 100644 --- a/protocol/core/shell.go +++ b/protocol/core/shell.go @@ -1,6 +1,8 @@ package core import ( + "encoding/binary" + "errors" tz "github.com/ecadlabs/gotez/v2" "github.com/ecadlabs/gotez/v2/encoding" ) @@ -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= + ( not in gotez) + + + + + */ + + 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"` diff --git a/protocol/proto_022_PsRiotum/sign_request.go b/protocol/proto_022_PsRiotum/sign_request.go index deeaf3b..6cb1312 100644 --- a/protocol/proto_022_PsRiotum/sign_request.go +++ b/protocol/proto_022_PsRiotum/sign_request.go @@ -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 {