@@ -37,6 +37,7 @@ import (
3737 "github.com/ethereum/go-ethereum/log"
3838 "github.com/ethereum/go-ethereum/rlp"
3939 "github.com/ethereum/go-ethereum/rpc"
40+ lru "github.com/hashicorp/golang-lru"
4041)
4142
4243const (
8889
8990 nonceAuthVote = hexutil .MustDecode ("0xffffffffffffffff" ) // Magic nonce number to vote on adding a new validator
9091 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 )
9195)
9296
9397// Author retrieves the Ethereum address of the account that minted the given
@@ -673,12 +677,23 @@ func sigHash(header *types.Header) (hash common.Hash) {
673677
674678// ecrecover extracts the Ethereum account address from a signed header.
675679func 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+
676685 // Retrieve the signature from the header extra-data
677686 istanbulExtra , err := types .ExtractIstanbulExtra (header )
678687 if err != nil {
679688 return common.Address {}, err
680689 }
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
682697}
683698
684699// prepareExtra returns a extra-data of the given header and validators
0 commit comments