mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +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
|
// Cross reference the requested bytecodes with the response to find gaps
|
||||||
// that the serving node is missing
|
// that the serving node is missing
|
||||||
hasher := crypto.NewKeccakState()
|
|
||||||
hash := make([]byte, 32)
|
|
||||||
|
|
||||||
codes := make([][]byte, len(req.hashes))
|
codes := make([][]byte, len(req.hashes))
|
||||||
for i, j := 0, 0; i < len(bytecodes); i++ {
|
for i, j := 0, 0; i < len(bytecodes); i++ {
|
||||||
// Find the next hash that we've been served, leaving misses with nils
|
// Find the next hash that we've been served, leaving misses with nils
|
||||||
hasher.Reset()
|
hash := crypto.Keccak256(bytecodes[i])
|
||||||
hasher.Write(bytecodes[i])
|
|
||||||
hasher.Read(hash)
|
|
||||||
|
|
||||||
for j < len(req.hashes) && !bytes.Equal(hash, req.hashes[j][:]) {
|
for j < len(req.hashes) && !bytes.Equal(hash, req.hashes[j][:]) {
|
||||||
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
|
// Cross reference the requested trienodes with the response to find gaps
|
||||||
// that the serving node is missing
|
// that the serving node is missing
|
||||||
var (
|
var (
|
||||||
hasher = crypto.NewKeccakState()
|
|
||||||
hash = make([]byte, 32)
|
|
||||||
nodes = make([][]byte, len(req.hashes))
|
nodes = make([][]byte, len(req.hashes))
|
||||||
fills uint64
|
fills uint64
|
||||||
)
|
)
|
||||||
for i, j := 0, 0; i < len(trienodes); i++ {
|
for i, j := 0, 0; i < len(trienodes); i++ {
|
||||||
// Find the next hash that we've been served, leaving misses with nils
|
// Find the next hash that we've been served, leaving misses with nils
|
||||||
hasher.Reset()
|
hash := crypto.Keccak256(trienodes[i])
|
||||||
hasher.Write(trienodes[i])
|
|
||||||
hasher.Read(hash)
|
|
||||||
|
|
||||||
for j < len(req.hashes) && !bytes.Equal(hash, req.hashes[j][:]) {
|
for j < len(req.hashes) && !bytes.Equal(hash, req.hashes[j][:]) {
|
||||||
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
|
// Cross reference the requested bytecodes with the response to find gaps
|
||||||
// that the serving node is missing
|
// that the serving node is missing
|
||||||
hasher := crypto.NewKeccakState()
|
|
||||||
hash := make([]byte, 32)
|
|
||||||
|
|
||||||
codes := make([][]byte, len(req.hashes))
|
codes := make([][]byte, len(req.hashes))
|
||||||
for i, j := 0, 0; i < len(bytecodes); i++ {
|
for i, j := 0, 0; i < len(bytecodes); i++ {
|
||||||
// Find the next hash that we've been served, leaving misses with nils
|
// Find the next hash that we've been served, leaving misses with nils
|
||||||
hasher.Reset()
|
hash := crypto.Keccak256(bytecodes[i])
|
||||||
hasher.Write(bytecodes[i])
|
|
||||||
hasher.Read(hash)
|
|
||||||
|
|
||||||
for j < len(req.hashes) && !bytes.Equal(hash, req.hashes[j][:]) {
|
for j < len(req.hashes) && !bytes.Equal(hash, req.hashes[j][:]) {
|
||||||
j++
|
j++
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,12 +64,8 @@ func TestHashing(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var new = func() {
|
var new = func() {
|
||||||
hasher := crypto.NewKeccakState()
|
|
||||||
var hash = make([]byte, 32)
|
|
||||||
for i := 0; i < len(bytecodes); i++ {
|
for i := 0; i < len(bytecodes); i++ {
|
||||||
hasher.Reset()
|
hash := crypto.Keccak256(bytecodes[i])
|
||||||
hasher.Write(bytecodes[i])
|
|
||||||
hasher.Read(hash)
|
|
||||||
want = fmt.Sprintf("%v\n%v", want, hash)
|
want = fmt.Sprintf("%v\n%v", want, hash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -96,12 +92,8 @@ func BenchmarkHashing(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var new = func() {
|
var new = func() {
|
||||||
hasher := crypto.NewKeccakState()
|
|
||||||
var hash = make([]byte, 32)
|
|
||||||
for i := 0; i < len(bytecodes); i++ {
|
for i := 0; i < len(bytecodes); i++ {
|
||||||
hasher.Reset()
|
crypto.Keccak256(bytecodes[i])
|
||||||
hasher.Write(bytecodes[i])
|
|
||||||
hasher.Read(hash)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.Run("old", func(b *testing.B) {
|
b.Run("old", func(b *testing.B) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue