2023-09-13 10:49:49 +00:00
|
|
|
package whitelist
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ledgerwatch/erigon-lib/common"
|
2023-10-09 18:13:31 +00:00
|
|
|
"github.com/ledgerwatch/erigon/consensus/bor/finality/rawdb"
|
2023-09-13 10:49:49 +00:00
|
|
|
"github.com/ledgerwatch/erigon/core/types"
|
2023-10-06 04:23:04 +00:00
|
|
|
"github.com/ledgerwatch/erigon/metrics"
|
2023-09-13 10:49:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type checkpoint struct {
|
|
|
|
finality[*rawdb.Checkpoint]
|
|
|
|
}
|
|
|
|
type checkpointService interface {
|
|
|
|
finalityService
|
|
|
|
}
|
|
|
|
|
2023-10-06 04:23:04 +00:00
|
|
|
var (
|
|
|
|
//Metrics for collecting the whitelisted milestone number
|
|
|
|
whitelistedCheckpointNumberMeter = metrics.GetOrCreateCounter("chain_checkpoint_latest", true)
|
2023-09-13 10:49:49 +00:00
|
|
|
|
2023-10-06 04:23:04 +00:00
|
|
|
//Metrics for collecting the number of invalid chains received
|
|
|
|
CheckpointChainMeter = metrics.GetOrCreateCounter("chain_checkpoint_isvalidchain")
|
|
|
|
|
|
|
|
//Metrics for collecting the number of valid peers received
|
|
|
|
CheckpointPeerMeter = metrics.GetOrCreateCounter("chain_checkpoint_isvalidpeer")
|
|
|
|
)
|
2023-09-13 10:49:49 +00:00
|
|
|
|
|
|
|
// IsValidChain checks the validity of chain by comparing it
|
|
|
|
// against the local checkpoint entry
|
|
|
|
func (w *checkpoint) IsValidChain(currentHeader uint64, chain []*types.Header) bool {
|
|
|
|
w.finality.RLock()
|
|
|
|
defer w.finality.RUnlock()
|
|
|
|
|
|
|
|
res := w.finality.IsValidChain(currentHeader, chain)
|
|
|
|
|
2023-10-06 04:23:04 +00:00
|
|
|
if res {
|
|
|
|
CheckpointChainMeter.Add(1)
|
|
|
|
} else {
|
|
|
|
CheckpointPeerMeter.Add(-1)
|
|
|
|
}
|
2023-09-13 10:49:49 +00:00
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *checkpoint) Process(block uint64, hash common.Hash) {
|
|
|
|
w.finality.Lock()
|
|
|
|
defer w.finality.Unlock()
|
|
|
|
|
|
|
|
w.finality.Process(block, hash)
|
|
|
|
|
2023-10-06 04:23:04 +00:00
|
|
|
whitelistedCheckpointNumberMeter.Set(block)
|
2023-09-13 10:49:49 +00:00
|
|
|
}
|