upstream

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: Apache-2.0, UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Overview

Package upstream defines tm2 types whose amino wire-format is byte-identical to upstream Tendermint v0.34's protobuf encoding. They exist only for the privval-wire boundary — the path between a gno.land validator and an external upstream-protocol KMS such as tmkms.

The chain's own Vote/Proposal/BlockID/PartSetHeader types in tm2/pkg/bft/types remain unchanged; they're used in p2p messages and blocks, where any byte-level shift would be a network-coordinated upgrade. The translator (translator.go) converts between the two shapes.

CanonicalVote and CanonicalProposal are NOT redefined here — they live in tm2/pkg/bft/types and were re-tagged in Phase 1 (POLRound varint; CanonicalPartSetHeader uint32 Total first) to be byte-identical to upstream's canonical.proto.

Index

Constants

This section is empty.

Variables

View Source
var Package = pkg.NewPackage(
	"github.com/gnolang/gno/tm2/pkg/bft/privval/upstream",
	"upstream",
	pkg.GetCallersDirname(),
).WithTypes(

	Vote{},
	Proposal{},
	BlockID{},
	PartSetHeader{},
)

Package registers the upstream-shaped operational types with amino so they can be marshaled via the codec. Registration drives the binary encoder's per-field FieldOptions (binary:"varint" tags), which is how these types produce upstream-Tendermint-compatible wire bytes.

NOTE: privval socket-protocol messages (Message, PubKeyRequest, etc.) are NOT amino-encoded. They live in the upstreampb sibling package as protoc-generated types, used directly via google.golang.org/protobuf for wire I/O. Mirrors how cometbft/privval uses cometbft/proto.

Functions

func ProposalFromProto

func ProposalFromProto(p *upstreampb.Proposal) (*types.Proposal, error)

func ProposalToProto

func ProposalToProto(p *types.Proposal) (*upstreampb.Proposal, error)

func PubKeyFromProto

func PubKeyFromProto(p *upstreampb.PublicKey) (crypto.PubKey, error)

PubKeyFromProto returns the tm2 crypto.PubKey for an upstreampb.PublicKey oneof, dispatching on the populated branch.

func PubKeyToProto

func PubKeyToProto(pk crypto.PubKey) (*upstreampb.PublicKey, error)

PubKeyToProto converts a tm2 crypto.PubKey to the upstreampb.PublicKey oneof. Returns an error for unsupported key types — only ed25519 and secp256k1 are mapped, matching upstream Tendermint v0.34's PublicKey oneof.

func ToTM2BlockID

func ToTM2BlockID(b BlockID) types.BlockID

func ToTM2PartSetHeader

func ToTM2PartSetHeader(p PartSetHeader) types.PartSetHeader

func ToTM2Proposal

func ToTM2Proposal(p *Proposal) *types.Proposal

ToTM2Proposal converts an upstream-shape Proposal back to chain-internal.

func ToTM2Vote

func ToTM2Vote(v *Vote) *types.Vote

ToTM2Vote converts an upstream-shape Vote back to a chain-internal types.Vote. ValidatorAddress bytes must be exactly crypto.AddressSize (20); otherwise the conversion panics — an upstream peer sending a malformed address is a protocol violation we surface immediately rather than silently truncate.

func UnwrapMsg

func UnwrapMsg(msg *upstreampb.Message) (interface{}, error)

UnwrapMsg returns the concrete privval message inside an upstreampb.Message envelope. Returns an error if the envelope is empty or carries an unrecognized Sum variant — the wire was malformed or emitted by an incompatible peer.

func VoteFromProto

func VoteFromProto(v *upstreampb.Vote) (*types.Vote, error)

VoteFromProto converts upstreampb.Vote to tm2 types.Vote.

func VoteToProto

func VoteToProto(v *types.Vote) (*upstreampb.Vote, error)

VoteToProto converts a tm2 types.Vote to upstreampb.Vote.

func WrapMsg

func WrapMsg(pb interface{}) *upstreampb.Message

WrapMsg builds an upstreampb.Message containing the given concrete privval message. Panics if pb is not one of the recognized privval message types — this is a programming error, not a runtime input.

Mirror of cometbft/privval/msgs.go::mustWrapMsg.

Types

type BlockID

type BlockID struct {
	Hash          []byte
	PartSetHeader PartSetHeader
}

BlockID matches upstream's types.proto BlockID:

message BlockID {
  bytes         hash            = 1;
  PartSetHeader part_set_header = 2;
}

The Go field name is PartSetHeader (matching upstream) rather than tm2's PartsHeader. Only field POSITION matters for wire bytes.

func FromTM2BlockID

func FromTM2BlockID(b types.BlockID) BlockID

type PartSetHeader

type PartSetHeader struct {
	Total uint32
	Hash  []byte
}

PartSetHeader matches upstream's types.proto PartSetHeader:

message PartSetHeader {
  uint32 total = 1;
  bytes  hash  = 2;
}

Difference from tm2/pkg/bft/types.PartSetHeader:

  • total: uint32 plain varint (tm2: int → sint64 zigzag)

Field order matches tm2 (Total first); only the type changes.

func FromTM2PartSetHeader

func FromTM2PartSetHeader(p types.PartSetHeader) PartSetHeader

type Proposal

type Proposal struct {
	Type      types.SignedMsgType
	Height    int64 `binary:"varint"`
	Round     int32 `binary:"varint"`
	POLRound  int32 `binary:"varint"`
	BlockID   BlockID
	Timestamp time.Time
	Signature []byte
}

Proposal matches upstream Tendermint v0.34's types.proto Proposal:

message Proposal {
  SignedMsgType type      = 1;
  int64         height    = 2;
  int32         round     = 3;
  int32         pol_round = 4;
  BlockID       block_id  = 5;
  google.protobuf.Timestamp timestamp = 6;
  bytes         signature = 7;
}

func FromTM2Proposal

func FromTM2Proposal(p *types.Proposal) *Proposal

FromTM2Proposal converts a chain-internal types.Proposal to upstream shape.

type Vote

type Vote struct {
	Type             types.SignedMsgType
	Height           int64 `binary:"varint"`
	Round            int32 `binary:"varint"`
	BlockID          BlockID
	Timestamp        time.Time
	ValidatorAddress []byte
	ValidatorIndex   int32 `binary:"varint"`
	Signature        []byte
}

Vote matches upstream Tendermint v0.34's types.proto Vote message:

message Vote {
  SignedMsgType type              = 1;
  int64         height            = 2;
  int32         round             = 3;
  BlockID       block_id          = 4;
  google.protobuf.Timestamp timestamp = 5;
  bytes         validator_address = 6;
  int32         validator_index   = 7;
  bytes         signature         = 8;
}

Differences from tm2/pkg/bft/types.Vote:

  • height: int64 plain varint (tm2: sint64 zigzag)
  • round: int32 plain varint (tm2: sint64)
  • validator_address: raw bytes (tm2: bech32 string via Address.MarshalAmino)
  • validator_index: int32 plain varint (tm2: sint64)

func FromTM2Vote

func FromTM2Vote(v *types.Vote) *Vote

FromTM2Vote converts a chain-internal types.Vote to its upstream-compatible shape. ValidatorAddress is the raw 20 bytes of the bech32-encoded tm2 Address; rounds and indices narrow to int32 (overflow panics — these are consensus-shaped values that cannot legitimately exceed int32 range).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL