Skip to content

Commit 2207109

Browse files
authored
Merge pull request #648 from hyperweb-io/anmol/faucet-fix
fix: remove after log, no longer required, nor is it actually correct
2 parents ee7ab8a + bde8107 commit 2207109

File tree

5 files changed

+80
-26
lines changed

5 files changed

+80
-26
lines changed

.github/workflows/pr-tests.yaml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
8888
- name: Setup Test infra
8989
id: starship-action
90-
uses: hyperweb-io/starship-action@0.5.6
90+
uses: hyperweb-io/starship-action@c810d7760328a55474594aebaa7cb834e219f896
9191
with:
9292
config: ${{ env.CONFIG_FILE }}
9393
chart: ./starship/charts/devnet
@@ -101,23 +101,21 @@ jobs:
101101
TEST_CONFIG_FILE: ${{ env.CONFIG_FILE }}
102102
working-directory: starship
103103

104-
- name: Log if tests step fails
104+
- name: Log pods
105105
if: failure()
106106
run: |
107-
set -euxo pipefail
108-
109-
echo "Tests failed Logging everything"
110-
kubectl get pods -n $DEVNET_NAMESPACE
111-
112-
for i in `kubectl get po -n $DEVNET_NAMESPACE -o json | jq -r '.items[].metadata.name'`; do
107+
kubectl get pods -n $NAMESPACE
108+
for i in `kubectl get po -n $NAMESPACE -o json | jq -r '.items[].metadata.name'`; do
113109
echo "==================================================="
114110
echo "Logs for $i"
115-
kubectl describe pods $i -n $DEVNET_NAMESPACE
116-
kubectl logs $i -n $DEVNET_NAMESPACE --all-containers --tail=10000
111+
kubectl describe pods $i -n $NAMESPACE
112+
kubectl logs $i -n $NAMESPACE -c faucet --tail=10000
113+
echo "=====================Previous======================"
114+
kubectl logs $i -n $NAMESPACE -c faucet --previous --tail=10000
117115
echo "==================================================="
118116
done
119117
env:
120-
DEVNET_NAMESPACE: ${{ steps.starship-action.outputs.namespace }}
118+
NAMESPACE: ${{ steps.starship-action.outputs.namespace }}
121119

122120
# todo: change this to be post step of the action
123121
- name: Cleanup cluster

starship/charts/devnet/defaults.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ defaultFaucet:
993993
image: ghcr.io/cosmology-tech/starship/cosmjs-faucet:v0.31.1
994994
concurrency: 5
995995
starship:
996-
image: ghcr.io/hyperweb-io/starship/faucet:20250325-9eb67d7
996+
image: anmol1696/faucet:20250325-e08407f # debug faucet # ghcr.io/hyperweb-io/starship/faucet:20250325-9eb67d7
997997
concurrency: 5
998998

999999
defaultCometmock:

