-
Notifications
You must be signed in to change notification settings - Fork 20.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eth/downloader: implement beacon sync #23982
Changes from 17 commits
0f78c4f
0d22561
786308d
49b7771
3f16180
1c5a698
344d81a
944e050
0a50767
f6a427d
ba9e91f
ef4d465
92020c9
46c0e3f
336b5df
38114ad
71861e7
7ac324b
4f2c4e9
2cb92eb
bec4fd6
7c12053
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2021 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package rawdb | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/ethdb" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/rlp" | ||
) | ||
|
||
// ReadSkeletonSyncStatus retrieves the serialized sync status saved at shutdown. | ||
func ReadSkeletonSyncStatus(db ethdb.KeyValueReader) []byte { | ||
data, _ := db.Get(skeletonSyncStatusKey) | ||
return data | ||
} | ||
|
||
// WriteSkeletonSyncStatus stores the serialized sync status to save at shutdown. | ||
func WriteSkeletonSyncStatus(db ethdb.KeyValueWriter, status []byte) { | ||
if err := db.Put(skeletonSyncStatusKey, status); err != nil { | ||
log.Crit("Failed to store skeleton sync status", "err", err) | ||
} | ||
} | ||
|
||
// DeleteSkeletonSyncStatus deletes the serialized sync status saved at the last | ||
// shutdown | ||
func DeleteSkeletonSyncStatus(db ethdb.KeyValueWriter) { | ||
if err := db.Delete(skeletonSyncStatusKey); err != nil { | ||
log.Crit("Failed to remove skeleton sync status", "err", err) | ||
} | ||
} | ||
|
||
// ReadSkeletonHeader retrieves a block header from the skeleton sync store, | ||
func ReadSkeletonHeader(db ethdb.KeyValueReader, number uint64) *types.Header { | ||
data, _ := db.Get(skeletonHeaderKey(number)) | ||
if len(data) == 0 { | ||
return nil | ||
} | ||
header := new(types.Header) | ||
if err := rlp.Decode(bytes.NewReader(data), header); err != nil { | ||
log.Error("Invalid skeleton header RLP", "number", number, "err", err) | ||
return nil | ||
} | ||
return header | ||
} | ||
|
||
// WriteSkeletonHeader stores a block header into the skeleton sync store. | ||
func WriteSkeletonHeader(db ethdb.KeyValueWriter, header *types.Header) { | ||
data, err := rlp.EncodeToBytes(header) | ||
if err != nil { | ||
log.Crit("Failed to RLP encode header", "err", err) | ||
} | ||
key := skeletonHeaderKey(header.Number.Uint64()) | ||
if err := db.Put(key, data); err != nil { | ||
log.Crit("Failed to store skeleton header", "err", err) | ||
} | ||
} | ||
|
||
// DeleteSkeletonHeader removes all block header data associated with a hash. | ||
func DeleteSkeletonHeader(db ethdb.KeyValueWriter, number uint64) { | ||
if err := db.Delete(skeletonHeaderKey(number)); err != nil { | ||
log.Crit("Failed to delete skeleton header", "err", err) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,9 @@ var ( | |
// snapshotSyncStatusKey tracks the snapshot sync status across restarts. | ||
snapshotSyncStatusKey = []byte("SnapshotSyncStatus") | ||
|
||
// skeletonSyncStatusKey tracks the skeleton sync status across restarts. | ||
skeletonSyncStatusKey = []byte("SkeletonSyncStatus") | ||
|
||
// txIndexTailKey tracks the oldest block whose transactions have been indexed. | ||
txIndexTailKey = []byte("TransactionIndexTail") | ||
|
||
|
@@ -92,6 +95,7 @@ var ( | |
SnapshotAccountPrefix = []byte("a") // SnapshotAccountPrefix + account hash -> account trie value | ||
SnapshotStoragePrefix = []byte("o") // SnapshotStoragePrefix + account hash + storage hash -> storage trie value | ||
CodePrefix = []byte("c") // CodePrefix + code hash -> account code | ||
skeletonHeaderPrefix = []byte("S") // skeletonHeaderPrefox + num (uint64 big endian) -> header | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use something that doesn't clash with the meta entries. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Myeah, changing this would cause all merge testnet nodes to blow up since they'd need a database upgrade (i.e. resync). I don't really see it as valuable as how much a PITA it is to change. |
||
|
||
PreimagePrefix = []byte("secure-key-") // PreimagePrefix + hash -> preimage | ||
configPrefix = []byte("ethereum-config-") // config prefix for the db | ||
|
@@ -210,6 +214,11 @@ func bloomBitsKey(bit uint, section uint64, hash common.Hash) []byte { | |
return key | ||
} | ||
|
||
// skeletonHeaderKey = skeletonHeaderPrefix + num (uint64 big endian) | ||
func skeletonHeaderKey(number uint64) []byte { | ||
return append(skeletonHeaderPrefix, encodeBlockNumber(number)...) | ||
} | ||
|
||
// preimageKey = PreimagePrefix + hash | ||
func preimageKey(hash common.Hash) []byte { | ||
return append(PreimagePrefix, hash.Bytes()...) | ||
|
This comment was marked as spam.
Sorry, something went wrong.