go-blockchain/p2p/sync.go
Snider 71f0a5c1d5
Some checks failed
Security Scan / security (push) Successful in 11s
Test / Test (push) Failing after 23s
refactor: replace fmt.Errorf/os.* with go-io/go-log conventions
Replace all fmt.Errorf and errors.New in production code with
coreerr.E("Caller.Method", "message", err) from go-log. Replace
os.MkdirAll with coreio.Local.EnsureDir from go-io. Sentinel errors
(consensus/errors.go, wire/varint.go) intentionally kept as errors.New
for errors.Is compatibility.

270 error call sites converted across 38 files. Test files untouched.
crypto/ directory (CGO) untouched.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-16 21:17:49 +00:00

82 lines
2 KiB
Go

// Copyright (c) 2017-2026 Lethean (https://lt.hn)
//
// Licensed under the European Union Public Licence (EUPL) version 1.2.
// SPDX-License-Identifier: EUPL-1.2
package p2p
import (
"forge.lthn.ai/core/go-blockchain/types"
"forge.lthn.ai/core/go-p2p/node/levin"
)
// CoreSyncData is the blockchain state exchanged during handshake and timed sync.
type CoreSyncData struct {
CurrentHeight uint64
TopID types.Hash
LastCheckpointHeight uint64
CoreTime uint64
ClientVersion string
NonPruningMode bool
}
// MarshalSection encodes CoreSyncData into a portable storage Section.
func (d *CoreSyncData) MarshalSection() levin.Section {
return levin.Section{
"current_height": levin.Uint64Val(d.CurrentHeight),
"top_id": levin.StringVal(d.TopID[:]),
"last_checkpoint_height": levin.Uint64Val(d.LastCheckpointHeight),
"core_time": levin.Uint64Val(d.CoreTime),
"client_version": levin.StringVal([]byte(d.ClientVersion)),
"non_pruning_mode_enabled": levin.BoolVal(d.NonPruningMode),
}
}
// UnmarshalSection decodes CoreSyncData from a portable storage Section.
func (d *CoreSyncData) UnmarshalSection(s levin.Section) error {
if v, ok := s["current_height"]; ok {
val, err := v.AsUint64()
if err != nil {
return err
}
d.CurrentHeight = val
}
if v, ok := s["top_id"]; ok {
blob, err := v.AsString()
if err != nil {
return err
}
if len(blob) == 32 {
copy(d.TopID[:], blob)
}
}
if v, ok := s["last_checkpoint_height"]; ok {
val, err := v.AsUint64()
if err != nil {
return err
}
d.LastCheckpointHeight = val
}
if v, ok := s["core_time"]; ok {
val, err := v.AsUint64()
if err != nil {
return err
}
d.CoreTime = val
}
if v, ok := s["client_version"]; ok {
blob, err := v.AsString()
if err != nil {
return err
}
d.ClientVersion = string(blob)
}
if v, ok := s["non_pruning_mode_enabled"]; ok {
val, err := v.AsBool()
if err != nil {
return err
}
d.NonPruningMode = val
}
return nil
}