@@ -24,6 +24,7 @@ import (
24
24
"github.com/ethereum/go-ethereum/core/types"
25
25
"github.com/ethereum/go-ethereum/ethdb"
26
26
"github.com/ethereum/go-ethereum/params"
27
+ lru "github.com/hashicorp/golang-lru"
27
28
)
28
29
29
30
// Vote represents a single vote that an authorized signer made to modify the
@@ -44,7 +45,8 @@ type Tally struct {
44
45
45
46
// Snapshot is the state of the authorization voting at a given point in time.
46
47
type Snapshot struct {
47
- config * params.CliqueConfig // Consensus engine parameters to fine tune behavior
48
+ config * params.CliqueConfig // Consensus engine parameters to fine tune behavior
49
+ sigcache * lru.ARCCache // Cache of recent block signatures to speed up ecrecover
48
50
49
51
Number uint64 `json:"number"` // Block number where the snapshot was created
50
52
Hash common.Hash `json:"hash"` // Block hash where the snapshot was created
@@ -57,14 +59,15 @@ type Snapshot struct {
57
59
// newSnapshot create a new snapshot with the specified startup parameters. This
58
60
// method does not initialize the set of recent signers, so only ever use if for
59
61
// the genesis block.
60
- func newSnapshot (config * params.CliqueConfig , number uint64 , hash common.Hash , signers []common.Address ) * Snapshot {
62
+ func newSnapshot (config * params.CliqueConfig , sigcache * lru. ARCCache , number uint64 , hash common.Hash , signers []common.Address ) * Snapshot {
61
63
snap := & Snapshot {
62
- config : config ,
63
- Number : number ,
64
- Hash : hash ,
65
- Signers : make (map [common.Address ]struct {}),
66
- Recents : make (map [uint64 ]common.Address ),
67
- Tally : make (map [common.Address ]Tally ),
64
+ config : config ,
65
+ sigcache : sigcache ,
66
+ Number : number ,
67
+ Hash : hash ,
68
+ Signers : make (map [common.Address ]struct {}),
69
+ Recents : make (map [uint64 ]common.Address ),
70
+ Tally : make (map [common.Address ]Tally ),
68
71
}
69
72
for _ , signer := range signers {
70
73
snap .Signers [signer ] = struct {}{}
@@ -73,7 +76,7 @@ func newSnapshot(config *params.CliqueConfig, number uint64, hash common.Hash, s
73
76
}
74
77
75
78
// loadSnapshot loads an existing snapshot from the database.
76
- func loadSnapshot (config * params.CliqueConfig , db ethdb.Database , hash common.Hash ) (* Snapshot , error ) {
79
+ func loadSnapshot (config * params.CliqueConfig , sigcache * lru. ARCCache , db ethdb.Database , hash common.Hash ) (* Snapshot , error ) {
77
80
blob , err := db .Get (append ([]byte ("clique-" ), hash [:]... ))
78
81
if err != nil {
79
82
return nil , err
@@ -83,6 +86,7 @@ func loadSnapshot(config *params.CliqueConfig, db ethdb.Database, hash common.Ha
83
86
return nil , err
84
87
}
85
88
snap .config = config
89
+ snap .sigcache = sigcache
86
90
87
91
return snap , nil
88
92
}
@@ -99,13 +103,14 @@ func (s *Snapshot) store(db ethdb.Database) error {
99
103
// copy creates a deep copy of the snapshot, though not the individual votes.
100
104
func (s * Snapshot ) copy () * Snapshot {
101
105
cpy := & Snapshot {
102
- config : s .config ,
103
- Number : s .Number ,
104
- Hash : s .Hash ,
105
- Signers : make (map [common.Address ]struct {}),
106
- Recents : make (map [uint64 ]common.Address ),
107
- Votes : make ([]* Vote , len (s .Votes )),
108
- Tally : make (map [common.Address ]Tally ),
106
+ config : s .config ,
107
+ sigcache : s .sigcache ,
108
+ Number : s .Number ,
109
+ Hash : s .Hash ,
110
+ Signers : make (map [common.Address ]struct {}),
111
+ Recents : make (map [uint64 ]common.Address ),
112
+ Votes : make ([]* Vote , len (s .Votes )),
113
+ Tally : make (map [common.Address ]Tally ),
109
114
}
110
115
for signer := range s .Signers {
111
116
cpy .Signers [signer ] = struct {}{}
@@ -190,7 +195,7 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
190
195
delete (snap .Recents , number - limit )
191
196
}
192
197
// Resolve the authorization key and check against signers
193
- signer , err := ecrecover (header )
198
+ signer , err := ecrecover (header , s . sigcache )
194
199
if err != nil {
195
200
return nil , err
196
201
}
0 commit comments