mukan-consensus/statesync/messages.go
Mukan Erkin Törük ef24c0b67e
Some checks are pending
docker-build-cometbft / vars (push) Waiting to run
docker-build-cometbft / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-cometbft / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-cometbft / merge-images (push) Blocked by required conditions
docker-build-e2e-node / vars (push) Waiting to run
docker-build-e2e-node / build-images (amd64, ubuntu-24.04) (push) Blocked by required conditions
docker-build-e2e-node / build-images (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
docker-build-e2e-node / merge-images (push) Blocked by required conditions
initial: sovereign Mukan Network fork
2026-05-11 03:18:27 +03:00

61 lines
1.6 KiB
Go

package statesync
import (
"errors"
"fmt"
"github.com/cosmos/gogoproto/proto"
ssproto "github.com/cometbft/cometbft/proto/tendermint/statesync"
)
const (
// snapshotMsgSize is the maximum size of a snapshotResponseMessage
snapshotMsgSize = int(4e6)
// chunkMsgSize is the maximum size of a chunkResponseMessage
chunkMsgSize = int(16e6)
)
var (
ErrExceedsMaxSnapshotChunks = errors.New("amount of chunks in the snapshot exceeds the maximum allowed number of chunks")
)
// validateMsg validates a message.
func validateMsg(pb proto.Message, maxSnapshotChunks uint32) error {
if pb == nil {
return errors.New("message cannot be nil")
}
switch msg := pb.(type) {
case *ssproto.ChunkRequest:
if msg.Height == 0 {
return errors.New("height cannot be 0")
}
case *ssproto.ChunkResponse:
if msg.Height == 0 {
return errors.New("height cannot be 0")
}
if msg.Missing && len(msg.Chunk) > 0 {
return errors.New("missing chunk cannot have contents")
}
if !msg.Missing && msg.Chunk == nil {
return errors.New("chunk cannot be nil")
}
case *ssproto.SnapshotsRequest:
case *ssproto.SnapshotsResponse:
if msg.Height == 0 {
return errors.New("height cannot be 0")
}
if len(msg.Hash) == 0 {
return errors.New("snapshot has no hash")
}
if msg.Chunks == 0 {
return errors.New("snapshot has no chunks")
}
if msg.Chunks > maxSnapshotChunks {
return fmt.Errorf("%w: snapshot response chunk count: %d, maximum chunks: %d", ErrExceedsMaxSnapshotChunks, msg.Chunks, maxSnapshotChunks)
}
default:
return fmt.Errorf("unknown message type %T", msg)
}
return nil
}