rm reorg param, re-use liveOnly

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
Sina Mahmoodi 2023-09-18 15:41:52 +02:00 committed by jsvisa
parent 743cd0bc32
commit be43dcebac

View file

@ -359,8 +359,12 @@ func (api *FilterAPI) histLogs(notifier notifier, rpcSub *rpc.Subscription, from
}() }()
var ( var (
delivered uint64 delivered uint64
liveOnly bool // liveOnly is true when all historical logs are delivered
reorged bool // and we switch-over to solely returning live logs.
liveOnly bool
// reorged is true when a reorg is detected.
// Question is if its enough to keep one flag (liveMode).
//reorged bool
staleHash common.Hash staleHash common.Hash
) )
for { for {
@ -379,20 +383,14 @@ func (api *FilterAPI) histLogs(notifier notifier, rpcSub *rpc.Subscription, from
if len(logs) == 0 { if len(logs) == 0 {
continue continue
} }
if liveOnly {
notifyLogsIf(notifier, rpcSub.ID, logs, nil)
continue
}
reorgBlock := logs[0].BlockNumber reorgBlock := logs[0].BlockNumber
if !reorged && reorgBlock <= delivered { if !liveOnly && reorgBlock <= delivered {
logger.Info("Reorg detected", "reorgBlock", reorgBlock, "delivered", delivered) logger.Info("Reorg detected", "reorgBlock", reorgBlock, "delivered", delivered)
reorged = true liveOnly = true
} }
if !reorged { if !liveOnly && logs[0].Removed && staleHash == (common.Hash{}) {
// Reorg in future. Remember fork point. // Reorg in future. Remember fork point.
if logs[0].Removed && staleHash == (common.Hash{}) { staleHash = logs[0].BlockHash
staleHash = logs[0].BlockHash
}
continue continue
} }
if logs[0].Removed { if logs[0].Removed {
@ -411,7 +409,7 @@ func (api *FilterAPI) histLogs(notifier notifier, rpcSub *rpc.Subscription, from
if len(logs) == 0 { if len(logs) == 0 {
continue continue
} }
if reorged { if liveOnly {
continue continue
} }
if logs[0].BlockHash == staleHash { if logs[0].BlockHash == staleHash {