mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
eth: use stateless keccak
This commit is contained in:
parent
bc9e3faed1
commit
1b0bf9608f
2 changed files with 7 additions and 30 deletions
|
|
@ -2672,15 +2672,10 @@ func (s *Syncer) onByteCodes(peer SyncPeer, id uint64, bytecodes [][]byte) error
|
|||
|
||||
// Cross reference the requested bytecodes with the response to find gaps
|
||||
// that the serving node is missing
|
||||
hasher := crypto.NewKeccakState()
|
||||
hash := make([]byte, 32)
|
||||
|
||||
codes := make([][]byte, len(req.hashes))
|
||||
for i, j := 0, 0; i < len(bytecodes); i++ {
|
||||
// Find the next hash that we've been served, leaving misses with nils
|
||||
hasher.Reset()
|
||||
hasher.Write(bytecodes[i])
|
||||
hasher.Read(hash)
|
||||
hash := crypto.Keccak256(bytecodes[i])
|
||||
|
||||
for j < len(req.hashes) && !bytes.Equal(hash, req.hashes[j][:]) {
|
||||
j++
|
||||
|
|
@ -2920,16 +2915,12 @@ func (s *Syncer) OnTrieNodes(peer SyncPeer, id uint64, trienodes [][]byte) error
|
|||
// Cross reference the requested trienodes with the response to find gaps
|
||||
// that the serving node is missing
|
||||
var (
|
||||
hasher = crypto.NewKeccakState()
|
||||
hash = make([]byte, 32)
|
||||
nodes = make([][]byte, len(req.hashes))
|
||||
fills uint64
|
||||
nodes = make([][]byte, len(req.hashes))
|
||||
fills uint64
|
||||
)
|
||||
for i, j := 0, 0; i < len(trienodes); i++ {
|
||||
// Find the next hash that we've been served, leaving misses with nils
|
||||
hasher.Reset()
|
||||
hasher.Write(trienodes[i])
|
||||
hasher.Read(hash)
|
||||
hash := crypto.Keccak256(trienodes[i])
|
||||
|
||||
for j < len(req.hashes) && !bytes.Equal(hash, req.hashes[j][:]) {
|
||||
j++
|
||||
|
|
@ -3026,16 +3017,10 @@ func (s *Syncer) onHealByteCodes(peer SyncPeer, id uint64, bytecodes [][]byte) e
|
|||
|
||||
// Cross reference the requested bytecodes with the response to find gaps
|
||||
// that the serving node is missing
|
||||
hasher := crypto.NewKeccakState()
|
||||
hash := make([]byte, 32)
|
||||
|
||||
codes := make([][]byte, len(req.hashes))
|
||||
for i, j := 0, 0; i < len(bytecodes); i++ {
|
||||
// Find the next hash that we've been served, leaving misses with nils
|
||||
hasher.Reset()
|
||||
hasher.Write(bytecodes[i])
|
||||
hasher.Read(hash)
|
||||
|
||||
hash := crypto.Keccak256(bytecodes[i])
|
||||
for j < len(req.hashes) && !bytes.Equal(hash, req.hashes[j][:]) {
|
||||
j++
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,12 +64,8 @@ func TestHashing(t *testing.T) {
|
|||
}
|
||||
}
|
||||
var new = func() {
|
||||
hasher := crypto.NewKeccakState()
|
||||
var hash = make([]byte, 32)
|
||||
for i := 0; i < len(bytecodes); i++ {
|
||||
hasher.Reset()
|
||||
hasher.Write(bytecodes[i])
|
||||
hasher.Read(hash)
|
||||
hash := crypto.Keccak256(bytecodes[i])
|
||||
want = fmt.Sprintf("%v\n%v", want, hash)
|
||||
}
|
||||
}
|
||||
|
|
@ -96,12 +92,8 @@ func BenchmarkHashing(b *testing.B) {
|
|||
}
|
||||
}
|
||||
var new = func() {
|
||||
hasher := crypto.NewKeccakState()
|
||||
var hash = make([]byte, 32)
|
||||
for i := 0; i < len(bytecodes); i++ {
|
||||
hasher.Reset()
|
||||
hasher.Write(bytecodes[i])
|
||||
hasher.Read(hash)
|
||||
crypto.Keccak256(bytecodes[i])
|
||||
}
|
||||
}
|
||||
b.Run("old", func(b *testing.B) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue