erigon-pulse/consensus/bor/finality/whitelist/checkpoint.go
a 436493350e
Sentinel refactor (#8296)
1. changes sentinel to use an http-like interface

2. moves hexutil, crypto/blake2b, metrics packages to erigon-lib
2023-10-22 01:17:18 +02:00

53 lines
1.3 KiB
Go

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
}
var (
//Metrics for collecting the whitelisted milestone number
whitelistedCheckpointNumberMeter = metrics.GetOrCreateCounter("chain_checkpoint_latest", true)
//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")
)
// 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)
if res {
CheckpointChainMeter.Add(1)
} else {
CheckpointPeerMeter.Add(-1)
}
return res
}
func (w *checkpoint) Process(block uint64, hash common.Hash) {
w.finality.Lock()
defer w.finality.Unlock()
w.finality.Process(block, hash)
whitelistedCheckpointNumberMeter.Set(block)
}