From 27654d30228f9de2c15e351948103ae619364f36 Mon Sep 17 00:00:00 2001 From: David Theodore <29786815+infosecual@users.noreply.github.com> Date: Thu, 20 Jun 2024 07:08:54 -0500 Subject: [PATCH 1/4] p2p/rlpx: 2KB maximum size for handshake messages (#30029) Co-authored-by: Felix Lange --- p2p/rlpx/rlpx.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/p2p/rlpx/rlpx.go b/p2p/rlpx/rlpx.go index a338490e62..dd14822dee 100644 --- a/p2p/rlpx/rlpx.go +++ b/p2p/rlpx/rlpx.go @@ -604,6 +604,11 @@ func (h *handshakeState) readMsg(msg interface{}, prv *ecdsa.PrivateKey, r io.Re } size := binary.BigEndian.Uint16(prefix) + // baseProtocolMaxMsgSize = 2 * 1024 + if size > 2048 { + return nil, errors.New("message too big") + } + // Read the handshake packet. packet, err := h.rbuf.read(r, int(size)) if err != nil { From e0e45dbc32501d7917edb07083aa1c34ab7b0fb4 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Fri, 21 Jun 2024 09:51:03 +0800 Subject: [PATCH 2/4] core/state/snapshot: tiny fixes (#29995) --- core/state/snapshot/generate.go | 9 +-------- core/state/snapshot/snapshot.go | 10 ++-------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/core/state/snapshot/generate.go b/core/state/snapshot/generate.go index d81a628c91..6d9e163075 100644 --- a/core/state/snapshot/generate.go +++ b/core/state/snapshot/generate.go @@ -631,16 +631,10 @@ func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) er accMarker = nil return nil } - // Always reset the initial account range as 1 whenever recover from the - // interruption. TODO(rjl493456442) can we remove it? - var accountRange = accountCheckRange - if len(accMarker) > 0 { - accountRange = 1 - } origin := common.CopyBytes(accMarker) for { id := trie.StateTrieID(dl.root) - exhausted, last, err := dl.generateRange(ctx, id, rawdb.SnapshotAccountPrefix, snapAccount, origin, accountRange, onAccount, types.FullAccountRLP) + exhausted, last, err := dl.generateRange(ctx, id, rawdb.SnapshotAccountPrefix, snapAccount, origin, accountCheckRange, onAccount, types.FullAccountRLP) if err != nil { return err // The procedure it aborted, either by external signal or internal error. } @@ -652,7 +646,6 @@ func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) er ctx.removeStorageLeft() break } - accountRange = accountCheckRange } return nil } diff --git a/core/state/snapshot/snapshot.go b/core/state/snapshot/snapshot.go index 752f4359fb..e319c8e4e0 100644 --- a/core/state/snapshot/snapshot.go +++ b/core/state/snapshot/snapshot.go @@ -258,14 +258,6 @@ func (t *Tree) Disable() { for _, layer := range t.layers { switch layer := layer.(type) { case *diskLayer: - - layer.lock.RLock() - generating := layer.genMarker != nil - layer.lock.RUnlock() - if !generating { - // Generator is already aborted or finished - break - } // If the base layer is generating, abort it if layer.genAbort != nil { abort := make(chan *generatorStats) @@ -276,6 +268,7 @@ func (t *Tree) Disable() { layer.lock.Lock() layer.stale = true layer.lock.Unlock() + layer.Release() case *diffLayer: // If the layer is a simple diff, simply mark as stale @@ -740,6 +733,7 @@ func (t *Tree) Rebuild(root common.Hash) { layer.lock.Lock() layer.stale = true layer.lock.Unlock() + layer.Release() case *diffLayer: // If the layer is a simple diff, simply mark as stale From c10ac4f48fb9c985390be0f46115aaa40a4ef16d Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Fri, 21 Jun 2024 15:42:43 +0800 Subject: [PATCH 3/4] Revert "core/state/snapshot: tiny fixes" (#30039) Revert "core/state/snapshot: tiny fixes (#29995)" This reverts commit e0e45dbc32501d7917edb07083aa1c34ab7b0fb4. --- core/state/snapshot/generate.go | 9 ++++++++- core/state/snapshot/snapshot.go | 10 ++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/core/state/snapshot/generate.go b/core/state/snapshot/generate.go index 6d9e163075..d81a628c91 100644 --- a/core/state/snapshot/generate.go +++ b/core/state/snapshot/generate.go @@ -631,10 +631,16 @@ func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) er accMarker = nil return nil } + // Always reset the initial account range as 1 whenever recover from the + // interruption. TODO(rjl493456442) can we remove it? + var accountRange = accountCheckRange + if len(accMarker) > 0 { + accountRange = 1 + } origin := common.CopyBytes(accMarker) for { id := trie.StateTrieID(dl.root) - exhausted, last, err := dl.generateRange(ctx, id, rawdb.SnapshotAccountPrefix, snapAccount, origin, accountCheckRange, onAccount, types.FullAccountRLP) + exhausted, last, err := dl.generateRange(ctx, id, rawdb.SnapshotAccountPrefix, snapAccount, origin, accountRange, onAccount, types.FullAccountRLP) if err != nil { return err // The procedure it aborted, either by external signal or internal error. } @@ -646,6 +652,7 @@ func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) er ctx.removeStorageLeft() break } + accountRange = accountCheckRange } return nil } diff --git a/core/state/snapshot/snapshot.go b/core/state/snapshot/snapshot.go index e319c8e4e0..752f4359fb 100644 --- a/core/state/snapshot/snapshot.go +++ b/core/state/snapshot/snapshot.go @@ -258,6 +258,14 @@ func (t *Tree) Disable() { for _, layer := range t.layers { switch layer := layer.(type) { case *diskLayer: + + layer.lock.RLock() + generating := layer.genMarker != nil + layer.lock.RUnlock() + if !generating { + // Generator is already aborted or finished + break + } // If the base layer is generating, abort it if layer.genAbort != nil { abort := make(chan *generatorStats) @@ -268,7 +276,6 @@ func (t *Tree) Disable() { layer.lock.Lock() layer.stale = true layer.lock.Unlock() - layer.Release() case *diffLayer: // If the layer is a simple diff, simply mark as stale @@ -733,7 +740,6 @@ func (t *Tree) Rebuild(root common.Hash) { layer.lock.Lock() layer.stale = true layer.lock.Unlock() - layer.Release() case *diffLayer: // If the layer is a simple diff, simply mark as stale From a71f6f91fdb2fcccdd0c1e336267951d45932f26 Mon Sep 17 00:00:00 2001 From: Halimao <1065621723@qq.com> Date: Fri, 21 Jun 2024 21:29:07 +0800 Subject: [PATCH 4/4] p2p/discover: improve flaky revalidation tests (#30023) --- p2p/discover/table_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/discover/table_test.go b/p2p/discover/table_test.go index 2f1797d1e2..8cc4ae33b2 100644 --- a/p2p/discover/table_test.go +++ b/p2p/discover/table_test.go @@ -135,7 +135,7 @@ func waitForRevalidationPing(t *testing.T, transport *pingRecorder, tab *Table, simclock.Run(tab.cfg.PingInterval * slowRevalidationFactor) p := transport.waitPing(2 * time.Second) if p == nil { - t.Fatal("Table did not send revalidation ping") + continue } if id == (enode.ID{}) || p.ID() == id { return p