Skip to content

Commit 64161e3

Browse files
committed
fixes
1 parent fb8fd83 commit 64161e3

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

cmd/push-validator/root_cobra.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,14 @@ func handlePostStartFlow(cfg config.Config, p *ui.Printer) bool {
781781
}
782782

783783
// Create reconfigure function to get fresh trust parameters
784-
reconfigFunc := func() error {
784+
// Takes attempt number to rotate through fullnode RPCs on each retry
785+
reconfigFunc := func(attempt int) error {
785786
fmt.Println(p.Colors.Info(" Refreshing state sync parameters..."))
786787
svc := bootstrap.New()
787788
return svc.ReconfigureStateSync(context.Background(), bootstrap.Options{
788789
HomeDir: cfg.HomeDir,
789-
SnapshotRPC: "", // Use default fullnode RPC
790+
SnapshotRPC: "", // Empty = rotate through fullnode RPCs based on attempt
791+
Attempt: attempt,
790792
})
791793
}
792794

internal/bootstrap/bootstrap.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Options struct {
4040
BinPath string // pchaind path
4141
SnapshotRPC string // e.g., https://donut.rpc.push.org
4242
Progress func(string) // optional callback for progress messages
43+
Attempt int // Retry attempt number (0-based), used to rotate fullnode RPCs
4344
}
4445

4546
type Service interface {
@@ -199,7 +200,7 @@ func (s *svc) Init(ctx context.Context, opts Options) error {
199200
TrustHash: tp.Hash,
200201
RPCServers: rpcServers,
201202
TrustPeriod: "336h0m0s",
202-
ChunkFetchers: 12, // Aggressive: 3x parallel downloads for faster sync
203+
ChunkFetchers: 6, // Balanced: 3 per peer when 2 peers share snapshot
203204
ChunkRequestTimeout: "60m0s", // Extended timeout for slow/congested networks
204205
DiscoveryTime: "90s", // More time to discover all available snapshots
205206
}); err != nil {
@@ -217,14 +218,19 @@ func (s *svc) Init(ctx context.Context, opts Options) error {
217218

218219
// ReconfigureStateSync updates state sync configuration with fresh trust parameters.
219220
// This is used during retry logic when the previous sync attempt failed.
221+
// The Attempt field in opts is used to rotate through fullnode RPCs, so each retry
222+
// uses a different peer's snapshot (which may be available from multiple peers).
220223
func (s *svc) ReconfigureStateSync(ctx context.Context, opts Options) error {
221224
if opts.HomeDir == "" {
222225
return errors.New("HomeDir required")
223226
}
224227

225228
snapshotRPC := opts.SnapshotRPC
226229
if snapshotRPC == "" {
227-
snapshotRPC = fullnodeRPCs[0]
230+
// Rotate through fullnode RPCs based on attempt number
231+
// This ensures each retry uses a different peer's trust height/snapshot
232+
rpcIndex := opts.Attempt % len(fullnodeRPCs)
233+
snapshotRPC = fullnodeRPCs[rpcIndex]
228234
}
229235

230236
// Compute fresh trust parameters
@@ -245,7 +251,7 @@ func (s *svc) ReconfigureStateSync(ctx context.Context, opts Options) error {
245251
TrustHash: tp.Hash,
246252
RPCServers: rpcServers,
247253
TrustPeriod: "336h0m0s",
248-
ChunkFetchers: 12,
254+
ChunkFetchers: 6,
249255
ChunkRequestTimeout: "60m0s",
250256
DiscoveryTime: "90s",
251257
})

internal/sync/monitor.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,9 @@ func Run(ctx context.Context, opts Options) error {
674674
// RetryOptions extends Options with retry configuration
675675
type RetryOptions struct {
676676
Options
677-
MaxRetries int // Max retry attempts (default: 3)
678-
ResetFunc func() error // Function to reset data before retry
679-
ReconfigFunc func() error // Function to reconfigure state sync params
677+
MaxRetries int // Max retry attempts (default: 3)
678+
ResetFunc func() error // Function to reset data before retry
679+
ReconfigFunc func(int) error // Function to reconfigure state sync params (receives attempt number)
680680
}
681681

682682
// RunWithRetry runs sync monitoring with automatic retry on failure
@@ -702,8 +702,9 @@ func RunWithRetry(ctx context.Context, opts RetryOptions) error {
702702
}
703703

704704
// Optionally reconfigure (e.g., get fresh trust height)
705+
// Pass attempt number to allow RPC rotation on each retry
705706
if opts.ReconfigFunc != nil {
706-
_ = opts.ReconfigFunc() // Best-effort reconfigure
707+
_ = opts.ReconfigFunc(attempt) // Best-effort reconfigure
707708
}
708709

709710
// Wait before retry (exponential backoff: 10s, 20s, 30s)

0 commit comments

Comments
 (0)