Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions consensus/clique/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ package clique
import (
"bytes"
"encoding/json"
"maps"
"slices"
"time"

lru "github.com/hashicorp/golang-lru"
"slices"

"github.com/CortexFoundation/CortexTheseus/common"
"github.com/CortexFoundation/CortexTheseus/core/rawdb"
Expand Down Expand Up @@ -106,29 +107,17 @@ func (s *Snapshot) store(db ctxcdb.Database) error {
}

// copy creates a deep copy of the snapshot, though not the individual votes.
func (s *Snapshot) deepCopy() *Snapshot {
cpy := &Snapshot{
func (s *Snapshot) copy() *Snapshot {
return &Snapshot{
config: s.config,
sigcache: s.sigcache,
Number: s.Number,
Hash: s.Hash,
Signers: make(map[common.Address]struct{}),
Recents: make(map[uint64]common.Address),
Votes: make([]*Vote, len(s.Votes)),
Tally: make(map[common.Address]Tally),
Signers: maps.Clone(s.Signers),
Recents: maps.Clone(s.Recents),
Votes: slices.Clone(s.Votes),
Tally: maps.Clone(s.Tally),
}
for signer := range s.Signers {
cpy.Signers[signer] = struct{}{}
}
for block, signer := range s.Recents {
cpy.Recents[block] = signer
}
for address, tally := range s.Tally {
cpy.Tally[address] = tally
}
copy(cpy.Votes, s.Votes)

return cpy
}

// validVote returns whether it makes sense to cast the specified vote in the
Expand Down Expand Up @@ -192,7 +181,7 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
return nil, errInvalidVotingChain
}
// Iterate through the headers and create a new snapshot
snap := s.deepCopy()
snap := s.copy()

var (
start = time.Now()
Expand Down