mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
parent
3107006ac6
commit
9155d354c9
2 changed files with 22 additions and 31 deletions
|
|
@ -19,6 +19,8 @@ package clique
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"maps"
|
||||
"slices"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/common"
|
||||
"github.com/XinFinOrg/XDPoSChain/common/lru"
|
||||
|
|
@ -104,28 +106,16 @@ func (s *Snapshot) store(db ethdb.Database) error {
|
|||
|
||||
// copy creates a deep copy of the snapshot, though not the individual votes.
|
||||
func (s *Snapshot) copy() *Snapshot {
|
||||
cpy := &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
|
||||
|
|
|
|||
|
|
@ -16,6 +16,12 @@
|
|||
|
||||
package trie
|
||||
|
||||
import (
|
||||
"maps"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/common"
|
||||
)
|
||||
|
||||
// tracer tracks the changes of trie nodes. During the trie operations,
|
||||
// some nodes can be deleted from the trie, while these deleted nodes
|
||||
// won't be captured by trie.Hasher or trie.Committer. Thus, these deleted
|
||||
|
|
@ -154,24 +160,19 @@ func (t *tracer) reset() {
|
|||
|
||||
// copy returns a deep copied tracer instance.
|
||||
func (t *tracer) copy() *tracer {
|
||||
// Tracer isn't used right now, remove this check later.
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
var (
|
||||
insert = make(map[string]struct{})
|
||||
delete = make(map[string]struct{})
|
||||
origin = make(map[string][]byte)
|
||||
)
|
||||
for key := range t.insert {
|
||||
insert[key] = struct{}{}
|
||||
}
|
||||
for key := range t.delete {
|
||||
delete[key] = struct{}{}
|
||||
}
|
||||
for key, val := range t.origin {
|
||||
origin[key] = val
|
||||
|
||||
insert := maps.Clone(t.insert)
|
||||
delete := maps.Clone(t.delete)
|
||||
|
||||
origin := make(map[string][]byte, len(t.origin))
|
||||
for k, v := range t.origin {
|
||||
// `common.CopyBytes` ensures deep copy according to comment
|
||||
origin[k] = common.CopyBytes(v)
|
||||
}
|
||||
|
||||
return &tracer{
|
||||
insert: insert,
|
||||
delete: delete,
|
||||
|
|
|
|||
Loading…
Reference in a new issue