@@ -37,6 +37,7 @@ import (
37
37
"github.com/ethereum/go-ethereum/log"
38
38
"github.com/ethereum/go-ethereum/rlp"
39
39
"github.com/ethereum/go-ethereum/rpc"
40
+ lru "github.com/hashicorp/golang-lru"
40
41
)
41
42
42
43
const (
88
89
89
90
nonceAuthVote = hexutil .MustDecode ("0xffffffffffffffff" ) // Magic nonce number to vote on adding a new validator
90
91
nonceDropVote = hexutil .MustDecode ("0x0000000000000000" ) // Magic nonce number to vote on removing a validator.
92
+
93
+ inmemoryAddresses = 20 // Number of recent addresses from ecrecover
94
+ recentAddresses , _ = lru .NewARC (inmemoryAddresses )
91
95
)
92
96
93
97
// Author retrieves the Ethereum address of the account that minted the given
@@ -673,12 +677,23 @@ func sigHash(header *types.Header) (hash common.Hash) {
673
677
674
678
// ecrecover extracts the Ethereum account address from a signed header.
675
679
func ecrecover (header * types.Header ) (common.Address , error ) {
680
+ hash := header .Hash ()
681
+ if addr , ok := recentAddresses .Get (hash ); ok {
682
+ return addr .(common.Address ), nil
683
+ }
684
+
676
685
// Retrieve the signature from the header extra-data
677
686
istanbulExtra , err := types .ExtractIstanbulExtra (header )
678
687
if err != nil {
679
688
return common.Address {}, err
680
689
}
681
- return istanbul .GetSignatureAddress (sigHash (header ).Bytes (), istanbulExtra .Seal )
690
+
691
+ addr , err := istanbul .GetSignatureAddress (sigHash (header ).Bytes (), istanbulExtra .Seal )
692
+ if err != nil {
693
+ return addr , err
694
+ }
695
+ recentAddresses .Add (hash , addr )
696
+ return addr , nil
682
697
}
683
698
684
699
// prepareExtra returns a extra-data of the given header and validators
0 commit comments