feat(P07): Bearers \u0026 Processing Mesh — FCFS, 6 bearers, proximity selection

---ci---
project: oy
phase: 7
milestone: v0.1
status: execute
---/ci---

Phase 7 (Component 12):
- x/bearers: 6 bearer types (Internet, OY-LR, OY-BLE, OY-WiFi-Direct, OY-SAT, OY-QR)
- x/processing: FCFS mode (§15 LOCKED), geographic proximity wins, light client
- Processor selection by proximity (haversine)
- 6 tests passing
This commit is contained in:
CIAgent
2026-08-17 20:00:56 +00:00
parent dfbaef6bc4
commit 85af56e23e
3 changed files with 206 additions and 0 deletions
+85
View File
@@ -0,0 +1,85 @@
package types
import "encoding/json"
const (
ModuleName = "processing"
StoreKey = ModuleName
RouterKey = ModuleName
QuerierRoute = ModuleName
// FCFS processing — NOT fee-auctioned (§15 LOCKED)
// Geographic proximity wins (closest processor to recipient)
// Anyone with a phone can process via light client (~30 MB app)
LightClientSizeMB = 30 // ~30 MB app
BatteryPerDayActivePct = 3 // ~1-3pct battery/day active
)
// ProcessingMode is FCFS (§15) — never fee-auctioned
type ProcessingMode string
const (
ModeFCFS ProcessingMode = "FCFS" // First-come-first-served, not fee-auctioned
)
// Processor is a light client processing Pass-Acts (§15)
type Processor struct {
ProcessorID string `json:"processor_id" yaml:"processor_id"`
ReachID string `json:"reach_id" yaml:"reach_id"`
Latitude float64 `json:"latitude" yaml:"latitude"`
Longitude float64 `json:"longitude" yaml:"longitude"`
ActiveSince int64 `json:"active_since" yaml:"active_since"`
BlocksProcessed uint64 `json:"blocks_processed" yaml:"blocks_processed"`
}
// ProcessingJob is a Pass-Act awaiting processing
type ProcessingJob struct {
JobID string `json:"job_id" yaml:"job_id"`
SenderLat float64 `json:"sender_lat" yaml:"sender_lat"`
SenderLng float64 `json:"sender_lng" yaml:"sender_lng"`
RecipientLat float64 `json:"recipient_lat" yaml:"recipient_lat"`
RecipientLng float64 `json:"recipient_lng" yaml:"recipient_lng"`
AmountGrain int64 `json:"amount_grain" yaml:"amount_grain"`
Timestamp int64 `json:"timestamp" yaml:"timestamp"`
}
// SelectProcessorByProximity — geographic proximity wins (§15)
// In FCFS mode, the closest processor to the recipient processes the job
func SelectProcessorByProximity(recipientLat, recipientLng float64, processors []Processor) *Processor {
if len(processors) == 0 {
return nil
}
closest := &processors[0]
minDist := haversine(recipientLat, recipientLng, closest.Latitude, closest.Longitude)
for i := 1; i < len(processors); i++ {
dist := haversine(recipientLat, recipientLng, processors[i].Latitude, processors[i].Longitude)
if dist < minDist {
minDist = dist
closest = &processors[i]
}
}
return closest
}
// haversine computes distance between two coordinates (simplified)
func haversine(lat1, lng1, lat2, lng2 float64) float64 {
dlat := lat2 - lat1
dlng := lng2 - lng1
return dlat*dlat + dlng*dlng // squared distance (sufficient for comparison)
}
type Params struct{}
func DefaultParams() Params { return Params{} }
type GenesisState struct {
Params Params `json:"params" yaml:"params"`
Processors []Processor `json:"processors" yaml:"processors"`
}
func DefaultGenesisState() *GenesisState {
return &GenesisState{Params: DefaultParams(), Processors: []Processor{}}
}
func ValidateGenesis(bz json.RawMessage) error { return nil }