mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd/swarm/swarm-snapshot: fixed bugs in snapshot creation binary
This commit is contained in:
parent
61531e188b
commit
96a50fd588
2 changed files with 9 additions and 5 deletions
|
|
@ -59,13 +59,16 @@ func createSnapshot(filename string, nodes int, services []string) (err error) {
|
||||||
log.Debug("create snapshot", "filename", filename, "nodes", nodes, "services", services)
|
log.Debug("create snapshot", "filename", filename, "nodes", nodes, "services", services)
|
||||||
|
|
||||||
sim := simulation.New(map[string]simulation.ServiceFunc{
|
sim := simulation.New(map[string]simulation.ServiceFunc{
|
||||||
"bzz": func(ctx *adapters.ServiceContext, b *sync.Map) (node.Service, func(), error) {
|
"bzz": func(ctx *adapters.ServiceContext, bucket *sync.Map) (node.Service, func(), error) {
|
||||||
addr := network.NewAddr(ctx.Config.Node())
|
addr := network.NewAddr(ctx.Config.Node())
|
||||||
kad := network.NewKademlia(addr.Over(), network.NewKadParams())
|
kad := network.NewKademlia(addr.Over(), network.NewKadParams())
|
||||||
hp := network.NewHiveParams()
|
hp := network.NewHiveParams()
|
||||||
hp.KeepAliveInterval = time.Duration(200) * time.Millisecond
|
hp.KeepAliveInterval = time.Duration(200) * time.Millisecond
|
||||||
hp.Discovery = true // discovery must be enabled when creating a snapshot
|
hp.Discovery = true // discovery must be enabled when creating a snapshot
|
||||||
|
|
||||||
|
// store the kademlia in the bucket, needed later in the WaitTillHealthy function
|
||||||
|
bucket.Store(simulation.BucketKeyKademlia, kad)
|
||||||
|
|
||||||
config := &network.BzzConfig{
|
config := &network.BzzConfig{
|
||||||
OverlayAddr: addr.Over(),
|
OverlayAddr: addr.Over(),
|
||||||
UnderlayAddr: addr.Under(),
|
UnderlayAddr: addr.Under(),
|
||||||
|
|
@ -76,12 +79,12 @@ func createSnapshot(filename string, nodes int, services []string) (err error) {
|
||||||
})
|
})
|
||||||
defer sim.Close()
|
defer sim.Close()
|
||||||
|
|
||||||
_, err = sim.AddNodes(nodes)
|
ids, err := sim.AddNodes(nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("add nodes: %v", err)
|
return fmt.Errorf("add nodes: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = sim.Net.ConnectNodesRing(nil)
|
err = sim.Net.ConnectNodesRing(ids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("connect nodes: %v", err)
|
return fmt.Errorf("connect nodes: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ func (s *Simulation) WaitTillHealthy(ctx context.Context) (ill map[enode.ID]*net
|
||||||
delete(ill, k)
|
delete(ill, k)
|
||||||
}
|
}
|
||||||
log.Debug("kademlia health check", "addr count", len(addrs))
|
log.Debug("kademlia health check", "addr count", len(addrs))
|
||||||
|
log.Debug("kademlias length", "len", len(kademlias))
|
||||||
for id, k := range kademlias {
|
for id, k := range kademlias {
|
||||||
//PeerPot for this node
|
//PeerPot for this node
|
||||||
addr := common.Bytes2Hex(k.BaseAddr())
|
addr := common.Bytes2Hex(k.BaseAddr())
|
||||||
|
|
@ -84,8 +85,8 @@ func (s *Simulation) WaitTillHealthy(ctx context.Context) (ill map[enode.ID]*net
|
||||||
// kademlias returns all Kademlia instances that are set
|
// kademlias returns all Kademlia instances that are set
|
||||||
// in simulation bucket.
|
// in simulation bucket.
|
||||||
func (s *Simulation) kademlias() (ks map[enode.ID]*network.Kademlia) {
|
func (s *Simulation) kademlias() (ks map[enode.ID]*network.Kademlia) {
|
||||||
//items := s.UpNodesItems(BucketKeyKademlia)
|
items := s.UpNodesItems(BucketKeyKademlia)
|
||||||
items := s.NodesItems(BucketKeyKademlia)
|
log.Debug("kademlia len items", "len", len(items))
|
||||||
ks = make(map[enode.ID]*network.Kademlia, len(items))
|
ks = make(map[enode.ID]*network.Kademlia, len(items))
|
||||||
for id, v := range items {
|
for id, v := range items {
|
||||||
k, ok := v.(*network.Kademlia)
|
k, ok := v.(*network.Kademlia)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue