snapshot_sync_test.go 19 KB

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