ceremonyclient/node/execution/intrinsics/global/global_serialization.go
Cassandra Heart 53f7c2b5c9
v2.1.0.2 (#442)
* v2.1.0.2

* restore tweaks to simlibp2p

* fix: nil ref on size calc

* fix: panic should induce shutdown from event_distributor

* fix: friendlier initialization that requires less manual kickstarting for test/devnets

* fix: fewer available shards than provers should choose shard length

* fix: update stored worker registry, improve logging for debug mode

* fix: shut the fuck up, peer log

* qol: log value should be snake cased

* fix:non-archive snap sync issues

* fix: separate X448/Decaf448 signed keys, add onion key to registry

* fix: overflow arithmetic on frame number comparison

* fix: worker registration should be idempotent if inputs are same, otherwise permit updated records

* fix: remove global prover state from size calculation

* fix: divide by zero case

* fix: eager prover

* fix: broadcast listener default

* qol: diagnostic data for peer authenticator

* fix: master/worker connectivity issue in sparse networks

tight coupling of peer and workers can sometimes interfere if mesh is sparse, so give workers a pseudoidentity but publish messages with the proper peer key

* fix: reorder steps of join creation

* fix: join verify frame source + ensure domain is properly padded (unnecessary but good for consistency)

* fix: add delegate to protobuf <-> reified join conversion

* fix: preempt prover from planning with no workers

* fix: use the unallocated workers to generate a proof

* qol: underflow causes join fail in first ten frames on test/devnets

* qol: small logging tweaks for easier log correlation in debug mode

* qol: use fisher-yates shuffle to ensure prover allocations are evenly distributed when scores are equal

* qol: separate decisional logic on post-enrollment confirmation into consensus engine, proposer, and worker manager where relevant, refactor out scoring

* reuse shard descriptors for both join planning and confirm/reject decisions

* fix: add missing interface method and amend test blossomsub to use new peer id basis

* fix: only check allocations if they exist

* fix: pomw mint proof data needs to be hierarchically under global intrinsic domain

* staging temporary state under diagnostics

* fix: first phase of distributed lock refactoring

* fix: compute intrinsic locking

* fix: hypergraph intrinsic locking

* fix: token intrinsic locking

* fix: update execution engines to support new locking model

* fix: adjust tests with new execution shape

* fix: weave in lock/unlock semantics to liveness provider

* fix lock fallthrough, add missing allocation update

* qol: additional logging for diagnostics, also testnet/devnet handling for confirmations

* fix: establish grace period on halt scenario to permit recovery

* fix: support test/devnet defaults for coverage scenarios

* fix: nil ref on consensus halts for non-archive nodes

* fix: remove unnecessary prefix from prover ref

* add test coverage for fork choice behaviors and replay – once passing, blocker (2) is resolved

* fix: no fork replay on repeat for non-archive nodes, snap now behaves correctly

* rollup of pre-liveness check lock interactions

* ahead of tests, get the protobuf/metrics-related changes out so teams can prepare

* add test coverage for distributed lock behaviors – once passing, blocker (3) is resolved

* fix: blocker (3)

* Dev docs improvements (#445)

* Make install deps script more robust

* Improve testing instructions

* Worker node should stop upon OS SIGINT/SIGTERM signal (#447)

* move pebble close to Stop()

* move deferred Stop() to Start()

* add core id to worker stop log message

* create done os signal channel and stop worker upon message to it

---------

Co-authored-by: Cassandra Heart <7929478+CassOnMars@users.noreply.github.com>

---------

Co-authored-by: Daz <daz_the_corgi@proton.me>
Co-authored-by: Black Swan <3999712+blacks1ne@users.noreply.github.com>
2025-10-23 01:03:06 -05:00

427 lines
12 KiB
Go

package global
import (
"github.com/pkg/errors"
"source.quilibrium.com/quilibrium/monorepo/protobufs"
"source.quilibrium.com/quilibrium/monorepo/types/crypto"
"source.quilibrium.com/quilibrium/monorepo/types/hypergraph"
"source.quilibrium.com/quilibrium/monorepo/types/keys"
"source.quilibrium.com/quilibrium/monorepo/types/store"
)
// ToBytes serializes a BLS48581SignatureWithProofOfPossession to bytes using
// protobuf
func (s *BLS48581SignatureWithProofOfPossession) ToBytes() ([]byte, error) {
pb := s.ToProtobuf()
return pb.ToCanonicalBytes()
}
// FromBytes deserializes a BLS48581SignatureWithProofOfPossession from bytes
// using protobuf
func (s *BLS48581SignatureWithProofOfPossession) FromBytes(data []byte) error {
pb := &protobufs.BLS48581SignatureWithProofOfPossession{}
if err := pb.FromCanonicalBytes(data); err != nil {
return errors.Wrap(err, "from bytes")
}
converted, err := BLS48581SignatureWithProofOfPossessionFromProtobuf(pb)
if err != nil {
return errors.Wrap(err, "from bytes")
}
*s = *converted
return nil
}
// ToBytes serializes a BLS48581AddressedSignature to bytes using protobuf
func (s *BLS48581AddressedSignature) ToBytes() ([]byte, error) {
pb := s.ToProtobuf()
return pb.ToCanonicalBytes()
}
// FromBytes deserializes a BLS48581AddressedSignature from bytes using protobuf
func (s *BLS48581AddressedSignature) FromBytes(data []byte) error {
pb := &protobufs.BLS48581AddressedSignature{}
if err := pb.FromCanonicalBytes(data); err != nil {
return errors.Wrap(err, "from bytes")
}
converted, err := BLS48581AddressedSignatureFromProtobuf(pb)
if err != nil {
return errors.Wrap(err, "from bytes")
}
*s = *converted
return nil
}
// ToBytes serializes a SeniorityMerge to bytes using protobuf
func (s *SeniorityMerge) ToBytes() ([]byte, error) {
pb := s.ToProtobuf()
return pb.ToCanonicalBytes()
}
// FromBytes deserializes a SeniorityMerge from bytes using protobuf
func (s *SeniorityMerge) FromBytes(data []byte) error {
pb := &protobufs.SeniorityMerge{}
if err := pb.FromCanonicalBytes(data); err != nil {
return errors.Wrap(err, "from bytes")
}
converted, err := SeniorityMergeFromProtobuf(pb)
if err != nil {
return errors.Wrap(err, "from bytes")
}
*s = *converted
return nil
}
// ToBytes serializes a ProverJoin to bytes using protobuf
func (p *ProverJoin) ToBytes() ([]byte, error) {
pb := p.ToProtobuf()
return pb.ToCanonicalBytes()
}
// ToRequestBytes serializes a ProverJoin to MessageRequest bytes using protobuf
func (p *ProverJoin) ToRequestBytes() ([]byte, error) {
pb := p.ToProtobuf()
req := &protobufs.MessageRequest{
Request: &protobufs.MessageRequest_Join{
Join: pb,
},
}
return req.ToCanonicalBytes()
}
// FromBytes deserializes a ProverJoin from bytes using protobuf
func (p *ProverJoin) FromBytes(data []byte) error {
pb := &protobufs.ProverJoin{}
if err := pb.FromCanonicalBytes(data); err != nil {
return errors.Wrap(err, "from bytes")
}
// Note: Runtime dependencies are not available here
// They need to be injected separately after deserialization
converted, err := ProverJoinFromProtobuf(pb, nil, nil, nil, nil, nil, nil)
if err != nil {
return errors.Wrap(err, "from bytes")
}
// Copy only the data fields, runtime dependencies will be set separately
p.Filters = converted.Filters
p.FrameNumber = converted.FrameNumber
p.PublicKeySignatureBLS48581 = converted.PublicKeySignatureBLS48581
p.MergeTargets = converted.MergeTargets
return nil
}
// ToBytes serializes a ProverLeave to bytes using protobuf
func (p *ProverLeave) ToBytes() ([]byte, error) {
pb := p.ToProtobuf()
return pb.ToCanonicalBytes()
}
// ToRequestBytes serializes a ProverLeave to MessageRequest bytes using protobuf
func (p *ProverLeave) ToRequestBytes() ([]byte, error) {
pb := p.ToProtobuf()
req := &protobufs.MessageRequest{
Request: &protobufs.MessageRequest_Leave{
Leave: pb,
},
}
return req.ToCanonicalBytes()
}
// FromBytes deserializes a ProverLeave from bytes using protobuf
func (p *ProverLeave) FromBytes(data []byte) error {
pb := &protobufs.ProverLeave{}
if err := pb.FromCanonicalBytes(data); err != nil {
return errors.Wrap(err, "from bytes")
}
converted, err := ProverLeaveFromProtobuf(pb, nil, nil, nil, nil)
if err != nil {
return errors.Wrap(err, "from bytes")
}
// Copy only the data fields, runtime dependencies will be set separately
p.Filters = converted.Filters
p.FrameNumber = converted.FrameNumber
p.PublicKeySignatureBLS48581 = converted.PublicKeySignatureBLS48581
return nil
}
// ToBytes serializes a ProverPause to bytes using protobuf
func (p *ProverPause) ToBytes() ([]byte, error) {
pb := p.ToProtobuf()
return pb.ToCanonicalBytes()
}
// ToRequestBytes serializes a ProverPause to MessageRequest bytes using protobuf
func (p *ProverPause) ToRequestBytes() ([]byte, error) {
pb := p.ToProtobuf()
req := &protobufs.MessageRequest{
Request: &protobufs.MessageRequest_Pause{
Pause: pb,
},
}
return req.ToCanonicalBytes()
}
// FromBytes deserializes a ProverPause from bytes using protobuf
func (p *ProverPause) FromBytes(data []byte) error {
pb := &protobufs.ProverPause{}
if err := pb.FromCanonicalBytes(data); err != nil {
return errors.Wrap(err, "from bytes")
}
converted, err := ProverPauseFromProtobuf(pb, nil, nil, nil, nil)
if err != nil {
return errors.Wrap(err, "from bytes")
}
// Copy only the data fields, runtime dependencies will be set separately
p.Filter = converted.Filter
p.FrameNumber = converted.FrameNumber
p.PublicKeySignatureBLS48581 = converted.PublicKeySignatureBLS48581
return nil
}
// ToBytes serializes a ProverResume to bytes using protobuf
func (p *ProverResume) ToBytes() ([]byte, error) {
pb := p.ToProtobuf()
return pb.ToCanonicalBytes()
}
// ToRequestBytes serializes a ProverResume to MessageRequest bytes using
// protobuf
func (p *ProverResume) ToRequestBytes() ([]byte, error) {
pb := p.ToProtobuf()
req := &protobufs.MessageRequest{
Request: &protobufs.MessageRequest_Resume{
Resume: pb,
},
}
return req.ToCanonicalBytes()
}
// FromBytes deserializes a ProverResume from bytes using protobuf
func (p *ProverResume) FromBytes(data []byte) error {
pb := &protobufs.ProverResume{}
if err := pb.FromCanonicalBytes(data); err != nil {
return errors.Wrap(err, "from bytes")
}
converted, err := ProverResumeFromProtobuf(pb, nil, nil, nil, nil)
if err != nil {
return errors.Wrap(err, "from bytes")
}
// Copy only the data fields, runtime dependencies will be set separately
p.Filter = converted.Filter
p.FrameNumber = converted.FrameNumber
p.PublicKeySignatureBLS48581 = converted.PublicKeySignatureBLS48581
return nil
}
// ToBytes serializes a ProverConfirm to bytes using protobuf
func (p *ProverConfirm) ToBytes() ([]byte, error) {
pb := p.ToProtobuf()
return pb.ToCanonicalBytes()
}
// ToRequestBytes serializes a ProverConfirm to MessageRequest bytes using
// protobuf
func (p *ProverConfirm) ToRequestBytes() ([]byte, error) {
pb := p.ToProtobuf()
req := &protobufs.MessageRequest{
Request: &protobufs.MessageRequest_Confirm{
Confirm: pb,
},
}
return req.ToCanonicalBytes()
}
// FromBytes deserializes a ProverConfirm from bytes using protobuf
func (p *ProverConfirm) FromBytes(data []byte) error {
pb := &protobufs.ProverConfirm{}
if err := pb.FromCanonicalBytes(data); err != nil {
return errors.Wrap(err, "from bytes")
}
converted, err := ProverConfirmFromProtobuf(pb, nil, nil, nil, nil)
if err != nil {
return errors.Wrap(err, "from bytes")
}
// Copy only the data fields, runtime dependencies will be set separately
p.Filter = converted.Filter
p.FrameNumber = converted.FrameNumber
p.PublicKeySignatureBLS48581 = converted.PublicKeySignatureBLS48581
return nil
}
// ToBytes serializes a ProverReject to bytes using protobuf
func (p *ProverReject) ToBytes() ([]byte, error) {
pb := p.ToProtobuf()
return pb.ToCanonicalBytes()
}
// ToRequestBytes serializes a ProverReject to MessageRequest bytes using
// protobuf
func (p *ProverReject) ToRequestBytes() ([]byte, error) {
pb := p.ToProtobuf()
req := &protobufs.MessageRequest{
Request: &protobufs.MessageRequest_Reject{
Reject: pb,
},
}
return req.ToCanonicalBytes()
}
// FromBytes deserializes a ProverReject from bytes using protobuf
func (p *ProverReject) FromBytes(data []byte) error {
pb := &protobufs.ProverReject{}
if err := pb.FromCanonicalBytes(data); err != nil {
return errors.Wrap(err, "from bytes")
}
converted, err := ProverRejectFromProtobuf(pb, nil, nil, nil, nil)
if err != nil {
return errors.Wrap(err, "from bytes")
}
// Copy only the data fields, runtime dependencies will be set separately
p.Filter = converted.Filter
p.FrameNumber = converted.FrameNumber
p.PublicKeySignatureBLS48581 = converted.PublicKeySignatureBLS48581
return nil
}
// ToBytes serializes a ProverKick to bytes using protobuf
func (p *ProverKick) ToBytes() ([]byte, error) {
pb := p.ToProtobuf()
return pb.ToCanonicalBytes()
}
// ToRequestBytes serializes a ProverKick to MessageRequest bytes using protobuf
func (p *ProverKick) ToRequestBytes() ([]byte, error) {
pb := p.ToProtobuf()
req := &protobufs.MessageRequest{
Request: &protobufs.MessageRequest_Kick{
Kick: pb,
},
}
return req.ToCanonicalBytes()
}
// FromBytes deserializes a ProverKick from bytes using protobuf
// Note: ProverKick requires special handling for traversal proof
func (p *ProverKick) FromBytes(data []byte) error {
pb := &protobufs.ProverKick{}
if err := pb.FromCanonicalBytes(data); err != nil {
return errors.Wrap(err, "from bytes")
}
converted, err := ProverKickFromProtobuf(pb, nil, nil, nil)
if err != nil {
return errors.Wrap(err, "from bytes")
}
// Copy all fields including TraversalProof
*p = *converted
return nil
}
// Special FromBytes for ProverKick that handles hypergraph dependency
func (p *ProverKick) FromBytesWithHypergraph(
data []byte,
hg hypergraph.Hypergraph,
inclusionProver crypto.InclusionProver,
keyManager keys.KeyManager,
) error {
pb := &protobufs.ProverKick{}
if err := pb.FromCanonicalBytes(data); err != nil {
return errors.Wrap(err, "from bytes")
}
converted, err := ProverKickFromProtobuf(pb, hg, inclusionProver, keyManager)
if err != nil {
return errors.Wrap(err, "from bytes")
}
*p = *converted
return nil
}
// GlobalRequestFromBytes deserializes a global request from bytes using
// protobuf
func GlobalRequestFromBytes(
data []byte,
hg hypergraph.Hypergraph,
signer crypto.Signer,
inclusionProver crypto.InclusionProver,
keyManager keys.KeyManager,
frameProver crypto.FrameProver,
frameStore store.ClockStore,
) (interface{}, error) {
pb := &protobufs.MessageRequest{}
if err := pb.FromCanonicalBytes(data); err != nil {
return nil, errors.Wrap(err, "global request from bytes")
}
return GlobalRequestFromProtobuf(
pb,
hg,
signer,
inclusionProver,
keyManager,
frameProver,
frameStore,
)
}
// ToBytes serializes a ProverUpdate to bytes using protobuf
func (p *ProverUpdate) ToBytes() ([]byte, error) {
pb := p.ToProtobuf()
return pb.ToCanonicalBytes()
}
// ToRequestBytes serializes a ProverUpdate to MessageRequest bytes using protobuf
func (p *ProverUpdate) ToRequestBytes() ([]byte, error) {
pb := p.ToProtobuf()
req := &protobufs.MessageRequest{
Request: &protobufs.MessageRequest_Update{
Update: pb,
},
}
return req.ToCanonicalBytes()
}
// FromBytes deserializes a ProverUpdate from bytes using protobuf
func (p *ProverUpdate) FromBytes(data []byte) error {
pb := &protobufs.ProverUpdate{}
if err := pb.FromCanonicalBytes(data); err != nil {
return errors.Wrap(err, "from bytes")
}
converted, err := ProverUpdateFromProtobuf(pb, nil, nil, nil, nil)
if err != nil {
return errors.Wrap(err, "from bytes")
}
// Copy only the data fields, runtime dependencies will be set separately
p.DelegateAddress = converted.DelegateAddress
p.PublicKeySignatureBLS48581 = converted.PublicKeySignatureBLS48581
return nil
}