erigon-pulse/consensus/bor/finality/whitelist/checkpoint.go

50 lines
1.2 KiB
Go
Raw Normal View History

package whitelist
import (
"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/metrics"
"github.com/ledgerwatch/erigon/consensus/bor/finality/rawdb"
"github.com/ledgerwatch/erigon/core/types"
)
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.GetOrCreateGauge("chain_checkpoint_latest")
2023-10-06 04:23:04 +00:00
//Metrics for collecting the number of invalid chains received
checkpointChainMeter = metrics.GetOrCreateGauge("chain_checkpoint_isvalidchain")
2023-10-06 04:23:04 +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.Inc()
2023-10-06 04:23:04 +00:00
} else {
checkpointChainMeter.Dec()
2023-10-06 04:23:04 +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)
whitelistedCheckpointNumberMeter.SetUint64(block)
}