mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-21 19:20:39 +00:00
use crypto pool (#6197)
This commit is contained in:
parent
c401a2e9d2
commit
63b88c7d16
@ -15,7 +15,7 @@ import (
|
||||
"github.com/ledgerwatch/erigon/core/state"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/core/vm"
|
||||
"github.com/ledgerwatch/erigon/crypto"
|
||||
"github.com/ledgerwatch/erigon/crypto/cryptopool"
|
||||
"github.com/ledgerwatch/erigon/rpc"
|
||||
"github.com/ledgerwatch/erigon/turbo/adapter/ethapi"
|
||||
"github.com/ledgerwatch/erigon/turbo/rpchelper"
|
||||
@ -149,8 +149,8 @@ func (api *APIImpl) CallBundle(ctx context.Context, txHashes []common.Hash, stat
|
||||
|
||||
results := []map[string]interface{}{}
|
||||
|
||||
bundleHash := crypto.NewLegacyKeccak256()
|
||||
defer crypto.ReturnToPoolKeccak256(bundleHash)
|
||||
bundleHash := cryptopool.NewLegacyKeccak256()
|
||||
defer cryptopool.ReturnToPoolKeccak256(bundleHash)
|
||||
|
||||
for _, txn := range txs {
|
||||
msg, err := txn.AsMessage(*signer, nil, rules)
|
||||
|
@ -29,7 +29,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/ledgerwatch/erigon/common/hexutil"
|
||||
"golang.org/x/crypto/sha3"
|
||||
"github.com/ledgerwatch/erigon/crypto/cryptopool"
|
||||
)
|
||||
|
||||
// Lengths of hashes and addresses in bytes.
|
||||
@ -246,10 +246,12 @@ func (a *Address) checksumHex() []byte {
|
||||
buf := a.hex()
|
||||
|
||||
// compute checksum
|
||||
sha := sha3.NewLegacyKeccak256()
|
||||
sha := cryptopool.NewLegacyKeccak256()
|
||||
//nolint:errcheck
|
||||
sha.Write(buf[2:])
|
||||
hash := sha.Sum(nil)
|
||||
cryptopool.ReturnToPoolKeccak256(sha)
|
||||
|
||||
for i := 2; i < len(buf); i++ {
|
||||
hashByte := hash[(i-2)/2]
|
||||
if i%2 == 0 {
|
||||
@ -507,10 +509,11 @@ func (a *Address32) checksumHex() []byte {
|
||||
buf := a.hex()
|
||||
|
||||
// compute checksum
|
||||
sha := sha3.NewLegacyKeccak256()
|
||||
sha := cryptopool.NewLegacyKeccak256()
|
||||
//nolint:errcheck
|
||||
sha.Write(buf[2:])
|
||||
hash := sha.Sum(nil)
|
||||
cryptopool.ReturnToPoolKeccak256(sha)
|
||||
for i := 2; i < len(buf); i++ {
|
||||
hashByte := hash[(i-2)/2]
|
||||
if i%2 == 0 {
|
||||
|
@ -27,6 +27,7 @@ import (
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/core/types/accounts"
|
||||
"github.com/ledgerwatch/erigon/crypto"
|
||||
"github.com/ledgerwatch/erigon/crypto/cryptopool"
|
||||
"github.com/ledgerwatch/erigon/params"
|
||||
"github.com/ledgerwatch/erigon/params/networkname"
|
||||
"github.com/ledgerwatch/erigon/rlp"
|
||||
@ -144,8 +145,8 @@ func ecrecover(header *types.Header, sigcache *lru.ARCCache, c *params.BorConfig
|
||||
|
||||
// SealHash returns the hash of a block prior to it being sealed.
|
||||
func SealHash(header *types.Header, c *params.BorConfig) (hash common.Hash) {
|
||||
hasher := crypto.NewLegacyKeccak256()
|
||||
defer crypto.ReturnToPoolKeccak256(hasher)
|
||||
hasher := cryptopool.NewLegacyKeccak256()
|
||||
defer cryptopool.ReturnToPoolKeccak256(hasher)
|
||||
|
||||
encodeSigHeader(hasher, header, c)
|
||||
hasher.Sum(hash[:0])
|
||||
|
@ -40,6 +40,7 @@ import (
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/core/types/accounts"
|
||||
"github.com/ledgerwatch/erigon/crypto"
|
||||
"github.com/ledgerwatch/erigon/crypto/cryptopool"
|
||||
"github.com/ledgerwatch/erigon/params"
|
||||
"github.com/ledgerwatch/erigon/rlp"
|
||||
"github.com/ledgerwatch/erigon/rpc"
|
||||
@ -524,8 +525,8 @@ func (c *Clique) APIs(chain consensus.ChainHeaderReader) []rpc.API {
|
||||
|
||||
// SealHash returns the hash of a block prior to it being sealed.
|
||||
func SealHash(header *types.Header) (hash common.Hash) {
|
||||
hasher := crypto.NewLegacyKeccak256()
|
||||
defer crypto.ReturnToPoolKeccak256(hasher)
|
||||
hasher := cryptopool.NewLegacyKeccak256()
|
||||
defer cryptopool.ReturnToPoolKeccak256(hasher)
|
||||
|
||||
encodeSigHeader(hasher, header)
|
||||
hasher.Sum(hash[:0])
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/common/length"
|
||||
"github.com/ledgerwatch/erigon/core/rawdb"
|
||||
"github.com/ledgerwatch/erigon/crypto/cryptopool"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"github.com/holiman/uint256"
|
||||
@ -173,8 +174,8 @@ func ecrecover(header *types.Header, sigCache *lru.ARCCache, chainId *big.Int) (
|
||||
|
||||
// SealHash returns the hash of a block prior to it being sealed.
|
||||
func SealHash(header *types.Header, chainId *big.Int) (hash common.Hash) {
|
||||
hasher := crypto.NewLegacyKeccak256()
|
||||
defer crypto.ReturnToPoolKeccak256(hasher)
|
||||
hasher := cryptopool.NewLegacyKeccak256()
|
||||
defer cryptopool.ReturnToPoolKeccak256(hasher)
|
||||
|
||||
encodeSigHeader(hasher, header, chainId)
|
||||
hasher.Sum(hash[:0])
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/ledgerwatch/erigon/common/hexutil"
|
||||
"github.com/ledgerwatch/erigon/crypto"
|
||||
"github.com/ledgerwatch/erigon/crypto/cryptopool"
|
||||
)
|
||||
|
||||
type bytesBacked interface {
|
||||
@ -139,7 +140,7 @@ func bloomValues(data []byte, hashbuf []byte) (uint, byte, uint, byte, uint, byt
|
||||
sha := crypto.NewKeccakState()
|
||||
sha.Write(data) //nolint:errcheck
|
||||
sha.Read(hashbuf) //nolint:errcheck
|
||||
crypto.ReturnToPoolKeccak256(sha)
|
||||
cryptopool.ReturnToPoolKeccak256(sha)
|
||||
// The actual bits to flip
|
||||
v1 := byte(1 << (hashbuf[1] & 0x7))
|
||||
v2 := byte(1 << (hashbuf[3] & 0x7))
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/ledgerwatch/erigon/crypto"
|
||||
"github.com/ledgerwatch/erigon/crypto/cryptopool"
|
||||
"github.com/ledgerwatch/erigon/rlp"
|
||||
"github.com/ledgerwatch/erigon/turbo/rlphacks"
|
||||
"github.com/ledgerwatch/erigon/turbo/trie"
|
||||
@ -162,7 +163,7 @@ func RawRlpHash(rawRlpData rlp.RawValue) (h common.Hash) {
|
||||
sha := crypto.NewKeccakState()
|
||||
sha.Write(rawRlpData) //nolint:errcheck
|
||||
sha.Read(h[:]) //nolint:errcheck
|
||||
crypto.ReturnToPoolKeccak256(sha)
|
||||
cryptopool.ReturnToPoolKeccak256(sha)
|
||||
return h
|
||||
}
|
||||
|
||||
@ -170,7 +171,7 @@ func rlpHash(x interface{}) (h common.Hash) {
|
||||
sha := crypto.NewKeccakState()
|
||||
rlp.Encode(sha, x) //nolint:errcheck
|
||||
sha.Read(h[:]) //nolint:errcheck
|
||||
crypto.ReturnToPoolKeccak256(sha)
|
||||
cryptopool.ReturnToPoolKeccak256(sha)
|
||||
return h
|
||||
}
|
||||
|
||||
@ -185,6 +186,6 @@ func prefixedRlpHash(prefix byte, x interface{}) (h common.Hash) {
|
||||
}
|
||||
//nolint:errcheck
|
||||
sha.Read(h[:])
|
||||
crypto.ReturnToPoolKeccak256(sha)
|
||||
cryptopool.ReturnToPoolKeccak256(sha)
|
||||
return h
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/ledgerwatch/erigon/crypto/cryptopool"
|
||||
"golang.org/x/crypto/sha3"
|
||||
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
@ -66,7 +67,7 @@ type KeccakState interface {
|
||||
|
||||
// NewKeccakState creates a new KeccakState
|
||||
func NewKeccakState() KeccakState {
|
||||
return NewLegacyKeccak256().(KeccakState)
|
||||
return cryptopool.NewLegacyKeccak256().(KeccakState)
|
||||
}
|
||||
|
||||
// HashData hashes the provided data using the KeccakState and returns a 32 byte hash
|
||||
@ -87,7 +88,7 @@ func Keccak256(data ...[]byte) []byte {
|
||||
d.Write(b)
|
||||
}
|
||||
d.Read(b) //nolint:errcheck
|
||||
ReturnToPoolKeccak256(d)
|
||||
cryptopool.ReturnToPoolKeccak256(d)
|
||||
return b
|
||||
}
|
||||
|
||||
@ -99,7 +100,7 @@ func Keccak256Hash(data ...[]byte) (h common.Hash) {
|
||||
d.Write(b)
|
||||
}
|
||||
d.Read(h[:]) //nolint:errcheck
|
||||
ReturnToPoolKeccak256(d)
|
||||
cryptopool.ReturnToPoolKeccak256(d)
|
||||
return h
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package crypto
|
||||
package cryptopool
|
||||
|
||||
import (
|
||||
"hash"
|
@ -36,6 +36,7 @@ import (
|
||||
"github.com/ledgerwatch/erigon/core/rawdb"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/crypto"
|
||||
"github.com/ledgerwatch/erigon/crypto/cryptopool"
|
||||
"github.com/ledgerwatch/erigon/eth/ethconfig"
|
||||
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
|
||||
"github.com/ledgerwatch/erigon/params"
|
||||
@ -1838,7 +1839,7 @@ func HeadersIdx(ctx context.Context, segmentFilePath string, firstBlockNumInSegm
|
||||
p.Total.Store(uint64(d.Count()))
|
||||
|
||||
hasher := crypto.NewKeccakState()
|
||||
defer crypto.ReturnToPoolKeccak256(hasher)
|
||||
defer cryptopool.ReturnToPoolKeccak256(hasher)
|
||||
var h common.Hash
|
||||
if err := Idx(ctx, d, firstBlockNumInSegment, tmpDir, log.LvlDebug, func(idx *recsplit.RecSplit, i, offset uint64, word []byte) error {
|
||||
p.Processed.Inc()
|
||||
|
Loading…
Reference in New Issue
Block a user