mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-31 00:53:46 +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>
90 lines
2.6 KiB
Go
90 lines
2.6 KiB
Go
// Copyright 2020 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/>.
|
|
|
|
// This file contains some shares testing functionality, common to multiple
|
|
// different files and modules being tested.
|
|
|
|
package eth
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/p2p"
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
)
|
|
|
|
// testPeer is a simulated peer to allow testing direct network calls.
|
|
type testPeer struct {
|
|
*Peer
|
|
|
|
net p2p.MsgReadWriter // Network layer reader/writer to simulate remote messaging
|
|
app *p2p.MsgPipeRW // Application layer reader/writer to simulate the local side
|
|
}
|
|
|
|
// newTestPeer creates a new peer registered at the given data backend.
|
|
func newTestPeer(name string, version uint, backend Backend) (*testPeer, <-chan error) {
|
|
// Create a message pipe to communicate through
|
|
app, net := p2p.MsgPipe()
|
|
|
|
// Start the peer on a new thread
|
|
var id enode.ID
|
|
rand.Read(id[:])
|
|
|
|
peer := NewPeer(version, p2p.NewPeer(id, name, nil), net, backend.TxPool(), backend.BlobPool(), nil)
|
|
errc := make(chan error, 1)
|
|
go func() {
|
|
defer app.Close()
|
|
|
|
errc <- backend.RunPeer(peer, func(peer *Peer) error {
|
|
return Handle(backend, peer)
|
|
})
|
|
}()
|
|
return &testPeer{app: app, net: net, Peer: peer}, errc
|
|
}
|
|
|
|
// close terminates the local side of the peer, notifying the remote protocol
|
|
// manager of termination.
|
|
func (p *testPeer) close() {
|
|
p.Peer.Close()
|
|
p.app.Close()
|
|
}
|
|
|
|
func TestPeerSet(t *testing.T) {
|
|
size := 5
|
|
s := newKnownCache(size)
|
|
|
|
// add 10 items
|
|
for i := 0; i < size*2; i++ {
|
|
s.Add(common.Hash{byte(i)})
|
|
}
|
|
|
|
if s.Cardinality() != size {
|
|
t.Fatalf("wrong size, expected %d but found %d", size, s.Cardinality())
|
|
}
|
|
|
|
vals := []common.Hash{}
|
|
for i := 10; i < 20; i++ {
|
|
vals = append(vals, common.Hash{byte(i)})
|
|
}
|
|
|
|
// add item in batch
|
|
s.Add(vals...)
|
|
if s.Cardinality() < size {
|
|
t.Fatalf("bad size")
|
|
}
|
|
}
|