snapshot_sync_test.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. // Copyright 2018 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package stream
  17. import (
  18. "context"
  19. crand "crypto/rand"
  20. "fmt"
  21. "io"
  22. "os"
  23. "runtime"
  24. "sync"
  25. "testing"
  26. "time"
  27. "github.com/ethereum/go-ethereum/common"
  28. "github.com/ethereum/go-ethereum/log"
  29. "github.com/ethereum/go-ethereum/node"
  30. "github.com/ethereum/go-ethereum/p2p"
  31. "github.com/ethereum/go-ethereum/p2p/enode"
  32. "github.com/ethereum/go-ethereum/p2p/simulations"
  33. "github.com/ethereum/go-ethereum/p2p/simulations/adapters"
  34. "github.com/ethereum/go-ethereum/swarm/network"
  35. "github.com/ethereum/go-ethereum/swarm/network/simulation"
  36. "github.com/ethereum/go-ethereum/swarm/pot"
  37. "github.com/ethereum/go-ethereum/swarm/state"
  38. "github.com/ethereum/go-ethereum/swarm/storage"
  39. mockdb "github.com/ethereum/go-ethereum/swarm/storage/mock/db"
  40. )
  41. const MaxTimeout = 600
  42. type synctestConfig struct {
  43. addrs [][]byte
  44. hashes []storage.Address
  45. idToChunksMap map[enode.ID][]int
  46. //chunksToNodesMap map[string][]int
  47. addrToIDMap map[string]enode.ID
  48. }
  49. const (
  50. // EventTypeNode is the type of event emitted when a node is either
  51. // created, started or stopped
  52. EventTypeChunkCreated simulations.EventType = "chunkCreated"
  53. EventTypeChunkOffered simulations.EventType = "chunkOffered"
  54. EventTypeChunkWanted simulations.EventType = "chunkWanted"
  55. EventTypeChunkDelivered simulations.EventType = "chunkDelivered"
  56. EventTypeChunkArrived simulations.EventType = "chunkArrived"
  57. EventTypeSimTerminated simulations.EventType = "simTerminated"
  58. )
  59. // Tests in this file should not request chunks from peers.
  60. // This function will panic indicating that there is a problem if request has been made.
  61. func dummyRequestFromPeers(_ context.Context, req *network.Request) (*enode.ID, chan struct{}, error) {
  62. panic(fmt.Sprintf("unexpected request: address %s, source %s", req.Addr.String(), req.Source.String()))
  63. }
  64. //This test is a syncing test for nodes.
  65. //One node is randomly selected to be the pivot node.
  66. //A configurable number of chunks and nodes can be
  67. //provided to the test, the number of chunks is uploaded
  68. //to the pivot node, and we check that nodes get the chunks
  69. //they are expected to store based on the syncing protocol.
  70. //Number of chunks and nodes can be provided via commandline too.
  71. func TestSyncingViaGlobalSync(t *testing.T) {
  72. if runtime.GOOS == "darwin" && os.Getenv("TRAVIS") == "true" {
  73. t.Skip("Flaky on mac on travis")
  74. }
  75. //if nodes/chunks have been provided via commandline,
  76. //run the tests with these values
  77. if *nodes != 0 && *chunks != 0 {
  78. log.Info(fmt.Sprintf("Running test with %d chunks and %d nodes...", *chunks, *nodes))
  79. testSyncingViaGlobalSync(t, *chunks, *nodes)
  80. } else {
  81. var nodeCnt []int
  82. var chnkCnt []int
  83. //if the `longrunning` flag has been provided
  84. //run more test combinations
  85. if *longrunning {
  86. chnkCnt = []int{1, 8, 32, 256, 1024}
  87. nodeCnt = []int{16, 32, 64, 128, 256}
  88. } else {
  89. //default test
  90. chnkCnt = []int{4, 32}
  91. nodeCnt = []int{32, 16}
  92. }
  93. for _, chnk := range chnkCnt {
  94. for _, n := range nodeCnt {
  95. log.Info(fmt.Sprintf("Long running test with %d chunks and %d nodes...", chnk, n))
  96. testSyncingViaGlobalSync(t, chnk, n)
  97. }
  98. }
  99. }
  100. }
  101. func TestSyncingViaDirectSubscribe(t *testing.T) {
  102. if runtime.GOOS == "darwin" && os.Getenv("TRAVIS") == "true" {
  103. t.Skip("Flaky on mac on travis")
  104. }
  105. //if nodes/chunks have been provided via commandline,
  106. //run the tests with these values
  107. if *nodes != 0 && *chunks != 0 {
  108. log.Info(fmt.Sprintf("Running test with %d chunks and %d nodes...", *chunks, *nodes))
  109. err := testSyncingViaDirectSubscribe(t, *chunks, *nodes)
  110. if err != nil {
  111. t.Fatal(err)
  112. }
  113. } else {
  114. var nodeCnt []int
  115. var chnkCnt []int
  116. //if the `longrunning` flag has been provided
  117. //run more test combinations
  118. if *longrunning {
  119. chnkCnt = []int{1, 8, 32, 256, 1024}
  120. nodeCnt = []int{32, 16}
  121. } else {
  122. //default test
  123. chnkCnt = []int{4, 32}
  124. nodeCnt = []int{32, 16}
  125. }
  126. for _, chnk := range chnkCnt {
  127. for _, n := range nodeCnt {
  128. log.Info(fmt.Sprintf("Long running test with %d chunks and %d nodes...", chnk, n))
  129. err := testSyncingViaDirectSubscribe(t, chnk, n)
  130. if err != nil {
  131. t.Fatal(err)
  132. }
  133. }
  134. }
  135. }
  136. }
  137. var simServiceMap = map[string]simulation.ServiceFunc{
  138. "streamer": streamerFunc,
  139. }
  140. func streamerFunc(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
  141. n := ctx.Config.Node()
  142. addr := network.NewAddr(n)
  143. store, datadir, err := createTestLocalStorageForID(n.ID(), addr)
  144. if err != nil {
  145. return nil, nil, err
  146. }
  147. bucket.Store(bucketKeyStore, store)
  148. localStore := store.(*storage.LocalStore)
  149. netStore, err := storage.NewNetStore(localStore, nil)
  150. if err != nil {
  151. return nil, nil, err
  152. }
  153. kad := network.NewKademlia(addr.Over(), network.NewKadParams())
  154. delivery := NewDelivery(kad, netStore)
  155. netStore.NewNetFetcherFunc = network.NewFetcherFactory(dummyRequestFromPeers, true).New
  156. r := NewRegistry(addr.ID(), delivery, netStore, state.NewInmemoryStore(), &RegistryOptions{
  157. DoSync: true,
  158. SyncUpdateDelay: 3 * time.Second,
  159. })
  160. bucket.Store(bucketKeyRegistry, r)
  161. cleanup = func() {
  162. os.RemoveAll(datadir)
  163. netStore.Close()
  164. r.Close()
  165. }
  166. return r, cleanup, nil
  167. }
  168. func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) {
  169. sim := simulation.New(simServiceMap)
  170. defer sim.Close()
  171. log.Info("Initializing test config")
  172. conf := &synctestConfig{}
  173. //map of discover ID to indexes of chunks expected at that ID
  174. conf.idToChunksMap = make(map[enode.ID][]int)
  175. //map of overlay address to discover ID
  176. conf.addrToIDMap = make(map[string]enode.ID)
  177. //array where the generated chunk hashes will be stored
  178. conf.hashes = make([]storage.Address, 0)
  179. err := sim.UploadSnapshot(fmt.Sprintf("testing/snapshot_%d.json", nodeCount))
  180. if err != nil {
  181. t.Fatal(err)
  182. }
  183. ctx, cancelSimRun := context.WithTimeout(context.Background(), 2*time.Minute)
  184. defer cancelSimRun()
  185. if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
  186. t.Fatal(err)
  187. }
  188. disconnections := sim.PeerEvents(
  189. context.Background(),
  190. sim.NodeIDs(),
  191. simulation.NewPeerEventsFilter().Type(p2p.PeerEventTypeDrop),
  192. )
  193. go func() {
  194. for d := range disconnections {
  195. log.Error("peer drop", "node", d.NodeID, "peer", d.Event.Peer)
  196. t.Fatal("unexpected disconnect")
  197. cancelSimRun()
  198. }
  199. }()
  200. result := runSim(conf, ctx, sim, chunkCount)
  201. if result.Error != nil {
  202. t.Fatal(result.Error)
  203. }
  204. log.Info("Simulation ended")
  205. }
  206. func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulation, chunkCount int) simulation.Result {
  207. return sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) error {
  208. nodeIDs := sim.UpNodeIDs()
  209. for _, n := range nodeIDs {
  210. //get the kademlia overlay address from this ID
  211. a := n.Bytes()
  212. //append it to the array of all overlay addresses
  213. conf.addrs = append(conf.addrs, a)
  214. //the proximity calculation is on overlay addr,
  215. //the p2p/simulations check func triggers on enode.ID,
  216. //so we need to know which overlay addr maps to which nodeID
  217. conf.addrToIDMap[string(a)] = n
  218. }
  219. //get the node at that index
  220. //this is the node selected for upload
  221. node := sim.RandomUpNode()
  222. item, ok := sim.NodeItem(node.ID, bucketKeyStore)
  223. if !ok {
  224. return fmt.Errorf("No localstore")
  225. }
  226. lstore := item.(*storage.LocalStore)
  227. hashes, err := uploadFileToSingleNodeStore(node.ID, chunkCount, lstore)
  228. if err != nil {
  229. return err
  230. }
  231. for _, h := range hashes {
  232. evt := &simulations.Event{
  233. Type: EventTypeChunkCreated,
  234. Node: sim.Net.GetNode(node.ID),
  235. Data: h.String(),
  236. }
  237. sim.Net.Events().Send(evt)
  238. }
  239. conf.hashes = append(conf.hashes, hashes...)
  240. mapKeysToNodes(conf)
  241. // File retrieval check is repeated until all uploaded files are retrieved from all nodes
  242. // or until the timeout is reached.
  243. var gDir string
  244. var globalStore *mockdb.GlobalStore
  245. if *useMockStore {
  246. gDir, globalStore, err = createGlobalStore()
  247. if err != nil {
  248. return fmt.Errorf("Something went wrong; using mockStore enabled but globalStore is nil")
  249. }
  250. defer func() {
  251. os.RemoveAll(gDir)
  252. err := globalStore.Close()
  253. if err != nil {
  254. log.Error("Error closing global store! %v", "err", err)
  255. }
  256. }()
  257. }
  258. REPEAT:
  259. for {
  260. for _, id := range nodeIDs {
  261. //for each expected chunk, check if it is in the local store
  262. localChunks := conf.idToChunksMap[id]
  263. for _, ch := range localChunks {
  264. //get the real chunk by the index in the index array
  265. chunk := conf.hashes[ch]
  266. log.Trace(fmt.Sprintf("node has chunk: %s:", chunk))
  267. //check if the expected chunk is indeed in the localstore
  268. var err error
  269. if *useMockStore {
  270. //use the globalStore if the mockStore should be used; in that case,
  271. //the complete localStore stack is bypassed for getting the chunk
  272. _, err = globalStore.Get(common.BytesToAddress(id.Bytes()), chunk)
  273. } else {
  274. //use the actual localstore
  275. item, ok := sim.NodeItem(id, bucketKeyStore)
  276. if !ok {
  277. return fmt.Errorf("Error accessing localstore")
  278. }
  279. lstore := item.(*storage.LocalStore)
  280. _, err = lstore.Get(ctx, chunk)
  281. }
  282. if err != nil {
  283. log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id))
  284. // Do not get crazy with logging the warn message
  285. time.Sleep(500 * time.Millisecond)
  286. continue REPEAT
  287. }
  288. evt := &simulations.Event{
  289. Type: EventTypeChunkArrived,
  290. Node: sim.Net.GetNode(id),
  291. Data: chunk.String(),
  292. }
  293. sim.Net.Events().Send(evt)
  294. log.Debug(fmt.Sprintf("Chunk %s IS FOUND for id %s", chunk, id))
  295. }
  296. }
  297. return nil
  298. }
  299. })
  300. }
  301. /*
  302. The test generates the given number of chunks
  303. For every chunk generated, the nearest node addresses
  304. are identified, we verify that the nodes closer to the
  305. chunk addresses actually do have the chunks in their local stores.
  306. The test loads a snapshot file to construct the swarm network,
  307. assuming that the snapshot file identifies a healthy
  308. kademlia network. The snapshot should have 'streamer' in its service list.
  309. */
  310. func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int) error {
  311. sim := simulation.New(map[string]simulation.ServiceFunc{
  312. "streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
  313. n := ctx.Config.Node()
  314. addr := network.NewAddr(n)
  315. store, datadir, err := createTestLocalStorageForID(n.ID(), addr)
  316. if err != nil {
  317. return nil, nil, err
  318. }
  319. bucket.Store(bucketKeyStore, store)
  320. localStore := store.(*storage.LocalStore)
  321. netStore, err := storage.NewNetStore(localStore, nil)
  322. if err != nil {
  323. return nil, nil, err
  324. }
  325. kad := network.NewKademlia(addr.Over(), network.NewKadParams())
  326. delivery := NewDelivery(kad, netStore)
  327. netStore.NewNetFetcherFunc = network.NewFetcherFactory(dummyRequestFromPeers, true).New
  328. r := NewRegistry(addr.ID(), delivery, netStore, state.NewInmemoryStore(), nil)
  329. bucket.Store(bucketKeyRegistry, r)
  330. fileStore := storage.NewFileStore(netStore, storage.NewFileStoreParams())
  331. bucket.Store(bucketKeyFileStore, fileStore)
  332. cleanup = func() {
  333. os.RemoveAll(datadir)
  334. netStore.Close()
  335. r.Close()
  336. }
  337. return r, cleanup, nil
  338. },
  339. })
  340. defer sim.Close()
  341. ctx, cancelSimRun := context.WithTimeout(context.Background(), 2*time.Minute)
  342. defer cancelSimRun()
  343. conf := &synctestConfig{}
  344. //map of discover ID to indexes of chunks expected at that ID
  345. conf.idToChunksMap = make(map[enode.ID][]int)
  346. //map of overlay address to discover ID
  347. conf.addrToIDMap = make(map[string]enode.ID)
  348. //array where the generated chunk hashes will be stored
  349. conf.hashes = make([]storage.Address, 0)
  350. err := sim.UploadSnapshot(fmt.Sprintf("testing/snapshot_%d.json", nodeCount))
  351. if err != nil {
  352. return err
  353. }
  354. if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
  355. return err
  356. }
  357. disconnections := sim.PeerEvents(
  358. context.Background(),
  359. sim.NodeIDs(),
  360. simulation.NewPeerEventsFilter().Type(p2p.PeerEventTypeDrop),
  361. )
  362. go func() {
  363. for d := range disconnections {
  364. log.Error("peer drop", "node", d.NodeID, "peer", d.Event.Peer)
  365. t.Fatal("unexpected disconnect")
  366. cancelSimRun()
  367. }
  368. }()
  369. result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) error {
  370. nodeIDs := sim.UpNodeIDs()
  371. for _, n := range nodeIDs {
  372. //get the kademlia overlay address from this ID
  373. a := n.Bytes()
  374. //append it to the array of all overlay addresses
  375. conf.addrs = append(conf.addrs, a)
  376. //the proximity calculation is on overlay addr,
  377. //the p2p/simulations check func triggers on enode.ID,
  378. //so we need to know which overlay addr maps to which nodeID
  379. conf.addrToIDMap[string(a)] = n
  380. }
  381. var subscriptionCount int
  382. filter := simulation.NewPeerEventsFilter().Type(p2p.PeerEventTypeMsgRecv).Protocol("stream").MsgCode(4)
  383. eventC := sim.PeerEvents(ctx, nodeIDs, filter)
  384. for j, node := range nodeIDs {
  385. log.Trace(fmt.Sprintf("Start syncing subscriptions: %d", j))
  386. //start syncing!
  387. item, ok := sim.NodeItem(node, bucketKeyRegistry)
  388. if !ok {
  389. return fmt.Errorf("No registry")
  390. }
  391. registry := item.(*Registry)
  392. var cnt int
  393. cnt, err = startSyncing(registry, conf)
  394. if err != nil {
  395. return err
  396. }
  397. //increment the number of subscriptions we need to wait for
  398. //by the count returned from startSyncing (SYNC subscriptions)
  399. subscriptionCount += cnt
  400. }
  401. for e := range eventC {
  402. if e.Error != nil {
  403. return e.Error
  404. }
  405. subscriptionCount--
  406. if subscriptionCount == 0 {
  407. break
  408. }
  409. }
  410. //select a random node for upload
  411. node := sim.RandomUpNode()
  412. item, ok := sim.NodeItem(node.ID, bucketKeyStore)
  413. if !ok {
  414. return fmt.Errorf("No localstore")
  415. }
  416. lstore := item.(*storage.LocalStore)
  417. hashes, err := uploadFileToSingleNodeStore(node.ID, chunkCount, lstore)
  418. if err != nil {
  419. return err
  420. }
  421. conf.hashes = append(conf.hashes, hashes...)
  422. mapKeysToNodes(conf)
  423. if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
  424. return err
  425. }
  426. var gDir string
  427. var globalStore *mockdb.GlobalStore
  428. if *useMockStore {
  429. gDir, globalStore, err = createGlobalStore()
  430. if err != nil {
  431. return fmt.Errorf("Something went wrong; using mockStore enabled but globalStore is nil")
  432. }
  433. defer os.RemoveAll(gDir)
  434. }
  435. // File retrieval check is repeated until all uploaded files are retrieved from all nodes
  436. // or until the timeout is reached.
  437. REPEAT:
  438. for {
  439. for _, id := range nodeIDs {
  440. //for each expected chunk, check if it is in the local store
  441. localChunks := conf.idToChunksMap[id]
  442. for _, ch := range localChunks {
  443. //get the real chunk by the index in the index array
  444. chunk := conf.hashes[ch]
  445. log.Trace(fmt.Sprintf("node has chunk: %s:", chunk))
  446. //check if the expected chunk is indeed in the localstore
  447. var err error
  448. if *useMockStore {
  449. //use the globalStore if the mockStore should be used; in that case,
  450. //the complete localStore stack is bypassed for getting the chunk
  451. _, err = globalStore.Get(common.BytesToAddress(id.Bytes()), chunk)
  452. } else {
  453. //use the actual localstore
  454. item, ok := sim.NodeItem(id, bucketKeyStore)
  455. if !ok {
  456. return fmt.Errorf("Error accessing localstore")
  457. }
  458. lstore := item.(*storage.LocalStore)
  459. _, err = lstore.Get(ctx, chunk)
  460. }
  461. if err != nil {
  462. log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id))
  463. // Do not get crazy with logging the warn message
  464. time.Sleep(500 * time.Millisecond)
  465. continue REPEAT
  466. }
  467. log.Debug(fmt.Sprintf("Chunk %s IS FOUND for id %s", chunk, id))
  468. }
  469. }
  470. return nil
  471. }
  472. })
  473. if result.Error != nil {
  474. return result.Error
  475. }
  476. log.Info("Simulation ended")
  477. return nil
  478. }
  479. //the server func to start syncing
  480. //issues `RequestSubscriptionMsg` to peers, based on po, by iterating over
  481. //the kademlia's `EachBin` function.
  482. //returns the number of subscriptions requested
  483. func startSyncing(r *Registry, conf *synctestConfig) (int, error) {
  484. var err error
  485. kad := r.delivery.kad
  486. subCnt := 0
  487. //iterate over each bin and solicit needed subscription to bins
  488. kad.EachBin(r.addr[:], pof, 0, func(conn *network.Peer, po int) bool {
  489. //identify begin and start index of the bin(s) we want to subscribe to
  490. subCnt++
  491. err = r.RequestSubscription(conf.addrToIDMap[string(conn.Address())], NewStream("SYNC", FormatSyncBinKey(uint8(po)), true), NewRange(0, 0), High)
  492. if err != nil {
  493. log.Error(fmt.Sprintf("Error in RequestSubsciption! %v", err))
  494. return false
  495. }
  496. return true
  497. })
  498. return subCnt, nil
  499. }
  500. //map chunk keys to addresses which are responsible
  501. func mapKeysToNodes(conf *synctestConfig) {
  502. nodemap := make(map[string][]int)
  503. //build a pot for chunk hashes
  504. np := pot.NewPot(nil, 0)
  505. indexmap := make(map[string]int)
  506. for i, a := range conf.addrs {
  507. indexmap[string(a)] = i
  508. np, _, _ = pot.Add(np, a, pof)
  509. }
  510. var kadMinProxSize = 2
  511. ppmap := network.NewPeerPotMap(kadMinProxSize, conf.addrs)
  512. //for each address, run EachNeighbour on the chunk hashes pot to identify closest nodes
  513. log.Trace(fmt.Sprintf("Generated hash chunk(s): %v", conf.hashes))
  514. for i := 0; i < len(conf.hashes); i++ {
  515. var a []byte
  516. np.EachNeighbour([]byte(conf.hashes[i]), pof, func(val pot.Val, po int) bool {
  517. // take the first address
  518. a = val.([]byte)
  519. return false
  520. })
  521. nns := ppmap[common.Bytes2Hex(a)].NNSet
  522. nns = append(nns, a)
  523. for _, p := range nns {
  524. nodemap[string(p)] = append(nodemap[string(p)], i)
  525. }
  526. }
  527. for addr, chunks := range nodemap {
  528. //this selects which chunks are expected to be found with the given node
  529. conf.idToChunksMap[conf.addrToIDMap[addr]] = chunks
  530. }
  531. log.Debug(fmt.Sprintf("Map of expected chunks by ID: %v", conf.idToChunksMap))
  532. }
  533. //upload a file(chunks) to a single local node store
  534. func uploadFileToSingleNodeStore(id enode.ID, chunkCount int, lstore *storage.LocalStore) ([]storage.Address, error) {
  535. log.Debug(fmt.Sprintf("Uploading to node id: %s", id))
  536. fileStore := storage.NewFileStore(lstore, storage.NewFileStoreParams())
  537. size := chunkSize
  538. var rootAddrs []storage.Address
  539. for i := 0; i < chunkCount; i++ {
  540. rk, wait, err := fileStore.Store(context.TODO(), io.LimitReader(crand.Reader, int64(size)), int64(size), false)
  541. if err != nil {
  542. return nil, err
  543. }
  544. err = wait(context.TODO())
  545. if err != nil {
  546. return nil, err
  547. }
  548. rootAddrs = append(rootAddrs, (rk))
  549. }
  550. return rootAddrs, nil
  551. }