Skip to content

Commit 2d956ed

Browse files
committed
fix: linter errors and added some more checks
1 parent 146d738 commit 2d956ed

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

pkg/node/node.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ func NewBee(
802802
}
803803
)
804804

805-
if !batchStoreExists && (networkID == mainnetNetworkID) {
805+
if !o.Resync && !batchStoreExists && (networkID == mainnetNetworkID) {
806806
chainBackend, err := NewSnapshotBlockHeightContractFilterer(logger)
807807
if err != nil {
808808
logger.Debug("failed to initialize batch snapshot chain backend", "error", err)
@@ -815,8 +815,11 @@ func NewBee(
815815
return nil, fmt.Errorf("init batch service: %w", err)
816816
}
817817

818-
if err := batchSvc.Start(ctx, postageSyncStart, initBatchState); err != nil {
819-
return nil, err
818+
err = batchSvc.Start(ctx, postageSyncStart, initBatchState)
819+
syncStatus.Store(true)
820+
if err != nil {
821+
syncErr.Store(err)
822+
return nil, fmt.Errorf("unable to start batch service: %w", err)
820823
}
821824

822825
if err := eventListener.Close(); err != nil {

pkg/node/snapshot.go

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2025 The Swarm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package node
26

37
import (
@@ -91,19 +95,17 @@ func (f *SnapshotBlockHeightContractFilterer) parseLogs(reader io.Reader) error
9195

9296
func (f *SnapshotBlockHeightContractFilterer) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error) {
9397
f.logger.Debug("filtering pre-loaded logs", "total_logs", len(f.loadedLogs), "query", query)
94-
95-
var filtered []types.Log
96-
98+
99+
filtered := make([]types.Log, 0, len(f.loadedLogs))
100+
97101
for _, log := range f.loadedLogs {
98-
// Filter by block range
99102
if query.FromBlock != nil && log.BlockNumber < query.FromBlock.Uint64() {
100103
continue
101104
}
102105
if query.ToBlock != nil && log.BlockNumber > query.ToBlock.Uint64() {
103106
continue
104107
}
105-
106-
// Filter by addresses
108+
107109
if len(query.Addresses) > 0 {
108110
addressMatch := false
109111
for _, addr := range query.Addresses {
@@ -116,48 +118,42 @@ func (f *SnapshotBlockHeightContractFilterer) FilterLogs(ctx context.Context, qu
116118
continue
117119
}
118120
}
119-
120-
// Filter by topics
121+
121122
if len(query.Topics) > 0 {
122123
topicMatch := true
123-
124-
// We have a max of 4 topics in Ethereum logs
124+
125125
for i := 0; i < len(query.Topics) && i < 4; i++ {
126-
// Skip if no filter for this topic position or empty filter array
127126
if i >= len(query.Topics) || len(query.Topics[i]) == 0 {
128127
continue
129128
}
130-
131-
// If we're filtering for this topic position but log doesn't have enough topics
129+
132130
if i >= len(log.Topics) {
133131
topicMatch = false
134132
break
135133
}
136-
137-
// Check if this topic matches any in the filter array for this position
134+
138135
hasMatch := false
139136
for _, topic := range query.Topics[i] {
140137
if log.Topics[i] == topic {
141138
hasMatch = true
142139
break
143140
}
144141
}
145-
142+
146143
if !hasMatch {
147144
topicMatch = false
148145
break
149146
}
150147
}
151-
148+
152149
if !topicMatch {
153150
continue
154151
}
155152
}
156-
157-
// If we got here, log passed all filters
153+
158154
filtered = append(filtered, log)
159155
}
160-
156+
161157
f.logger.Debug("filtered logs", "input_count", len(f.loadedLogs), "output_count", len(filtered))
162158
return filtered, nil
163159
}

0 commit comments

Comments
 (0)