Skip to content

Commit 62d7688

Browse files
holisticodezelig
authored andcommitted
cmd/swarm/swarm-smoke: Trigger chunk debug on timeout (ethereum#19101)
* cmd/swarm/swarm-smoke: first version trigger has-chunks on timeout * cmd/swarm/swarm-smoke: finalize trigger to chunk debug * cmd/swarm/swarm-smoke: fixed httpEndpoint for trigger * cmd/swarm/swarm-smoke: port * cmd/swarm/swarm-smoke: ws not rpc * cmd/swarm/swarm-smoke: added debug output * cmd/swarm/swarm-smoke: addressed PR comments * cmd/swarm/swarm-smoke: renamed track-timeout and track-chunks
1 parent b6ce358 commit 62d7688

File tree

2 files changed

+86
-10
lines changed

2 files changed

+86
-10
lines changed

cmd/swarm/swarm-smoke/main.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ var (
3737
)
3838

3939
var (
40-
allhosts string
41-
hosts []string
42-
filesize int
43-
syncDelay int
44-
httpPort int
45-
wsPort int
46-
verbosity int
47-
timeout int
48-
single bool
40+
allhosts string
41+
hosts []string
42+
filesize int
43+
syncDelay int
44+
httpPort int
45+
wsPort int
46+
verbosity int
47+
timeout int
48+
single bool
49+
trackTimeout int
4950
)
5051

5152
func main() {
@@ -102,6 +103,12 @@ func main() {
102103
Usage: "whether to fetch content from a single node or from all nodes",
103104
Destination: &single,
104105
},
106+
cli.IntFlag{
107+
Name: "track-timeout",
108+
Value: 5,
109+
Usage: "timeout in seconds to wait for GetAllReferences to return",
110+
Destination: &trackTimeout,
111+
},
105112
}
106113

107114
app.Flags = append(app.Flags, []cli.Flag{

cmd/swarm/swarm-smoke/upload_and_sync.go

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ package main
1818

1919
import (
2020
"bytes"
21+
"context"
2122
"fmt"
23+
"io/ioutil"
2224
"math/rand"
25+
"os"
2326
"sync"
2427
"time"
2528

2629
"github.com/ethereum/go-ethereum/log"
2730
"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"
2834
"github.com/ethereum/go-ethereum/swarm/testutil"
2935
"github.com/pborman/uuid"
3036

@@ -49,12 +55,75 @@ func uploadAndSyncCmd(ctx *cli.Context, tuid string) error {
4955
case <-time.After(time.Duration(timeout) * time.Second):
5056
metrics.GetOrRegisterCounter(fmt.Sprintf("%s.timeout", commandName), nil).Inc(1)
5157

58+
e := fmt.Errorf("timeout after %v sec", timeout)
5259
// trigger debug functionality on randomBytes
60+
err := trackChunks(randomBytes[:])
61+
if err != nil {
62+
e = fmt.Errorf("%v; triggerChunkDebug failed: %v", e, err)
63+
}
5364

54-
return fmt.Errorf("timeout after %v sec", timeout)
65+
return e
5566
}
5667
}
5768

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+
58127
func uplaodAndSync(c *cli.Context, randomBytes []byte, tuid string) error {
59128
log.Info("uploading to "+httpEndpoint(hosts[0])+" and syncing", "tuid", tuid, "seed", seed)
60129

0 commit comments

Comments
 (0)