mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
remove lru package alias (#7251)
This commit is contained in:
parent
a42d362cbd
commit
6339a3c9d1
@ -4,8 +4,8 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
|
||||
lru2 "github.com/hashicorp/golang-lru/v2"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
@ -25,19 +25,19 @@ const (
|
||||
type BeaconState struct {
|
||||
// State fields
|
||||
genesisTime uint64
|
||||
genesisValidatorsRoot libcommon.Hash
|
||||
genesisValidatorsRoot common.Hash
|
||||
slot uint64
|
||||
fork *cltypes.Fork
|
||||
latestBlockHeader *cltypes.BeaconBlockHeader
|
||||
blockRoots [blockRootsLength]libcommon.Hash
|
||||
stateRoots [stateRootsLength]libcommon.Hash
|
||||
historicalRoots []libcommon.Hash
|
||||
blockRoots [blockRootsLength]common.Hash
|
||||
stateRoots [stateRootsLength]common.Hash
|
||||
historicalRoots []common.Hash
|
||||
eth1Data *cltypes.Eth1Data
|
||||
eth1DataVotes []*cltypes.Eth1Data
|
||||
eth1DepositIndex uint64
|
||||
validators []*cltypes.Validator
|
||||
balances []uint64
|
||||
randaoMixes [randoMixesLength]libcommon.Hash
|
||||
randaoMixes [randoMixesLength]common.Hash
|
||||
slashings [slashingsLength]uint64
|
||||
previousEpochParticipation cltypes.ParticipationFlagsList
|
||||
currentEpochParticipation cltypes.ParticipationFlagsList
|
||||
@ -64,13 +64,13 @@ type BeaconState struct {
|
||||
touchedLeaves map[StateLeafIndex]bool // Maps each leaf to whether they were touched or not.
|
||||
publicKeyIndicies map[[48]byte]uint64
|
||||
// Caches
|
||||
activeValidatorsCache *lru2.Cache[uint64, []uint64]
|
||||
committeeCache *lru2.Cache[[16]byte, []uint64]
|
||||
shuffledSetsCache *lru2.Cache[libcommon.Hash, []uint64]
|
||||
activeValidatorsCache *lru.Cache[uint64, []uint64]
|
||||
committeeCache *lru.Cache[[16]byte, []uint64]
|
||||
shuffledSetsCache *lru.Cache[common.Hash, []uint64]
|
||||
totalActiveBalanceCache *uint64
|
||||
totalActiveBalanceRootCache uint64
|
||||
proposerIndex *uint64
|
||||
previousStateRoot libcommon.Hash
|
||||
previousStateRoot common.Hash
|
||||
// Configs
|
||||
beaconConfig *clparams.BeaconChainConfig
|
||||
// Changesets
|
||||
@ -85,7 +85,7 @@ func New(cfg *clparams.BeaconChainConfig) *BeaconState {
|
||||
return state
|
||||
}
|
||||
|
||||
func preparateRootsForHashing(roots []libcommon.Hash) [][32]byte {
|
||||
func preparateRootsForHashing(roots []common.Hash) [][32]byte {
|
||||
ret := make([][32]byte, len(roots))
|
||||
for i := range roots {
|
||||
copy(ret[i][:], roots[i][:])
|
||||
@ -235,13 +235,13 @@ func (b *BeaconState) initBeaconState() error {
|
||||
b.publicKeyIndicies[validator.PublicKey] = uint64(i)
|
||||
}
|
||||
var err error
|
||||
if b.activeValidatorsCache, err = lru2.New[uint64, []uint64](5); err != nil {
|
||||
if b.activeValidatorsCache, err = lru.New[uint64, []uint64](5); err != nil {
|
||||
return err
|
||||
}
|
||||
if b.shuffledSetsCache, err = lru2.New[libcommon.Hash, []uint64](25); err != nil {
|
||||
if b.shuffledSetsCache, err = lru.New[common.Hash, []uint64](25); err != nil {
|
||||
return err
|
||||
}
|
||||
if b.committeeCache, err = lru2.New[[16]byte, []uint64](256); err != nil {
|
||||
if b.committeeCache, err = lru.New[[16]byte, []uint64](256); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := b._updateProposerIndex(); err != nil {
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
lru2 "github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/hashicorp/golang-lru/v2"
|
||||
common2 "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/dbg"
|
||||
"github.com/ledgerwatch/erigon-lib/gointerfaces/remote"
|
||||
@ -50,7 +50,7 @@ type LightClient struct {
|
||||
highestProcessedRoot common2.Hash // Highest processed ETH2 block root.
|
||||
lastEth2ParentRoot common2.Hash // Last ETH2 Parent root.
|
||||
finalizedEth1Hash common2.Hash
|
||||
recentHashesCache *lru2.Cache[common2.Hash, struct{}]
|
||||
recentHashesCache *lru.Cache[common2.Hash, struct{}]
|
||||
rpc *rpc.BeaconRpcP2P
|
||||
// Either execution server or client
|
||||
execution remote.ETHBACKENDServer
|
||||
@ -62,7 +62,7 @@ func NewLightClient(ctx context.Context, genesisConfig *clparams.GenesisConfig,
|
||||
execution remote.ETHBACKENDServer, executionClient remote.ETHBACKENDClient, sentinel sentinel.SentinelClient,
|
||||
highestSeen uint64, verbose bool) (*LightClient, error) {
|
||||
|
||||
recentHashesCache, err := lru2.New[common2.Hash, struct{}](maxRecentHashes)
|
||||
recentHashesCache, err := lru.New[common2.Hash, struct{}](maxRecentHashes)
|
||||
rpc := rpc.NewBeaconRpcP2P(ctx, sentinel, beaconConfig, genesisConfig)
|
||||
return &LightClient{
|
||||
ctx: ctx,
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
lru2 "github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/libp2p/go-libp2p/core/host"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
@ -40,26 +40,26 @@ type Peer struct {
|
||||
}
|
||||
|
||||
type Peers struct {
|
||||
badPeers *lru2.Cache[peer.ID, int] // Keep track of bad peers
|
||||
penalties *lru2.Cache[peer.ID, int] // Keep track on how many penalties a peer accumulated, PeerId => penalties
|
||||
peerRecord *lru2.Cache[peer.ID, Peer] // Keep track of our peer statuses
|
||||
badPeers *lru.Cache[peer.ID, int] // Keep track of bad peers
|
||||
penalties *lru.Cache[peer.ID, int] // Keep track on how many penalties a peer accumulated, PeerId => penalties
|
||||
peerRecord *lru.Cache[peer.ID, Peer] // Keep track of our peer statuses
|
||||
host host.Host
|
||||
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func New(host host.Host) *Peers {
|
||||
badPeers, err := lru2.New[peer.ID, int](maxBadPeers)
|
||||
badPeers, err := lru.New[peer.ID, int](maxBadPeers)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
penalties, err := lru2.New[peer.ID, int](maxBadPeers)
|
||||
penalties, err := lru.New[peer.ID, int](maxBadPeers)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
peerRecord, err := lru2.New[peer.ID, Peer](maxPeerRecordSize)
|
||||
peerRecord, err := lru.New[peer.ID, Peer](maxPeerRecordSize)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
lru2 "github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
@ -294,14 +294,14 @@ type AuRa struct {
|
||||
}
|
||||
|
||||
type GasLimitOverride struct {
|
||||
cache *lru2.Cache[libcommon.Hash, *uint256.Int]
|
||||
cache *lru.Cache[libcommon.Hash, *uint256.Int]
|
||||
}
|
||||
|
||||
func NewGasLimitOverride() *GasLimitOverride {
|
||||
// The number of recent block hashes for which the gas limit override is memoized.
|
||||
const GasLimitOverrideCacheCapacity = 10
|
||||
|
||||
cache, err := lru2.New[libcommon.Hash, *uint256.Int](GasLimitOverrideCacheCapacity)
|
||||
cache, err := lru.New[libcommon.Hash, *uint256.Int](GasLimitOverrideCacheCapacity)
|
||||
if err != nil {
|
||||
panic("error creating prefetching cache for blocks")
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
lru2 "github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/hashicorp/golang-lru/v2"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
|
||||
@ -412,8 +412,8 @@ func (q *ReportQueue) truncate() {
|
||||
// nolint
|
||||
type ValidatorSafeContract struct {
|
||||
contractAddress libcommon.Address
|
||||
validators *lru2.Cache[libcommon.Hash, *SimpleList] // RwLock<MemoryLruCache<H256, SimpleList>>,
|
||||
reportQueue ReportQueue //Mutex<ReportQueue>,
|
||||
validators *lru.Cache[libcommon.Hash, *SimpleList] // RwLock<MemoryLruCache<H256, SimpleList>>,
|
||||
reportQueue ReportQueue //Mutex<ReportQueue>,
|
||||
// The block number where we resent the queued reports last time.
|
||||
resentReportsInBlock atomic.Uint64
|
||||
// If set, this is the block number at which the consensus engine switches from AuRa to AuRa
|
||||
@ -426,7 +426,7 @@ type ValidatorSafeContract struct {
|
||||
|
||||
func NewValidatorSafeContract(contractAddress libcommon.Address, posdaoTransition *uint64, client client) *ValidatorSafeContract {
|
||||
const MemoizeCapacity = 500
|
||||
c, err := lru2.New[libcommon.Hash, *SimpleList](MemoizeCapacity)
|
||||
c, err := lru.New[libcommon.Hash, *SimpleList](MemoizeCapacity)
|
||||
if err != nil {
|
||||
panic("error creating ValidatorSafeContract cache")
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
lru2 "github.com/hashicorp/golang-lru/v2"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/xsleonard/go-merkle"
|
||||
"golang.org/x/crypto/sha3"
|
||||
|
||||
@ -30,7 +30,7 @@ var (
|
||||
type API struct {
|
||||
chain consensus.ChainHeaderReader
|
||||
bor *Bor
|
||||
rootHashCache *lru2.ARCCache[string, string]
|
||||
rootHashCache *lru.ARCCache[string, string]
|
||||
}
|
||||
|
||||
// GetSnapshot retrieves the state snapshot at a given block.
|
||||
@ -53,15 +53,15 @@ func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error) {
|
||||
type BlockSigners struct {
|
||||
Signers []difficultiesKV
|
||||
Diff int
|
||||
Author libcommon.Address
|
||||
Author common.Address
|
||||
}
|
||||
|
||||
type difficultiesKV struct {
|
||||
Signer libcommon.Address
|
||||
Signer common.Address
|
||||
Difficulty uint64
|
||||
}
|
||||
|
||||
func rankMapDifficulties(values map[libcommon.Address]uint64) []difficultiesKV {
|
||||
func rankMapDifficulties(values map[common.Address]uint64) []difficultiesKV {
|
||||
ss := make([]difficultiesKV, 0, len(values))
|
||||
for k, v := range values {
|
||||
ss = append(ss, difficultiesKV{k, v})
|
||||
@ -78,7 +78,7 @@ func rankMapDifficulties(values map[libcommon.Address]uint64) []difficultiesKV {
|
||||
func (api *API) GetSnapshotProposerSequence(number *rpc.BlockNumber) (BlockSigners, error) {
|
||||
snapNumber := *number - 1
|
||||
|
||||
var difficulties = make(map[libcommon.Address]uint64)
|
||||
var difficulties = make(map[common.Address]uint64)
|
||||
|
||||
snap, err := api.GetSnapshot(&snapNumber)
|
||||
|
||||
@ -117,19 +117,19 @@ func (api *API) GetSnapshotProposerSequence(number *rpc.BlockNumber) (BlockSigne
|
||||
}
|
||||
|
||||
// GetSnapshotProposer retrieves the in-turn signer at a given block.
|
||||
func (api *API) GetSnapshotProposer(number *rpc.BlockNumber) (libcommon.Address, error) {
|
||||
func (api *API) GetSnapshotProposer(number *rpc.BlockNumber) (common.Address, error) {
|
||||
*number -= 1
|
||||
snap, err := api.GetSnapshot(number)
|
||||
|
||||
if err != nil {
|
||||
return libcommon.Address{}, err
|
||||
return common.Address{}, err
|
||||
}
|
||||
|
||||
return snap.ValidatorSet.GetProposer().Address, nil
|
||||
}
|
||||
|
||||
// GetAuthor retrieves the author a block.
|
||||
func (api *API) GetAuthor(number *rpc.BlockNumber) (*libcommon.Address, error) {
|
||||
func (api *API) GetAuthor(number *rpc.BlockNumber) (*common.Address, error) {
|
||||
// Retrieve the requested block number (or current if none requested)
|
||||
var header *types.Header
|
||||
if number == nil || *number == rpc.LatestBlockNumber {
|
||||
@ -148,7 +148,7 @@ func (api *API) GetAuthor(number *rpc.BlockNumber) (*libcommon.Address, error) {
|
||||
}
|
||||
|
||||
// GetSnapshotAtHash retrieves the state snapshot at a given block.
|
||||
func (api *API) GetSnapshotAtHash(hash libcommon.Hash) (*Snapshot, error) {
|
||||
func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error) {
|
||||
header := api.chain.GetHeaderByHash(hash)
|
||||
if header == nil {
|
||||
return nil, errUnknownBlock
|
||||
@ -158,7 +158,7 @@ func (api *API) GetSnapshotAtHash(hash libcommon.Hash) (*Snapshot, error) {
|
||||
}
|
||||
|
||||
// GetSigners retrieves the list of authorized signers at the specified block.
|
||||
func (api *API) GetSigners(number *rpc.BlockNumber) ([]libcommon.Address, error) {
|
||||
func (api *API) GetSigners(number *rpc.BlockNumber) ([]common.Address, error) {
|
||||
// Retrieve the requested block number (or current if none requested)
|
||||
var header *types.Header
|
||||
if number == nil || *number == rpc.LatestBlockNumber {
|
||||
@ -181,7 +181,7 @@ func (api *API) GetSigners(number *rpc.BlockNumber) ([]libcommon.Address, error)
|
||||
}
|
||||
|
||||
// GetSignersAtHash retrieves the list of authorized signers at the specified block.
|
||||
func (api *API) GetSignersAtHash(hash libcommon.Hash) ([]libcommon.Address, error) {
|
||||
func (api *API) GetSignersAtHash(hash common.Hash) ([]common.Address, error) {
|
||||
header := api.chain.GetHeaderByHash(hash)
|
||||
if header == nil {
|
||||
return nil, errUnknownBlock
|
||||
@ -197,10 +197,10 @@ func (api *API) GetSignersAtHash(hash libcommon.Hash) ([]libcommon.Address, erro
|
||||
}
|
||||
|
||||
// GetCurrentProposer gets the current proposer
|
||||
func (api *API) GetCurrentProposer() (libcommon.Address, error) {
|
||||
func (api *API) GetCurrentProposer() (common.Address, error) {
|
||||
snap, err := api.GetSnapshot(nil)
|
||||
if err != nil {
|
||||
return libcommon.Address{}, err
|
||||
return common.Address{}, err
|
||||
}
|
||||
|
||||
return snap.ValidatorSet.GetProposer().Address, nil
|
||||
@ -289,7 +289,7 @@ func (api *API) GetRootHash(start uint64, end uint64) (string, error) {
|
||||
func (api *API) initializeRootHashCache() error {
|
||||
var err error
|
||||
if api.rootHashCache == nil {
|
||||
api.rootHashCache, err = lru2.NewARC[string, string](10)
|
||||
api.rootHashCache, err = lru.NewARC[string, string](10)
|
||||
}
|
||||
|
||||
return err
|
||||
|
@ -5,9 +5,9 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
lru2 "github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon/consensus/bor/valset"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
@ -15,19 +15,19 @@ import (
|
||||
|
||||
// Snapshot is the state of the authorization voting at a given point in time.
|
||||
type Snapshot struct {
|
||||
config *chain.BorConfig // Consensus engine parameters to fine tune behavior
|
||||
sigcache *lru2.ARCCache[libcommon.Hash, libcommon.Address] // Cache of recent block signatures to speed up ecrecover
|
||||
config *chain.BorConfig // Consensus engine parameters to fine tune behavior
|
||||
sigcache *lru.ARCCache[common.Hash, common.Address] // Cache of recent block signatures to speed up ecrecover
|
||||
|
||||
Number uint64 `json:"number"` // Block number where the snapshot was created
|
||||
Hash libcommon.Hash `json:"hash"` // Block hash where the snapshot was created
|
||||
ValidatorSet *valset.ValidatorSet `json:"validatorSet"` // Validator set at this moment
|
||||
Recents map[uint64]libcommon.Address `json:"recents"` // Set of recent signers for spam protections
|
||||
Number uint64 `json:"number"` // Block number where the snapshot was created
|
||||
Hash common.Hash `json:"hash"` // Block hash where the snapshot was created
|
||||
ValidatorSet *valset.ValidatorSet `json:"validatorSet"` // Validator set at this moment
|
||||
Recents map[uint64]common.Address `json:"recents"` // Set of recent signers for spam protections
|
||||
}
|
||||
|
||||
const BorSeparate = "BorSeparate"
|
||||
|
||||
// signersAscending implements the sort interface to allow sorting a list of addresses
|
||||
// type signersAscending []libcommon.Address
|
||||
// type signersAscending []common.Address
|
||||
|
||||
// func (s signersAscending) Len() int { return len(s) }
|
||||
// func (s signersAscending) Less(i, j int) bool { return bytes.Compare(s[i][:], s[j][:]) < 0 }
|
||||
@ -38,9 +38,9 @@ const BorSeparate = "BorSeparate"
|
||||
// the genesis block.
|
||||
func newSnapshot(
|
||||
config *chain.BorConfig,
|
||||
sigcache *lru2.ARCCache[libcommon.Hash, libcommon.Address],
|
||||
sigcache *lru.ARCCache[common.Hash, common.Address],
|
||||
number uint64,
|
||||
hash libcommon.Hash,
|
||||
hash common.Hash,
|
||||
validators []*valset.Validator,
|
||||
) *Snapshot {
|
||||
snap := &Snapshot{
|
||||
@ -49,13 +49,13 @@ func newSnapshot(
|
||||
Number: number,
|
||||
Hash: hash,
|
||||
ValidatorSet: valset.NewValidatorSet(validators),
|
||||
Recents: make(map[uint64]libcommon.Address),
|
||||
Recents: make(map[uint64]common.Address),
|
||||
}
|
||||
return snap
|
||||
}
|
||||
|
||||
// loadSnapshot loads an existing snapshot from the database.
|
||||
func loadSnapshot(config *chain.BorConfig, sigcache *lru2.ARCCache[libcommon.Hash, libcommon.Address], db kv.RwDB, hash libcommon.Hash) (*Snapshot, error) {
|
||||
func loadSnapshot(config *chain.BorConfig, sigcache *lru.ARCCache[common.Hash, common.Address], db kv.RwDB, hash common.Hash) (*Snapshot, error) {
|
||||
tx, err := db.BeginRo(context.Background())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -107,7 +107,7 @@ func (s *Snapshot) copy() *Snapshot {
|
||||
Number: s.Number,
|
||||
Hash: s.Hash,
|
||||
ValidatorSet: s.ValidatorSet.Copy(),
|
||||
Recents: make(map[uint64]libcommon.Address),
|
||||
Recents: make(map[uint64]common.Address),
|
||||
}
|
||||
for block, signer := range s.Recents {
|
||||
cpy.Recents[block] = signer
|
||||
@ -183,7 +183,7 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
|
||||
}
|
||||
|
||||
// GetSignerSuccessionNumber returns the relative position of signer in terms of the in-turn proposer
|
||||
func (s *Snapshot) GetSignerSuccessionNumber(signer libcommon.Address) (int, error) {
|
||||
func (s *Snapshot) GetSignerSuccessionNumber(signer common.Address) (int, error) {
|
||||
validators := s.ValidatorSet.Validators
|
||||
proposer := s.ValidatorSet.GetProposer().Address
|
||||
proposerIndex, _ := s.ValidatorSet.GetByAddress(proposer)
|
||||
@ -209,8 +209,8 @@ func (s *Snapshot) GetSignerSuccessionNumber(signer libcommon.Address) (int, err
|
||||
}
|
||||
|
||||
// signers retrieves the list of authorized signers in ascending order.
|
||||
func (s *Snapshot) signers() []libcommon.Address {
|
||||
sigs := make([]libcommon.Address, 0, len(s.ValidatorSet.Validators))
|
||||
func (s *Snapshot) signers() []common.Address {
|
||||
sigs := make([]common.Address, 0, len(s.ValidatorSet.Validators))
|
||||
for _, sig := range s.ValidatorSet.Validators {
|
||||
sigs = append(sigs, sig.Address)
|
||||
}
|
||||
@ -219,9 +219,9 @@ func (s *Snapshot) signers() []libcommon.Address {
|
||||
}
|
||||
|
||||
// Difficulty returns the difficulty for a particular signer at the current snapshot number
|
||||
func (s *Snapshot) Difficulty(signer libcommon.Address) uint64 {
|
||||
func (s *Snapshot) Difficulty(signer common.Address) uint64 {
|
||||
// if signer is empty
|
||||
if bytes.Equal(signer.Bytes(), libcommon.Address{}.Bytes()) {
|
||||
if bytes.Equal(signer.Bytes(), common.Address{}.Bytes()) {
|
||||
return 1
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/goccy/go-json"
|
||||
lru2 "github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
@ -144,7 +144,7 @@ var (
|
||||
type SignerFn func(signer libcommon.Address, mimeType string, message []byte) ([]byte, error)
|
||||
|
||||
// ecrecover extracts the Ethereum account address from a signed header.
|
||||
func ecrecover(header *types.Header, sigcache *lru2.ARCCache[libcommon.Hash, libcommon.Address]) (libcommon.Address, error) {
|
||||
func ecrecover(header *types.Header, sigcache *lru.ARCCache[libcommon.Hash, libcommon.Address]) (libcommon.Address, error) {
|
||||
// If the signature's already cached, return that
|
||||
hash := header.Hash()
|
||||
|
||||
@ -180,8 +180,8 @@ type Clique struct {
|
||||
snapshotConfig *params.ConsensusSnapshotConfig // Consensus engine configuration parameters
|
||||
db kv.RwDB // Database to store and retrieve snapshot checkpoints
|
||||
|
||||
signatures *lru2.ARCCache[libcommon.Hash, libcommon.Address] // Signatures of recent blocks to speed up mining
|
||||
recents *lru2.ARCCache[libcommon.Hash, *Snapshot] // Snapshots for recent block to speed up reorgs
|
||||
signatures *lru.ARCCache[libcommon.Hash, libcommon.Address] // Signatures of recent blocks to speed up mining
|
||||
recents *lru.ARCCache[libcommon.Hash, *Snapshot] // Snapshots for recent block to speed up reorgs
|
||||
|
||||
proposals map[libcommon.Address]bool // Current list of proposals we are pushing
|
||||
|
||||
@ -206,8 +206,8 @@ func New(cfg *chain.Config, snapshotConfig *params.ConsensusSnapshotConfig, cliq
|
||||
conf.Epoch = epochLength
|
||||
}
|
||||
// Allocate the snapshot caches and create the engine
|
||||
recents, _ := lru2.NewARC[libcommon.Hash, *Snapshot](snapshotConfig.InmemorySnapshots)
|
||||
signatures, _ := lru2.NewARC[libcommon.Hash, libcommon.Address](snapshotConfig.InmemorySignatures)
|
||||
recents, _ := lru.NewARC[libcommon.Hash, *Snapshot](snapshotConfig.InmemorySnapshots)
|
||||
signatures, _ := lru.NewARC[libcommon.Hash, libcommon.Address](snapshotConfig.InmemorySignatures)
|
||||
|
||||
exitCh := make(chan struct{})
|
||||
|
||||
|
@ -25,7 +25,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/goccy/go-json"
|
||||
lru2 "github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
@ -196,7 +196,7 @@ func (s *Snapshot) uncast(address libcommon.Address, authorize bool) bool {
|
||||
|
||||
// apply creates a new authorization snapshot by applying the given headers to
|
||||
// the original one.
|
||||
func (s *Snapshot) apply(sigcache *lru2.ARCCache[libcommon.Hash, libcommon.Address], headers ...*types.Header) (*Snapshot, error) {
|
||||
func (s *Snapshot) apply(sigcache *lru.ARCCache[libcommon.Hash, libcommon.Address], headers ...*types.Header) (*Snapshot, error) {
|
||||
// Allow passing in no headers for cleaner code
|
||||
if len(headers) == 0 {
|
||||
return s, nil
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
lru2 "github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/length"
|
||||
@ -150,7 +150,7 @@ var (
|
||||
type SignFn func(validator libcommon.Address, payload []byte, chainId *big.Int) ([]byte, error)
|
||||
|
||||
// ecrecover extracts the Ethereum account address from a signed header.
|
||||
func ecrecover(header *types.Header, sigCache *lru2.ARCCache[libcommon.Hash, libcommon.Address], chainId *big.Int) (libcommon.Address, error) {
|
||||
func ecrecover(header *types.Header, sigCache *lru.ARCCache[libcommon.Hash, libcommon.Address], chainId *big.Int) (libcommon.Address, error) {
|
||||
// If the signature's already cached, return that
|
||||
hash := header.Hash()
|
||||
if address, known := sigCache.Get(hash); known {
|
||||
@ -228,8 +228,8 @@ type Parlia struct {
|
||||
db kv.RwDB // Database to store and retrieve snapshot checkpoints
|
||||
chainDb kv.RwDB
|
||||
|
||||
recentSnaps *lru2.ARCCache[libcommon.Hash, *Snapshot] // Snapshots for recent block to speed up
|
||||
signatures *lru2.ARCCache[libcommon.Hash, libcommon.Address] // Signatures of recent blocks to speed up mining
|
||||
recentSnaps *lru.ARCCache[libcommon.Hash, *Snapshot] // Snapshots for recent block to speed up
|
||||
signatures *lru.ARCCache[libcommon.Hash, libcommon.Address] // Signatures of recent blocks to speed up mining
|
||||
|
||||
signer *types.Signer
|
||||
|
||||
@ -265,11 +265,11 @@ func New(
|
||||
}
|
||||
|
||||
// Allocate the snapshot caches and create the engine
|
||||
recentSnaps, err := lru2.NewARC[libcommon.Hash, *Snapshot](inMemorySnapshots)
|
||||
recentSnaps, err := lru.NewARC[libcommon.Hash, *Snapshot](inMemorySnapshots)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
signatures, err := lru2.NewARC[libcommon.Hash, libcommon.Address](inMemorySignatures)
|
||||
signatures, err := lru.NewARC[libcommon.Hash, libcommon.Address](inMemorySignatures)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ import (
|
||||
"math/big"
|
||||
"sort"
|
||||
|
||||
lru2 "github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutility"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
@ -39,14 +39,14 @@ import (
|
||||
|
||||
// Snapshot is the state of the validatorSet at a given point.
|
||||
type Snapshot struct {
|
||||
config *chain.ParliaConfig // Consensus engine parameters to fine tune behavior
|
||||
sigCache *lru2.ARCCache[libcommon.Hash, libcommon.Address] // Cache of recent block signatures to speed up ecrecover
|
||||
config *chain.ParliaConfig // Consensus engine parameters to fine tune behavior
|
||||
sigCache *lru.ARCCache[common.Hash, common.Address] // Cache of recent block signatures to speed up ecrecover
|
||||
|
||||
Number uint64 `json:"number"` // Block number where the snapshot was created
|
||||
Hash libcommon.Hash `json:"hash"` // Block hash where the snapshot was created
|
||||
Validators map[libcommon.Address]struct{} `json:"validators"` // Set of authorized validators at this moment
|
||||
Recents map[uint64]libcommon.Address `json:"recents"` // Set of recent validators for spam protections
|
||||
RecentForkHashes map[uint64]string `json:"recent_fork_hashes"` // Set of recent forkHash
|
||||
Number uint64 `json:"number"` // Block number where the snapshot was created
|
||||
Hash common.Hash `json:"hash"` // Block hash where the snapshot was created
|
||||
Validators map[common.Address]struct{} `json:"validators"` // Set of authorized validators at this moment
|
||||
Recents map[uint64]common.Address `json:"recents"` // Set of recent validators for spam protections
|
||||
RecentForkHashes map[uint64]string `json:"recent_fork_hashes"` // Set of recent forkHash
|
||||
}
|
||||
|
||||
// newSnapshot creates a new snapshot with the specified startup parameters. This
|
||||
@ -54,19 +54,19 @@ type Snapshot struct {
|
||||
// the genesis block.
|
||||
func newSnapshot(
|
||||
config *chain.ParliaConfig,
|
||||
sigCache *lru2.ARCCache[libcommon.Hash, libcommon.Address],
|
||||
sigCache *lru.ARCCache[common.Hash, common.Address],
|
||||
number uint64,
|
||||
hash libcommon.Hash,
|
||||
validators []libcommon.Address,
|
||||
hash common.Hash,
|
||||
validators []common.Address,
|
||||
) *Snapshot {
|
||||
snap := &Snapshot{
|
||||
config: config,
|
||||
sigCache: sigCache,
|
||||
Number: number,
|
||||
Hash: hash,
|
||||
Recents: make(map[uint64]libcommon.Address),
|
||||
Recents: make(map[uint64]common.Address),
|
||||
RecentForkHashes: make(map[uint64]string),
|
||||
Validators: make(map[libcommon.Address]struct{}),
|
||||
Validators: make(map[common.Address]struct{}),
|
||||
}
|
||||
for _, v := range validators {
|
||||
snap.Validators[v] = struct{}{}
|
||||
@ -75,21 +75,21 @@ func newSnapshot(
|
||||
}
|
||||
|
||||
// validatorsAscending implements the sort interface to allow sorting a list of addresses
|
||||
type validatorsAscending []libcommon.Address
|
||||
type validatorsAscending []common.Address
|
||||
|
||||
func (s validatorsAscending) Len() int { return len(s) }
|
||||
func (s validatorsAscending) Less(i, j int) bool { return bytes.Compare(s[i][:], s[j][:]) < 0 }
|
||||
func (s validatorsAscending) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// SnapshotFullKey = SnapshotBucket + num (uint64 big endian) + hash
|
||||
func SnapshotFullKey(number uint64, hash libcommon.Hash) []byte {
|
||||
func SnapshotFullKey(number uint64, hash common.Hash) []byte {
|
||||
return append(hexutility.EncodeTs(number), hash.Bytes()...)
|
||||
}
|
||||
|
||||
var ErrNoSnapsnot = fmt.Errorf("no parlia snapshot")
|
||||
|
||||
// loadSnapshot loads an existing snapshot from the database.
|
||||
func loadSnapshot(config *chain.ParliaConfig, sigCache *lru2.ARCCache[libcommon.Hash, libcommon.Address], db kv.RwDB, num uint64, hash libcommon.Hash) (*Snapshot, error) {
|
||||
func loadSnapshot(config *chain.ParliaConfig, sigCache *lru.ARCCache[common.Hash, common.Address], db kv.RwDB, num uint64, hash common.Hash) (*Snapshot, error) {
|
||||
tx, err := db.BeginRo(context.Background())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -130,8 +130,8 @@ func (s *Snapshot) copy() *Snapshot {
|
||||
sigCache: s.sigCache,
|
||||
Number: s.Number,
|
||||
Hash: s.Hash,
|
||||
Validators: make(map[libcommon.Address]struct{}),
|
||||
Recents: make(map[uint64]libcommon.Address),
|
||||
Validators: make(map[common.Address]struct{}),
|
||||
Recents: make(map[uint64]common.Address),
|
||||
RecentForkHashes: make(map[uint64]string),
|
||||
}
|
||||
|
||||
@ -224,7 +224,7 @@ func (s *Snapshot) apply(headers []*types.Header, chain consensus.ChainHeaderRea
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newVals := make(map[libcommon.Address]struct{}, len(newValArr))
|
||||
newVals := make(map[common.Address]struct{}, len(newValArr))
|
||||
for _, val := range newValArr {
|
||||
newVals[val] = struct{}{}
|
||||
}
|
||||
@ -252,8 +252,8 @@ func (s *Snapshot) apply(headers []*types.Header, chain consensus.ChainHeaderRea
|
||||
}
|
||||
|
||||
// validators retrieves the list of validators in ascending order.
|
||||
func (s *Snapshot) validators() []libcommon.Address {
|
||||
validators := make([]libcommon.Address, 0, len(s.Validators))
|
||||
func (s *Snapshot) validators() []common.Address {
|
||||
validators := make([]common.Address, 0, len(s.Validators))
|
||||
for v := range s.Validators {
|
||||
validators = append(validators, v)
|
||||
}
|
||||
@ -262,13 +262,13 @@ func (s *Snapshot) validators() []libcommon.Address {
|
||||
}
|
||||
|
||||
// inturn returns if a validator at a given block height is in-turn or not.
|
||||
func (s *Snapshot) inturn(validator libcommon.Address) bool {
|
||||
func (s *Snapshot) inturn(validator common.Address) bool {
|
||||
validators := s.validators()
|
||||
offset := (s.Number + 1) % uint64(len(validators))
|
||||
return validators[offset] == validator
|
||||
}
|
||||
|
||||
func (s *Snapshot) enoughDistance(validator libcommon.Address, header *types.Header) bool {
|
||||
func (s *Snapshot) enoughDistance(validator common.Address, header *types.Header) bool {
|
||||
idx := s.indexOfVal(validator)
|
||||
if idx < 0 {
|
||||
return true
|
||||
@ -288,7 +288,7 @@ func (s *Snapshot) enoughDistance(validator libcommon.Address, header *types.Hea
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Snapshot) indexOfVal(validator libcommon.Address) int {
|
||||
func (s *Snapshot) indexOfVal(validator common.Address) int {
|
||||
validators := s.validators()
|
||||
for idx, val := range validators {
|
||||
if val == validator {
|
||||
@ -298,22 +298,22 @@ func (s *Snapshot) indexOfVal(validator libcommon.Address) int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func (s *Snapshot) supposeValidator() libcommon.Address {
|
||||
func (s *Snapshot) supposeValidator() common.Address {
|
||||
validators := s.validators()
|
||||
index := (s.Number + 1) % uint64(len(validators))
|
||||
return validators[index]
|
||||
}
|
||||
|
||||
func ParseValidators(validatorsBytes []byte) ([]libcommon.Address, error) {
|
||||
func ParseValidators(validatorsBytes []byte) ([]common.Address, error) {
|
||||
if len(validatorsBytes)%validatorBytesLength != 0 {
|
||||
return nil, errors.New("invalid validators bytes")
|
||||
}
|
||||
n := len(validatorsBytes) / validatorBytesLength
|
||||
result := make([]libcommon.Address, n)
|
||||
result := make([]common.Address, n)
|
||||
for i := 0; i < n; i++ {
|
||||
address := make([]byte, validatorBytesLength)
|
||||
copy(address, validatorsBytes[i*validatorBytesLength:(i+1)*validatorBytesLength])
|
||||
result[i] = libcommon.BytesToAddress(address)
|
||||
result[i] = common.BytesToAddress(address)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user