swarm/network: Hardwire network minproxbinsize in swarm sim

This commit is contained in:
lash 2018-12-17 22:22:18 +01:00
parent eec6ba7f22
commit 89e7259149
7 changed files with 20 additions and 31 deletions

View file

@ -19,7 +19,6 @@ package simulation
import ( import (
"context" "context"
"encoding/hex" "encoding/hex"
"errors"
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -41,17 +40,10 @@ func (s *Simulation) WaitTillHealthy(ctx context.Context) (ill map[enode.ID]*net
kademlias := s.kademlias() kademlias := s.kademlias()
addrs := make([][]byte, 0, len(kademlias)) addrs := make([][]byte, 0, len(kademlias))
// TODO verify that all kademlias have same params // TODO verify that all kademlias have same params
var minProxBinSize int
for _, k := range kademlias { for _, k := range kademlias {
if minProxBinSize == 0 {
minProxBinSize = k.MinProxBinSize
}
addrs = append(addrs, k.BaseAddr()) addrs = append(addrs, k.BaseAddr())
} }
if minProxBinSize == 0 { ppmap = network.NewPeerPotMap(s.minProxBinSize, addrs)
return nil, errors.New("no kademlias in simulation")
}
ppmap = network.NewPeerPotMap(minProxBinSize, addrs)
// Wait for healthy Kademlia on every node before checking files // Wait for healthy Kademlia on every node before checking files
ticker := time.NewTicker(200 * time.Millisecond) ticker := time.NewTicker(200 * time.Millisecond)

View file

@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/simulations" "github.com/ethereum/go-ethereum/p2p/simulations"
"github.com/ethereum/go-ethereum/p2p/simulations/adapters" "github.com/ethereum/go-ethereum/p2p/simulations/adapters"
"github.com/ethereum/go-ethereum/swarm/network"
) )
// Common errors that are returned by functions in this package. // Common errors that are returned by functions in this package.
@ -42,13 +43,14 @@ type Simulation struct {
// of p2p/simulations.Network. // of p2p/simulations.Network.
Net *simulations.Network Net *simulations.Network
serviceNames []string serviceNames []string
cleanupFuncs []func() cleanupFuncs []func()
buckets map[enode.ID]*sync.Map buckets map[enode.ID]*sync.Map
pivotNodeID *enode.ID pivotNodeID *enode.ID
shutdownWG sync.WaitGroup shutdownWG sync.WaitGroup
done chan struct{} done chan struct{}
mu sync.RWMutex mu sync.RWMutex
minProxBinSize int
httpSrv *http.Server //attach a HTTP server via SimulationOptions httpSrv *http.Server //attach a HTTP server via SimulationOptions
handler *simulations.Server //HTTP handler for the server handler *simulations.Server //HTTP handler for the server
@ -65,16 +67,16 @@ type Simulation struct {
// after network shutdown. // after network shutdown.
type ServiceFunc func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) type ServiceFunc func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error)
// New creates a new Simulation instance with new // New creates a new simulation instance
// simulations.Network initialized with provided services.
// Services map must have unique keys as service names and // Services map must have unique keys as service names and
// every ServiceFunc must return a node.Service of the unique type. // every ServiceFunc must return a node.Service of the unique type.
// This restriction is required by node.Node.Start() function // This restriction is required by node.Node.Start() function
// which is used to start node.Service returned by ServiceFunc. // which is used to start node.Service returned by ServiceFunc.
func New(services map[string]ServiceFunc) (s *Simulation) { func New(services map[string]ServiceFunc) (s *Simulation) {
s = &Simulation{ s = &Simulation{
buckets: make(map[enode.ID]*sync.Map), buckets: make(map[enode.ID]*sync.Map),
done: make(chan struct{}), done: make(chan struct{}),
minProxBinSize: network.NewKadParams().MinProxBinSize,
} }
adapterServices := make(map[string]adapters.ServiceFunc, len(services)) adapterServices := make(map[string]adapters.ServiceFunc, len(services))

View file

@ -266,8 +266,7 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul
wg.Wait() wg.Wait()
log.Debug(fmt.Sprintf("nodes: %v", len(addrs))) log.Debug(fmt.Sprintf("nodes: %v", len(addrs)))
// construct the peer pot, so that kademlia health can be checked // construct the peer pot, so that kademlia health can be checked
k := network.NewKademlia(addrs[0], network.NewKadParams()) ppmap := network.NewPeerPotMap(network.NewKadParams().MinProxBinSize, addrs)
ppmap := network.NewPeerPotMap(k, addrs)
check := func(ctx context.Context, id enode.ID) (bool, error) { check := func(ctx context.Context, id enode.ID) (bool, error) {
select { select {
case <-ctx.Done(): case <-ctx.Done():
@ -403,8 +402,7 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
} }
healthy := &network.Health{} healthy := &network.Health{}
addr := id.String() addr := id.String()
k := network.NewKademlia(common.Hex2Bytes(addr), network.NewKadParams()) ppmap := network.NewPeerPotMap(network.NewKadParams().MinProxBinSize, addrs)
ppmap := network.NewPeerPotMap(k, addrs)
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil { if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
return fmt.Errorf("error getting node health: %s", err) return fmt.Errorf("error getting node health: %s", err)
} }
@ -492,8 +490,7 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
return false, fmt.Errorf("error getting node client: %s", err) return false, fmt.Errorf("error getting node client: %s", err)
} }
healthy := &network.Health{} healthy := &network.Health{}
k := network.NewKademlia(addrs[0], network.NewKadParams()) ppmap := network.NewPeerPotMap(network.NewKadParams().MinProxBinSize, addrs)
ppmap := network.NewPeerPotMap(k, addrs)
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil { if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
return false, fmt.Errorf("error getting node health: %s", err) return false, fmt.Errorf("error getting node health: %s", err)

View file

@ -55,8 +55,9 @@ var (
bucketKeyDelivery = simulation.BucketKey("delivery") bucketKeyDelivery = simulation.BucketKey("delivery")
bucketKeyRegistry = simulation.BucketKey("registry") bucketKeyRegistry = simulation.BucketKey("registry")
chunkSize = 4096 chunkSize = 4096
pof = network.Pof pof = network.Pof
minProxBinSize = network.NewKadParams().MinProxBinSize
) )
func init() { func init() {

View file

@ -453,7 +453,6 @@ func TestDeliveryFromNodes(t *testing.T) {
} }
func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck bool) { func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck bool) {
sim := simulation.New(map[string]simulation.ServiceFunc{ sim := simulation.New(map[string]simulation.ServiceFunc{
"streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) { "streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
node := ctx.Config.Node() node := ctx.Config.Node()

View file

@ -246,7 +246,6 @@ simulation's `action` function.
The snapshot should have 'streamer' in its service list. The snapshot should have 'streamer' in its service list.
*/ */
func runRetrievalTest(chunkCount int, nodeCount int) error { func runRetrievalTest(chunkCount int, nodeCount int) error {
sim := simulation.New(retrievalSimServiceMap) sim := simulation.New(retrievalSimServiceMap)
defer sim.Close() defer sim.Close()

View file

@ -182,7 +182,6 @@ func streamerFunc(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Servic
} }
func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) { func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) {
sim := simulation.New(simServiceMap) sim := simulation.New(simServiceMap)
defer sim.Close() defer sim.Close()