mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
fix eth/protocols/snap/sync_test.go (#589)
This commit is contained in:
parent
8c5bae2e69
commit
60216e44c3
1 changed files with 56 additions and 34 deletions
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto/codehash"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
|
|
@ -1469,7 +1470,7 @@ func key32(i uint64) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
codehashes = []common.Hash{
|
keccakCodehashes = []common.Hash{
|
||||||
crypto.Keccak256Hash([]byte{0}),
|
crypto.Keccak256Hash([]byte{0}),
|
||||||
crypto.Keccak256Hash([]byte{1}),
|
crypto.Keccak256Hash([]byte{1}),
|
||||||
crypto.Keccak256Hash([]byte{2}),
|
crypto.Keccak256Hash([]byte{2}),
|
||||||
|
|
@ -1479,11 +1480,28 @@ var (
|
||||||
crypto.Keccak256Hash([]byte{6}),
|
crypto.Keccak256Hash([]byte{6}),
|
||||||
crypto.Keccak256Hash([]byte{7}),
|
crypto.Keccak256Hash([]byte{7}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
poseidonCodehashes = []common.Hash{
|
||||||
|
codehash.PoseidonCodeHash([]byte{0}),
|
||||||
|
codehash.PoseidonCodeHash([]byte{1}),
|
||||||
|
codehash.PoseidonCodeHash([]byte{2}),
|
||||||
|
codehash.PoseidonCodeHash([]byte{3}),
|
||||||
|
codehash.PoseidonCodeHash([]byte{4}),
|
||||||
|
codehash.PoseidonCodeHash([]byte{5}),
|
||||||
|
codehash.PoseidonCodeHash([]byte{6}),
|
||||||
|
codehash.PoseidonCodeHash([]byte{7}),
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// getCodeHash returns a pseudo-random code hash
|
// getKeccakCodeHash returns a pseudo-random Keccak code hash
|
||||||
func getCodeHash(i uint64) []byte {
|
func getKeccakCodeHash(i uint64) []byte {
|
||||||
h := codehashes[int(i)%len(codehashes)]
|
h := keccakCodehashes[int(i)%len(keccakCodehashes)]
|
||||||
|
return common.CopyBytes(h[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
// getPoseidonCodeHash returns a pseudo-random Poseidon code hash
|
||||||
|
func getPoseidonCodeHash(i uint64) []byte {
|
||||||
|
h := poseidonCodehashes[int(i)%len(poseidonCodehashes)]
|
||||||
return common.CopyBytes(h[:])
|
return common.CopyBytes(h[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1492,7 +1510,7 @@ func getCodeByHash(hash common.Hash) []byte {
|
||||||
if hash == types.EmptyKeccakCodeHash {
|
if hash == types.EmptyKeccakCodeHash {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for i, h := range codehashes {
|
for i, h := range keccakCodehashes {
|
||||||
if h == hash {
|
if h == hash {
|
||||||
return []byte{byte(i)}
|
return []byte{byte(i)}
|
||||||
}
|
}
|
||||||
|
|
@ -1512,8 +1530,8 @@ func makeAccountTrieNoStorage(n int, scheme string) (string, *trie.Trie, []*kv)
|
||||||
Nonce: i,
|
Nonce: i,
|
||||||
Balance: big.NewInt(int64(i)),
|
Balance: big.NewInt(int64(i)),
|
||||||
Root: types.EmptyRootHash,
|
Root: types.EmptyRootHash,
|
||||||
KeccakCodeHash: getCodeHash(i),
|
KeccakCodeHash: getKeccakCodeHash(i),
|
||||||
// TODO: PoseidonCodeHash
|
PoseidonCodeHash: getPoseidonCodeHash(i),
|
||||||
})
|
})
|
||||||
key := key32(i)
|
key := key32(i)
|
||||||
elem := &kv{key, value}
|
elem := &kv{key, value}
|
||||||
|
|
@ -1564,8 +1582,8 @@ func makeBoundaryAccountTrie(scheme string, n int) (string, *trie.Trie, []*kv) {
|
||||||
Nonce: uint64(0),
|
Nonce: uint64(0),
|
||||||
Balance: big.NewInt(int64(i)),
|
Balance: big.NewInt(int64(i)),
|
||||||
Root: types.EmptyRootHash,
|
Root: types.EmptyRootHash,
|
||||||
KeccakCodeHash: getCodeHash(uint64(i)),
|
KeccakCodeHash: getKeccakCodeHash(i),
|
||||||
// TODO: PoseidonCodeHash
|
PoseidonCodeHash: getPoseidonCodeHash(i),
|
||||||
})
|
})
|
||||||
elem := &kv{boundaries[i].Bytes(), value}
|
elem := &kv{boundaries[i].Bytes(), value}
|
||||||
accTrie.MustUpdate(elem.k, elem.v)
|
accTrie.MustUpdate(elem.k, elem.v)
|
||||||
|
|
@ -1577,8 +1595,8 @@ func makeBoundaryAccountTrie(scheme string, n int) (string, *trie.Trie, []*kv) {
|
||||||
Nonce: i,
|
Nonce: i,
|
||||||
Balance: big.NewInt(int64(i)),
|
Balance: big.NewInt(int64(i)),
|
||||||
Root: types.EmptyRootHash,
|
Root: types.EmptyRootHash,
|
||||||
KeccakCodeHash: getCodeHash(i),
|
KeccakCodeHash: getKeccakCodeHash(i),
|
||||||
// TODO: PoseidonCodeHash
|
PoseidonCodeHash: getPoseidonCodeHash(i),
|
||||||
})
|
})
|
||||||
elem := &kv{key32(i), value}
|
elem := &kv{key32(i), value}
|
||||||
accTrie.MustUpdate(elem.k, elem.v)
|
accTrie.MustUpdate(elem.k, elem.v)
|
||||||
|
|
@ -1610,9 +1628,11 @@ func makeAccountTrieWithStorageWithUniqueStorage(scheme string, accounts, slots
|
||||||
// Create n accounts in the trie
|
// Create n accounts in the trie
|
||||||
for i := uint64(1); i <= uint64(accounts); i++ {
|
for i := uint64(1); i <= uint64(accounts); i++ {
|
||||||
key := key32(i)
|
key := key32(i)
|
||||||
codehash := types.EmptyKeccakCodeHash.Bytes()
|
keccakCodehash := types.EmptyKeccakCodeHash.Bytes()
|
||||||
|
poseidonCodeHash := types.EmptyPoseidonCodeHash.Bytes()
|
||||||
if code {
|
if code {
|
||||||
codehash = getCodeHash(i)
|
keccakCodehash = getKeccakCodeHash(i)
|
||||||
|
poseidonCodeHash = getPoseidonCodeHash(i)
|
||||||
}
|
}
|
||||||
// Create a storage trie
|
// Create a storage trie
|
||||||
stRoot, stNodes, stEntries := makeStorageTrieWithSeed(common.BytesToHash(key), uint64(slots), i, db)
|
stRoot, stNodes, stEntries := makeStorageTrieWithSeed(common.BytesToHash(key), uint64(slots), i, db)
|
||||||
|
|
@ -1622,8 +1642,8 @@ func makeAccountTrieWithStorageWithUniqueStorage(scheme string, accounts, slots
|
||||||
Nonce: i,
|
Nonce: i,
|
||||||
Balance: big.NewInt(int64(i)),
|
Balance: big.NewInt(int64(i)),
|
||||||
Root: stRoot,
|
Root: stRoot,
|
||||||
KeccakCodeHash: codehash,
|
KeccakCodeHash: keccakCodeHash,
|
||||||
// TODO: PoseidonCodeHash
|
PoseidonCodeHash: poseidonCodeHash,
|
||||||
})
|
})
|
||||||
elem := &kv{key, value}
|
elem := &kv{key, value}
|
||||||
accTrie.MustUpdate(elem.k, elem.v)
|
accTrie.MustUpdate(elem.k, elem.v)
|
||||||
|
|
@ -1666,9 +1686,11 @@ func makeAccountTrieWithStorage(scheme string, accounts, slots int, code, bounda
|
||||||
// Create n accounts in the trie
|
// Create n accounts in the trie
|
||||||
for i := uint64(1); i <= uint64(accounts); i++ {
|
for i := uint64(1); i <= uint64(accounts); i++ {
|
||||||
key := key32(i)
|
key := key32(i)
|
||||||
codehash := types.EmptyKeccakCodeHash.Bytes()
|
keccakCodehash := types.EmptyKeccakCodeHash.Bytes()
|
||||||
|
poseidonCodeHash := types.EmptyPoseidonCodeHash.Bytes()
|
||||||
if code {
|
if code {
|
||||||
codehash = getCodeHash(i)
|
keccakCodehash = getKeccakCodeHash(i)
|
||||||
|
poseidonCodeHash = getPoseidonCodeHash(i)
|
||||||
}
|
}
|
||||||
// Make a storage trie
|
// Make a storage trie
|
||||||
var (
|
var (
|
||||||
|
|
@ -1689,8 +1711,8 @@ func makeAccountTrieWithStorage(scheme string, accounts, slots int, code, bounda
|
||||||
Nonce: i,
|
Nonce: i,
|
||||||
Balance: big.NewInt(int64(i)),
|
Balance: big.NewInt(int64(i)),
|
||||||
Root: stRoot,
|
Root: stRoot,
|
||||||
KeccakCodeHash: codehash,
|
KeccakCodeHash: keccakCodehash,
|
||||||
// TODO: PoseidonCodeHash
|
PoseidonCodeHash: poseidonCodeHash,
|
||||||
})
|
})
|
||||||
elem := &kv{key, value}
|
elem := &kv{key, value}
|
||||||
accTrie.MustUpdate(elem.k, elem.v)
|
accTrie.MustUpdate(elem.k, elem.v)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue