Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit 0df6d75

Browse files
minh-bqhuyngopt1994
authored andcommitted
eth: only enable accepting transactions after checking (#686)
We need to check if the current head passes the required checkpoint and the head is not too old before enabling accepting transactions. So disable fast/snap sync and set pathdb's buffer manually, don't use enableSyncedFeatures which enables accepting transaction unconditionally. Reported-by: 0xarno <[email protected]>
1 parent d9da3a3 commit 0df6d75

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

eth/sync.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/ethereum/go-ethereum/eth/downloader"
2929
"github.com/ethereum/go-ethereum/eth/protocols/eth"
3030
"github.com/ethereum/go-ethereum/log"
31+
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"
3132
)
3233

3334
const (
@@ -243,8 +244,23 @@ func (h *handler) doSync(op *chainSyncOp) error {
243244
if err != nil {
244245
return err
245246
}
246-
h.enableSyncedFeatures()
247247

248+
// If we were running fast/snap sync and it finished, disable doing another
249+
// round on next sync cycle
250+
if atomic.LoadUint32(&h.fastSync) == 1 {
251+
log.Info("Fast sync complete, auto disabling")
252+
atomic.StoreUint32(&h.fastSync, 0)
253+
}
254+
if atomic.LoadUint32(&h.snapSync) == 1 {
255+
log.Info("Snap sync complete, auto disabling")
256+
atomic.StoreUint32(&h.snapSync, 0)
257+
}
258+
if h.chain.TrieDB().Scheme() == rawdb.PathScheme {
259+
h.chain.TrieDB().SetBufferSize(pathdb.DefaultBufferSize)
260+
}
261+
262+
// If we've successfully finished a sync cycle and passed any required checkpoint,
263+
// enable accepting transactions from the network.
248264
head := h.chain.CurrentBlock()
249265
if head.NumberU64() >= h.checkpointNumber {
250266
// Checkpoint passed, sanity check the timestamp to have a fallback mechanism

0 commit comments

Comments
 (0)