starship/charts/devnet/templates/chains/cosmos/genesis.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,9 @@ spec:
444444
445445
export | grep "FAUCET"
446446
447-
while [ $(curl -sw '%{http_code}' http://localhost:26657/status -o /dev/null) -ne 200 ]; do
448-
echo "Validator node does not seem to be ready. Waiting for it to start..."
449-
echo "Checking: http://localhost:26657/status"
450-
sleep 10;
447+
until [[ $(curl -s --connect-timeout 2 http://localhost:26657/status | jq -r '.result.sync_info.latest_block_height // "0"' | grep -E '^[1-9][0-9]*$') ]]; do
448+
echo "Validator node not ready or block height is still 0. Retrying in 5s..."
449+
sleep 5
451450
done
452451
453452
curl http://localhost:26657/status

starship/faucet/distributor.go

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"strings"
1010
"sync"
11+
"time"
1112

1213
"go.uber.org/zap"
1314

@@ -293,11 +294,44 @@ func (a *Account) queryTx(txhash string) (map[string]interface{}, error) {
293294
return txMap, nil
294295
}
295296

296-
// sendTokens performs chain binary send txn from account
297-
func (a *Account) sendTokens(address string, denom string, amount string) error {
297+
// queryTxWithRetry wraps queryTx with retry logic on tx "not found" error
298+
func (a *Account) queryTxWithRetry(txhash string, maxRetries int) (map[string]interface{}, error) {
299+
var (
300+
txMap map[string]interface{}
301+
err error
302+
)
303+
304+
for attempt := 1; attempt <= maxRetries; attempt++ {
305+
txMap, err = a.queryTx(txhash)
306+
if err == nil {
307+
return txMap, nil
308+
}
309+
310+
// Check explicitly for the "not found" error condition
311+
if strings.Contains(err.Error(), "not found") {
312+
a.logger.Warn("transaction not found, retrying",
313+
zap.String("txhash", txhash),
314+
zap.Int("attempt", attempt),
315+
zap.Int("maxRetries", maxRetries),
316+
)
317+
318+
// Sleep 2-3 seconds before retry
319+
time.Sleep(2*time.Second + time.Duration(rand.Intn(1000))*time.Millisecond)
320+
continue
321+
}
322+
323+
// If any other error occurs, return immediately
324+
return nil, err
325+
}
326+
327+
return nil, fmt.Errorf("transaction not found after retries: txhash: %s", txhash)
328+
}
329+
330+
// sendTokens performs chain binary send txn from account, returns txhash
331+
func (a *Account) sendTokens(address string, denom string, amount string) (string, error) {
298332
ok := a.mu.TryLock()
299333
if !ok {
300-
return fmt.Errorf("account %s busy: %w", a, ErrResourceInUse)
334+
return "", fmt.Errorf("account %s busy: %w", a, ErrResourceInUse)
301335
}
302336
defer a.mu.Unlock()
303337

@@ -306,29 +340,35 @@ func (a *Account) sendTokens(address string, denom string, amount string) error
306340
output, err := runCommand(cmdStr)
307341
if err != nil {
308342
a.logger.Error("send token failed", zap.String("cmd", cmdStr), zap.Error(err))
309-
return err
343+
return "", err
310344
}
311345
a.logger.Info("ran cmd to send tokens", zap.String("cmd", cmdStr), zap.String("stdout", string(output)))
312346

313347
// Find the JSON line and extract the txhash using a regular expression
314348
txhash, err := extractTxHash(string(output))
315349
if err != nil {
316350
a.logger.Error("failed to extract txhash", zap.Error(err))
317-
return err
351+
return "", err
318352
}
319353

320354
a.logger.Debug("send tokens txhash", zap.String("txhash", txhash))
321355

356+
return txhash, nil
357+
}
358+
359+
// confirmTx checks if the tx has gone through by checking the event
360+
func (a *Account) confirmTx(txhash, eventType string) error {
322361
// query tx to check if the tx was successful
323-
txMap, err := a.queryTx(txhash)
362+
txMap, err := a.queryTxWithRetry(txhash, 3)
324363
if err != nil {
325364
return err
326365
}
327366

328367
// check if the tx has the event
329-
err = hasEvent(txMap, "transfer")
368+
err = hasEvent(txMap, eventType)
330369
if err != nil {
331-
a.logger.Error("transfer event not found in tx",
370+
a.logger.Error("event not found in tx",
371+
zap.String("eventType", eventType),
332372
zap.String("txhash", txhash),
333373
zap.Any("txMap", txMap))
334374
return err
@@ -339,16 +379,23 @@ func (a *Account) sendTokens(address string, denom string, amount string) error
339379

340380
// SendTokens will perform send tokens with retries based on errors
341381
func (a *Account) SendTokens(address string, denom string, amount string) error {
342-
err := a.sendTokens(address, denom, amount)
382+
txHash, err := a.sendTokens(address, denom, amount)
343383
if err == nil {
344384
return nil
345385
}
386+
346387
if strings.Contains(err.Error(), "account sequence mismatch") {
347388
// retry sendTokens
348389
a.logger.Debug("got account sequence missmatch error, retrying send tokens recursively")
349390
return a.SendTokens(address, denom, amount)
350391
}
351392

393+
// Confirm tx has gone through
394+
err = a.confirmTx(txHash, "transfer")
395+
if err != nil {
396+
return err
397+
}
398+
352399
return err
353400
}
354401

starship/tests/e2e/faucet_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7+
"io"
78
"net/http"
89
urlpkg "net/url"
910
"strconv"
@@ -131,9 +132,17 @@ func (s *TestSuite) creditAccount(chain *Chain, addr, denom string) error {
131132
if err != nil {
132133
return err
133134
}
135+
134136
if resp.StatusCode != 200 {
135-
return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
137+
bodyBytes, err := io.ReadAll(resp.Body)
138+
if err != nil {
139+
return fmt.Errorf("unexpected status code: %d, and failed to read response body: %w", resp.StatusCode, err)
140+
}
141+
defer resp.Body.Close()
142+
143+
return fmt.Errorf("unexpected status code: %d, response: %s", resp.StatusCode, string(bodyBytes))
136144
}
145+
137146
return nil
138147
}
139148

@@ -186,6 +195,7 @@ func (s *TestSuite) TestFaucet_Credit_MultipleRequests() {
186195
// Send multiple requests
187196
numRequests := 3
188197
for i := 0; i < numRequests; i++ {
198+
s.T().Log("crediting account for request: ", i)
189199
err := s.creditAccount(chain, addr, denom)
190200
s.Require().NoError(err)
191201
}

0 commit comments

Comments
 (0)