Skip to content

Commit ce55507

Browse files
committed
eth: request ID based message dispatcher
1 parent e185a8c commit ce55507

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3129
-3381
lines changed

cmd/utils/flags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ var (
209209
defaultSyncMode = ethconfig.Defaults.SyncMode
210210
SyncModeFlag = TextMarshalerFlag{
211211
Name: "syncmode",
212-
Usage: `Blockchain sync mode ("fast", "full", "snap" or "light")`,
212+
Usage: `Blockchain sync mode ("snap", "full" or "light")`,
213213
Value: &defaultSyncMode,
214214
}
215215
GCModeFlag = cli.StringFlag{

core/blockchain.go

+9-15
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,9 @@ func (bc *BlockChain) SetHeadBeyondRoot(head uint64, root common.Hash) (uint64,
631631
return rootNumber, bc.loadLastState()
632632
}
633633

634-
// FastSyncCommitHead sets the current head block to the one defined by the hash
634+
// SnapSyncCommitHead sets the current head block to the one defined by the hash
635635
// irrelevant what the chain contents were prior.
636-
func (bc *BlockChain) FastSyncCommitHead(hash common.Hash) error {
636+
func (bc *BlockChain) SnapSyncCommitHead(hash common.Hash) error {
637637
// Make sure that both the block as well at its state trie exists
638638
block := bc.GetBlockByHash(hash)
639639
if block == nil {
@@ -738,30 +738,24 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
738738
//
739739
// Note, this function assumes that the `mu` mutex is held!
740740
func (bc *BlockChain) writeHeadBlock(block *types.Block) {
741-
// If the block is on a side chain or an unknown one, force other heads onto it too
742-
updateHeads := rawdb.ReadCanonicalHash(bc.db, block.NumberU64()) != block.Hash()
743-
744741
// Add the block to the canonical chain number scheme and mark as the head
745742
batch := bc.db.NewBatch()
743+
rawdb.WriteHeadHeaderHash(batch, block.Hash())
744+
rawdb.WriteHeadFastBlockHash(batch, block.Hash())
746745
rawdb.WriteCanonicalHash(batch, block.Hash(), block.NumberU64())
747746
rawdb.WriteTxLookupEntriesByBlock(batch, block)
748747
rawdb.WriteHeadBlockHash(batch, block.Hash())
749748

750-
// If the block is better than our head or is on a different chain, force update heads
751-
if updateHeads {
752-
rawdb.WriteHeadHeaderHash(batch, block.Hash())
753-
rawdb.WriteHeadFastBlockHash(batch, block.Hash())
754-
}
755749
// Flush the whole batch into the disk, exit the node if failed
756750
if err := batch.Write(); err != nil {
757751
log.Crit("Failed to update chain indexes and markers", "err", err)
758752
}
759753
// Update all in-memory chain markers in the last step
760-
if updateHeads {
761-
bc.hc.SetCurrentHeader(block.Header())
762-
bc.currentFastBlock.Store(block)
763-
headFastBlockGauge.Update(int64(block.NumberU64()))
764-
}
754+
bc.hc.SetCurrentHeader(block.Header())
755+
756+
bc.currentFastBlock.Store(block)
757+
headFastBlockGauge.Update(int64(block.NumberU64()))
758+
765759
bc.currentBlock.Store(block)
766760
headBlockGauge.Update(int64(block.NumberU64()))
767761
}

core/blockchain_repair_test.go

+112-112
Large diffs are not rendered by default.

core/blockchain_sethead_test.go

+120-120
Large diffs are not rendered by default.

core/blockchain_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2270,7 +2270,7 @@ func TestTransactionIndices(t *testing.T) {
22702270
}
22712271
}
22722272

2273-
func TestSkipStaleTxIndicesInFastSync(t *testing.T) {
2273+
func TestSkipStaleTxIndicesInSnapSync(t *testing.T) {
22742274
// Configure and generate a sample block chain
22752275
var (
22762276
gendb = rawdb.NewMemoryDatabase()

core/chain_makers.go

+22
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,28 @@ func (b *BlockGen) TxNonce(addr common.Address) uint64 {
155155

156156
// AddUncle adds an uncle header to the generated block.
157157
func (b *BlockGen) AddUncle(h *types.Header) {
158+
// The uncle will have the same timestamp and auto-generated difficulty
159+
h.Time = b.header.Time
160+
161+
var parent *types.Header
162+
for i := b.i - 1; i >= 0; i-- {
163+
if b.chain[i].Hash() == h.ParentHash {
164+
parent = b.chain[i].Header()
165+
break
166+
}
167+
}
168+
chainreader := &fakeChainReader{config: b.config}
169+
h.Difficulty = b.engine.CalcDifficulty(chainreader, b.header.Time, parent)
170+
171+
// The gas limit and price should be derived from the parent
172+
h.GasLimit = parent.GasLimit
173+
if b.config.IsLondon(h.Number) {
174+
h.BaseFee = misc.CalcBaseFee(b.config, parent)
175+
if !b.config.IsLondon(parent.Number) {
176+
parentGasLimit := parent.GasLimit * params.ElasticityMultiplier
177+
h.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit)
178+
}
179+
}
158180
b.uncles = append(b.uncles, h)
159181
}
160182

core/rawdb/accessors_chain.go

-18
Original file line numberDiff line numberDiff line change
@@ -242,24 +242,6 @@ func WriteLastPivotNumber(db ethdb.KeyValueWriter, pivot uint64) {
242242
}
243243
}
244244

245-
// ReadFastTrieProgress retrieves the number of tries nodes fast synced to allow
246-
// reporting correct numbers across restarts.
247-
func ReadFastTrieProgress(db ethdb.KeyValueReader) uint64 {
248-
data, _ := db.Get(fastTrieProgressKey)
249-
if len(data) == 0 {
250-
return 0
251-
}
252-
return new(big.Int).SetBytes(data).Uint64()
253-
}
254-
255-
// WriteFastTrieProgress stores the fast sync trie process counter to support
256-
// retrieving it across restarts.
257-
func WriteFastTrieProgress(db ethdb.KeyValueWriter, count uint64) {
258-
if err := db.Put(fastTrieProgressKey, new(big.Int).SetUint64(count).Bytes()); err != nil {
259-
log.Crit("Failed to store fast sync trie progress", "err", err)
260-
}
261-
}
262-
263245
// ReadTxIndexTail retrieves the number of oldest indexed block
264246
// whose transaction indices has been indexed. If the corresponding entry
265247
// is non-existent in database it means the indexing has been finished.

core/rawdb/accessors_snapshot.go

-8
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,3 @@ func WriteSnapshotSyncStatus(db ethdb.KeyValueWriter, status []byte) {
208208
log.Crit("Failed to store snapshot sync status", "err", err)
209209
}
210210
}
211-
212-
// DeleteSnapshotSyncStatus deletes the serialized sync status saved at the last
213-
// shutdown
214-
func DeleteSnapshotSyncStatus(db ethdb.KeyValueWriter) {
215-
if err := db.Delete(snapshotSyncStatusKey); err != nil {
216-
log.Crit("Failed to remove snapshot sync status", "err", err)
217-
}
218-
}

0 commit comments

Comments
 (0)