mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
swarm/network: Hardwire network minproxbinsize in swarm sim
This commit is contained in:
parent
eec6ba7f22
commit
89e7259149
7 changed files with 20 additions and 31 deletions
|
|
@ -19,7 +19,6 @@ package simulation
|
|||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"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()
|
||||
addrs := make([][]byte, 0, len(kademlias))
|
||||
// TODO verify that all kademlias have same params
|
||||
var minProxBinSize int
|
||||
for _, k := range kademlias {
|
||||
if minProxBinSize == 0 {
|
||||
minProxBinSize = k.MinProxBinSize
|
||||
}
|
||||
addrs = append(addrs, k.BaseAddr())
|
||||
}
|
||||
if minProxBinSize == 0 {
|
||||
return nil, errors.New("no kademlias in simulation")
|
||||
}
|
||||
ppmap = network.NewPeerPotMap(minProxBinSize, addrs)
|
||||
ppmap = network.NewPeerPotMap(s.minProxBinSize, addrs)
|
||||
|
||||
// Wait for healthy Kademlia on every node before checking files
|
||||
ticker := time.NewTicker(200 * time.Millisecond)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/ethereum/go-ethereum/p2p/simulations"
|
||||
"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.
|
||||
|
|
@ -49,6 +50,7 @@ type Simulation struct {
|
|||
shutdownWG sync.WaitGroup
|
||||
done chan struct{}
|
||||
mu sync.RWMutex
|
||||
minProxBinSize int
|
||||
|
||||
httpSrv *http.Server //attach a HTTP server via SimulationOptions
|
||||
handler *simulations.Server //HTTP handler for the server
|
||||
|
|
@ -65,8 +67,7 @@ type Simulation struct {
|
|||
// after network shutdown.
|
||||
type ServiceFunc func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error)
|
||||
|
||||
// New creates a new Simulation instance with new
|
||||
// simulations.Network initialized with provided services.
|
||||
// New creates a new simulation instance
|
||||
// Services map must have unique keys as service names and
|
||||
// every ServiceFunc must return a node.Service of the unique type.
|
||||
// This restriction is required by node.Node.Start() function
|
||||
|
|
@ -75,6 +76,7 @@ func New(services map[string]ServiceFunc) (s *Simulation) {
|
|||
s = &Simulation{
|
||||
buckets: make(map[enode.ID]*sync.Map),
|
||||
done: make(chan struct{}),
|
||||
minProxBinSize: network.NewKadParams().MinProxBinSize,
|
||||
}
|
||||
|
||||
adapterServices := make(map[string]adapters.ServiceFunc, len(services))
|
||||
|
|
|
|||
|
|
@ -266,8 +266,7 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul
|
|||
wg.Wait()
|
||||
log.Debug(fmt.Sprintf("nodes: %v", len(addrs)))
|
||||
// construct the peer pot, so that kademlia health can be checked
|
||||
k := network.NewKademlia(addrs[0], network.NewKadParams())
|
||||
ppmap := network.NewPeerPotMap(k, addrs)
|
||||
ppmap := network.NewPeerPotMap(network.NewKadParams().MinProxBinSize, addrs)
|
||||
check := func(ctx context.Context, id enode.ID) (bool, error) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
|
@ -403,8 +402,7 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
|
|||
}
|
||||
healthy := &network.Health{}
|
||||
addr := id.String()
|
||||
k := network.NewKademlia(common.Hex2Bytes(addr), network.NewKadParams())
|
||||
ppmap := network.NewPeerPotMap(k, addrs)
|
||||
ppmap := network.NewPeerPotMap(network.NewKadParams().MinProxBinSize, addrs)
|
||||
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
|
||||
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)
|
||||
}
|
||||
healthy := &network.Health{}
|
||||
k := network.NewKademlia(addrs[0], network.NewKadParams())
|
||||
ppmap := network.NewPeerPotMap(k, addrs)
|
||||
ppmap := network.NewPeerPotMap(network.NewKadParams().MinProxBinSize, addrs)
|
||||
|
||||
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
|
||||
return false, fmt.Errorf("error getting node health: %s", err)
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ var (
|
|||
|
||||
chunkSize = 4096
|
||||
pof = network.Pof
|
||||
minProxBinSize = network.NewKadParams().MinProxBinSize
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -453,7 +453,6 @@ func TestDeliveryFromNodes(t *testing.T) {
|
|||
}
|
||||
|
||||
func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck bool) {
|
||||
|
||||
sim := simulation.New(map[string]simulation.ServiceFunc{
|
||||
"streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
|
||||
node := ctx.Config.Node()
|
||||
|
|
|
|||
|
|
@ -246,7 +246,6 @@ simulation's `action` function.
|
|||
The snapshot should have 'streamer' in its service list.
|
||||
*/
|
||||
func runRetrievalTest(chunkCount int, nodeCount int) error {
|
||||
|
||||
sim := simulation.New(retrievalSimServiceMap)
|
||||
defer sim.Close()
|
||||
|
||||
|
|
|
|||
|
|
@ -182,7 +182,6 @@ func streamerFunc(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Servic
|
|||
}
|
||||
|
||||
func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) {
|
||||
|
||||
sim := simulation.New(simServiceMap)
|
||||
defer sim.Close()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue