Skip to content

Commit 3bcc070

Browse files
committed
chore: rework some comments
1 parent 599b852 commit 3bcc070

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

rolling-shutter/medley/chainsync/chainsegment/chain.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ func (bc *ChainSegment) DiffLeftAligned(other *ChainSegment) (remove, update *Ch
225225
}
226226
if oldHeader == nil {
227227
updated = append(updated, newHeader)
228-
// XXX: is just checking the hash sufficient?
229-
// sanity check also the blocknum + parent hash chain?
228+
// TODO: sanity check also the blocknum + parent hash chain
229+
// so that we are sure that we have consecutive segments.
230230
} else if oldHeader.Hash().Cmp(newHeader.Hash()) != 0 {
231231
removed = append(removed, oldHeader)
232232
updated = append(updated, newHeader)

rolling-shutter/medley/chainsync/syncer/fetch.go

-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ func (f *Fetcher) FetchAndHandle(ctx context.Context, update ChainUpdateContext)
186186
query := ethereum.FilterQuery{
187187
Addresses: f.addresses,
188188
Topics: f.topics,
189-
//FIXME: oes this work when from and to are the same?
190189
FromBlock: update.Append.Earliest().Number,
191190
ToBlock: update.Append.Latest().Number,
192191
}
@@ -210,7 +209,6 @@ func (f *Fetcher) FetchAndHandle(ctx context.Context, update ChainUpdateContext)
210209
var result error
211210
f.syncMux.RLock()
212211
for _, h := range f.contractEventHandlers {
213-
// TODO: copy all the logs?
214212
handler := h
215213
wg.Add(1)
216214
go func() {

rolling-shutter/medley/chainsync/syncer/loop.go

+27-14
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,12 @@ func (f *Fetcher) handlerSync(ctx context.Context) (success bool, err error) {
3535
return success, err
3636
}
3737
if errors.Is(err, ErrEmpy) {
38-
// no chain-cache present yet,
39-
// just set the chain-update without
38+
// no chain-cache present yet, just set the chain-update without
4039
// checking for reorgs
41-
// FIXME: here we could incorporate a starting block
42-
// option, fetch the starting block, and set this in
43-
// the cache and sync from there.
4440
removedSegment = nil
4541
updatedSegment = f.chainUpdate
4642
log.Trace().Msg("internal chain cache empty, setting updated chain segment")
4743
} else if err != nil {
48-
//TODO: what to do on db error?
4944
success = false
5045
return success, err
5146
} else {
@@ -63,6 +58,11 @@ func (f *Fetcher) handlerSync(ctx context.Context) (success bool, err error) {
6358
return success, fmt.Errorf("chain-update difference too big: %w", errUint64Overflow)
6459
}
6560
diff := diffBig.Uint64()
61+
queryBlocks := MaxRequestBlockRange
62+
// cap the extend range at the diff to the update to not overshoot
63+
if diff < uint64(queryBlocks) {
64+
queryBlocks = int(diff)
65+
}
6666

6767
// we are not synced to the chain-update
6868
// so first construct an update to the right of the synced chain
@@ -86,20 +86,33 @@ func (f *Fetcher) handlerSync(ctx context.Context) (success bool, err error) {
8686
}
8787
removedSegment = nil
8888
success = false
89-
result, errr := syncedChain.UpdateLatest(ctx, f.ethClient, f.chainUpdate)
90-
result, errr := syncedChain.UpdateLatest(ctx, f.client, f.chainUpdate)
91-
if errr != nil {
92-
// TODO: for ErrUpdateBlockTooFarInPast this should shut down the
93-
// client? Since we can't really play back a reorg that reaches too far in the past.
94-
// Now as long as the chain-cache eviction policy is not agressive (easily doable)
95-
log.Error().Err(err).Msg("error updating chain")
89+
} else {
90+
result, updateErr := syncedChain.UpdateLatest(ctx, f.ethClient, f.chainUpdate)
91+
success = true
92+
if updateErr != nil {
93+
log.Error().Err(err).Msg("error updating chain with latest segment")
94+
if errors.Is(err, chainsegment.ErrUpdateBlockTooFarInPast) {
95+
//TODO: what should we do on 'ErrUpdateBlockTooFarInPast'?
96+
// We can't provide handler calls with the same accuracy of
97+
// information on the potentially "removed" chain-segment,
98+
// since our chain-cache does not have the full old chain segment
99+
// in it's storage anymore, and especially the block-hash
100+
// of the reorged away chain is not present anymore.
101+
// The client should probably panic with a critical log error.
102+
// In general this is very unlikely when the chain-cache capacity is
103+
// larger than the most unlikely, still realistic reorg-size.
104+
// However the described condition might currently occur during
105+
// initial syncing, when the block-cache is not filled to capacity
106+
// yet.
107+
log.Warn().Err(err).Msg("received a reorg that pre-dates the internal chain-cache." +
108+
" ignoring chain-update for now, but this condition might be irrecoverable")
109+
}
96110
err = updateErr
97111
// Now as long as the chain-cache eviction policy is not aggressive (easily doable)
98112
removedSegment = result.RemovedSegment
99113
updatedSegment = result.UpdatedSegment
100114
// we will process the whole segment of the chain update
101115
f.chainUpdate = nil
102-
success = true
103116
}
104117
}
105118

0 commit comments

Comments
 (0)