@@ -18,13 +18,19 @@ package main
18
18
19
19
import (
20
20
"bytes"
21
+ "context"
21
22
"fmt"
23
+ "io/ioutil"
22
24
"math/rand"
25
+ "os"
23
26
"sync"
24
27
"time"
25
28
26
29
"github.com/ethereum/go-ethereum/log"
27
30
"github.com/ethereum/go-ethereum/metrics"
31
+ "github.com/ethereum/go-ethereum/rpc"
32
+ "github.com/ethereum/go-ethereum/swarm/api"
33
+ "github.com/ethereum/go-ethereum/swarm/storage"
28
34
"github.com/ethereum/go-ethereum/swarm/testutil"
29
35
"github.com/pborman/uuid"
30
36
@@ -49,12 +55,75 @@ func uploadAndSyncCmd(ctx *cli.Context, tuid string) error {
49
55
case <- time .After (time .Duration (timeout ) * time .Second ):
50
56
metrics .GetOrRegisterCounter (fmt .Sprintf ("%s.timeout" , commandName ), nil ).Inc (1 )
51
57
58
+ e := fmt .Errorf ("timeout after %v sec" , timeout )
52
59
// trigger debug functionality on randomBytes
60
+ err := trackChunks (randomBytes [:])
61
+ if err != nil {
62
+ e = fmt .Errorf ("%v; triggerChunkDebug failed: %v" , e , err )
63
+ }
53
64
54
- return fmt . Errorf ( "timeout after %v sec" , timeout )
65
+ return e
55
66
}
56
67
}
57
68
69
+ func trackChunks (testData []byte ) error {
70
+ log .Warn ("Test timed out; running chunk debug sequence" )
71
+
72
+ addrs , err := getAllRefs (testData )
73
+ if err != nil {
74
+ return err
75
+ }
76
+ log .Trace ("All references retrieved" )
77
+
78
+ // has-chunks
79
+ for _ , host := range hosts {
80
+ httpHost := fmt .Sprintf ("ws://%s:%d" , host , 8546 )
81
+ log .Trace ("Calling `Has` on host" , "httpHost" , httpHost )
82
+ rpcClient , err := rpc .Dial (httpHost )
83
+ if err != nil {
84
+ log .Trace ("Error dialing host" , "err" , err )
85
+ return err
86
+ }
87
+ log .Trace ("rpc dial ok" )
88
+ var hasInfo []api.HasInfo
89
+ err = rpcClient .Call (& hasInfo , "bzz_has" , addrs )
90
+ if err != nil {
91
+ log .Trace ("Error calling host" , "err" , err )
92
+ return err
93
+ }
94
+ log .Trace ("rpc call ok" )
95
+ count := 0
96
+ for _ , info := range hasInfo {
97
+ if ! info .Has {
98
+ count ++
99
+ log .Error ("Host does not have chunk" , "host" , httpHost , "chunk" , info .Addr )
100
+ }
101
+ }
102
+ if count == 0 {
103
+ log .Info ("Host reported to have all chunks" , "host" , httpHost )
104
+ }
105
+ }
106
+ return nil
107
+ }
108
+
109
+ func getAllRefs (testData []byte ) (storage.AddressCollection , error ) {
110
+ log .Trace ("Getting all references for given root hash" )
111
+ datadir , err := ioutil .TempDir ("" , "chunk-debug" )
112
+ if err != nil {
113
+ return nil , fmt .Errorf ("unable to create temp dir: %v" , err )
114
+ }
115
+ defer os .RemoveAll (datadir )
116
+ fileStore , err := storage .NewLocalFileStore (datadir , make ([]byte , 32 ))
117
+ if err != nil {
118
+ return nil , err
119
+ }
120
+ ctx , cancel := context .WithTimeout (context .Background (), time .Duration (trackTimeout )* time .Second )
121
+ defer cancel ()
122
+
123
+ reader := bytes .NewReader (testData )
124
+ return fileStore .GetAllReferences (ctx , reader , false )
125
+ }
126
+
58
127
func uplaodAndSync (c * cli.Context , randomBytes []byte , tuid string ) error {
59
128
log .Info ("uploading to " + httpEndpoint (hosts [0 ])+ " and syncing" , "tuid" , tuid , "seed" , seed )
60
129
0 commit comments