mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 11:46:44 +00:00
This is the implementation of EIP-8070 Sparse Blobpool. It introduces protocol version eth/72 which relays blob transaction cells instead of full blobs. The blobpool now store 'incomplete' transactions, where only some of the cells are provided. The stored cell indexes are taken from the custody bitmap, which is provided by the consensus layer in forkchoiceUpdatedV4. This method will be called once Glamsterdam activates, and the default custody is full custody, so for now there is no change in the amount of stored cells for now. The main entities added are the BlobBuffer and BlobFetcher, which work together to track and fetch missing cells from connected peers. The partial transactions become available for inclusion in blocks when they are covered by enough peers that hold all cells. This change also introduces engine_getBlobsV4, which allows for cell-based responses (and partial blobs with only some of the cells). We maintain backward compatibility with getBlobsV3 which expects full blob responses by recovering the blob from available cells. Since this process is resource-intensive, we proactively cache the conversion so it is ready in time for getBlobsV3 calls. This mechanism will be removed once support for getBlobsV4 is universal across all consensus layer implementations. devp2p tests for eth/72 are not part of this initial change. This is to avoid breaking test success status for execution clients that do not have eth/72 implemented yet. The tests will be added in a subsequent change. --------- Co-authored-by: Felix Lange <fjl@twurst.com>
101 lines
3.7 KiB
Go
101 lines
3.7 KiB
Go
// Copyright 2015 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 eth
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
|
"github.com/ethereum/go-ethereum/eth/protocols/eth"
|
|
"github.com/ethereum/go-ethereum/eth/protocols/snap"
|
|
"github.com/ethereum/go-ethereum/p2p"
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
)
|
|
|
|
// Tests that snap sync is disabled after a successful sync cycle.
|
|
func TestSnapSyncDisabling69(t *testing.T) { testSnapSyncDisabling(t, eth.ETH69, snap.SNAP1) }
|
|
|
|
// Tests that snap sync gets disabled as soon as a real block is successfully
|
|
// imported into the blockchain.
|
|
func testSnapSyncDisabling(t *testing.T, ethVer uint, snapVer uint) {
|
|
t.Parallel()
|
|
|
|
// Create an empty handler and ensure it's in snap sync mode
|
|
empty := newTestHandler(ethconfig.SnapSync)
|
|
defer empty.close()
|
|
|
|
// Create a full handler and ensure snap sync ends up disabled
|
|
full := newTestHandlerWithBlocks(1024, ethconfig.SnapSync)
|
|
defer full.close()
|
|
|
|
// Sync up the two handlers via both `eth` and `snap`
|
|
caps := []p2p.Cap{{Name: "eth", Version: ethVer}, {Name: "snap", Version: snapVer}}
|
|
|
|
emptyPipeEth, fullPipeEth := p2p.MsgPipe()
|
|
defer emptyPipeEth.Close()
|
|
defer fullPipeEth.Close()
|
|
|
|
emptyPeerEth := eth.NewPeer(ethVer, p2p.NewPeer(enode.ID{1}, "", caps), emptyPipeEth, empty.txpool, empty.blobpool, nil)
|
|
fullPeerEth := eth.NewPeer(ethVer, p2p.NewPeer(enode.ID{2}, "", caps), fullPipeEth, full.txpool, full.blobpool, nil)
|
|
defer emptyPeerEth.Close()
|
|
defer fullPeerEth.Close()
|
|
|
|
go empty.handler.runEthPeer(emptyPeerEth, func(peer *eth.Peer) error {
|
|
return eth.Handle((*ethHandler)(empty.handler), peer)
|
|
})
|
|
go full.handler.runEthPeer(fullPeerEth, func(peer *eth.Peer) error {
|
|
return eth.Handle((*ethHandler)(full.handler), peer)
|
|
})
|
|
|
|
emptyPipeSnap, fullPipeSnap := p2p.MsgPipe()
|
|
defer emptyPipeSnap.Close()
|
|
defer fullPipeSnap.Close()
|
|
|
|
emptyPeerSnap := snap.NewPeer(snapVer, p2p.NewPeer(enode.ID{1}, "", caps), emptyPipeSnap)
|
|
fullPeerSnap := snap.NewPeer(snapVer, p2p.NewPeer(enode.ID{2}, "", caps), fullPipeSnap)
|
|
|
|
go empty.handler.runSnapExtension(emptyPeerSnap, func(peer *snap.Peer) error {
|
|
return snap.Handle((*snapHandler)(empty.handler), peer)
|
|
})
|
|
go full.handler.runSnapExtension(fullPeerSnap, func(peer *snap.Peer) error {
|
|
return snap.Handle((*snapHandler)(full.handler), peer)
|
|
})
|
|
// Wait a bit for the above handlers to start
|
|
time.Sleep(250 * time.Millisecond)
|
|
|
|
// Check that snap sync was disabled
|
|
if err := empty.handler.downloader.BeaconSync(full.chain.CurrentBlock(), nil); err != nil {
|
|
t.Fatal("sync failed:", err)
|
|
}
|
|
// Snap sync and mode switching happen asynchronously, poll for completion.
|
|
timeout := time.NewTimer(15 * time.Second)
|
|
tick := time.NewTicker(100 * time.Millisecond)
|
|
defer timeout.Stop()
|
|
defer tick.Stop()
|
|
|
|
for {
|
|
select {
|
|
case <-timeout.C:
|
|
t.Fatalf("snap sync not disabled after successful synchronisation")
|
|
case <-tick.C:
|
|
if empty.handler.synced.Load() && empty.handler.downloader.ConfigSyncMode() == ethconfig.FullSync {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|