mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
core/txpool/blobpool: add test
This commit is contained in:
parent
d75e28ee32
commit
76e3a3686f
1 changed files with 91 additions and 10 deletions
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -50,6 +51,7 @@ var (
|
||||||
testBlobs []*kzg4844.Blob
|
testBlobs []*kzg4844.Blob
|
||||||
testBlobCommits []kzg4844.Commitment
|
testBlobCommits []kzg4844.Commitment
|
||||||
testBlobProofs []kzg4844.Proof
|
testBlobProofs []kzg4844.Proof
|
||||||
|
testBlobCellProofs [][]kzg4844.Proof
|
||||||
testBlobVHashes [][32]byte
|
testBlobVHashes [][32]byte
|
||||||
testBlobIndices = make(map[[32]byte]int)
|
testBlobIndices = make(map[[32]byte]int)
|
||||||
)
|
)
|
||||||
|
|
@ -67,6 +69,9 @@ func init() {
|
||||||
testBlobProof, _ := kzg4844.ComputeBlobProof(testBlob, testBlobCommit)
|
testBlobProof, _ := kzg4844.ComputeBlobProof(testBlob, testBlobCommit)
|
||||||
testBlobProofs = append(testBlobProofs, testBlobProof)
|
testBlobProofs = append(testBlobProofs, testBlobProof)
|
||||||
|
|
||||||
|
testBlobCellProof, _ := kzg4844.ComputeCellProofs(testBlob)
|
||||||
|
testBlobCellProofs = append(testBlobCellProofs, testBlobCellProof)
|
||||||
|
|
||||||
testBlobVHash := kzg4844.CalcBlobHashV1(sha256.New(), &testBlobCommit)
|
testBlobVHash := kzg4844.CalcBlobHashV1(sha256.New(), &testBlobCommit)
|
||||||
testBlobIndices[testBlobVHash] = len(testBlobVHashes)
|
testBlobIndices[testBlobVHash] = len(testBlobVHashes)
|
||||||
testBlobVHashes = append(testBlobVHashes, testBlobVHash)
|
testBlobVHashes = append(testBlobVHashes, testBlobVHash)
|
||||||
|
|
@ -416,24 +421,40 @@ func verifyBlobRetrievals(t *testing.T, pool *BlobPool) {
|
||||||
hashes = append(hashes, tx.vhashes...)
|
hashes = append(hashes, tx.vhashes...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blobs, _, proofs, err := pool.GetBlobs(hashes, types.BlobSidecarVersion0)
|
blobs1, _, proofs1, err := pool.GetBlobs(hashes, types.BlobSidecarVersion0)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
blobs2, _, proofs2, err := pool.GetBlobs(hashes, types.BlobSidecarVersion1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// Cross validate what we received vs what we wanted
|
// Cross validate what we received vs what we wanted
|
||||||
if len(blobs) != len(hashes) || len(proofs) != len(hashes) {
|
if len(blobs1) != len(hashes) || len(proofs1) != len(hashes) {
|
||||||
t.Errorf("retrieved blobs/proofs size mismatch: have %d/%d, want %d", len(blobs), len(proofs), len(hashes))
|
t.Errorf("retrieved blobs/proofs size mismatch: have %d/%d, want %d", len(blobs1), len(proofs1), len(hashes))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(blobs2) != len(hashes) || len(proofs2) != len(hashes) {
|
||||||
|
t.Errorf("retrieved blobs/proofs size mismatch: have %d/%d, want blobs %d, want proofs: %d", len(blobs2), len(proofs2), len(hashes), len(hashes))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for i, hash := range hashes {
|
for i, hash := range hashes {
|
||||||
// If an item is missing, but shouldn't, error
|
// If an item is missing, but shouldn't, error
|
||||||
if blobs[i] == nil || proofs[i] == nil {
|
if blobs1[i] == nil || proofs1[i] == nil {
|
||||||
|
t.Errorf("tracked blob retrieval failed: item %d, hash %x", i, hash)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if blobs2[i] == nil || proofs2[i] == nil {
|
||||||
t.Errorf("tracked blob retrieval failed: item %d, hash %x", i, hash)
|
t.Errorf("tracked blob retrieval failed: item %d, hash %x", i, hash)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Item retrieved, make sure it matches the expectation
|
// Item retrieved, make sure it matches the expectation
|
||||||
index := testBlobIndices[hash]
|
index := testBlobIndices[hash]
|
||||||
if *blobs[i] != *testBlobs[index] || proofs[i][0] != testBlobProofs[index] {
|
if *blobs1[i] != *testBlobs[index] || proofs1[i][0] != testBlobProofs[index] {
|
||||||
|
t.Errorf("retrieved blob or proof mismatch: item %d, hash %x", i, hash)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if *blobs2[i] != *testBlobs[index] || !slices.Equal(proofs2[i], testBlobCellProofs[index]) {
|
||||||
t.Errorf("retrieved blob or proof mismatch: item %d, hash %x", i, hash)
|
t.Errorf("retrieved blob or proof mismatch: item %d, hash %x", i, hash)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -1668,6 +1689,66 @@ func TestAdd(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests that adding the transactions with legacy sidecar and expect them to
|
||||||
|
// be converted to new format correctly.
|
||||||
|
func TestAddLegacyBlobTx(t *testing.T) {
|
||||||
|
var (
|
||||||
|
key1, _ = crypto.GenerateKey()
|
||||||
|
key2, _ = crypto.GenerateKey()
|
||||||
|
|
||||||
|
addr1 = crypto.PubkeyToAddress(key1.PublicKey)
|
||||||
|
addr2 = crypto.PubkeyToAddress(key2.PublicKey)
|
||||||
|
)
|
||||||
|
|
||||||
|
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting())
|
||||||
|
statedb.AddBalance(addr1, uint256.NewInt(1_000_000_000), tracing.BalanceChangeUnspecified)
|
||||||
|
statedb.AddBalance(addr2, uint256.NewInt(1_000_000_000), tracing.BalanceChangeUnspecified)
|
||||||
|
statedb.Commit(0, true, false)
|
||||||
|
|
||||||
|
// Make Prague-enabled custom chain config.
|
||||||
|
cancunTime := uint64(0)
|
||||||
|
pragueTime := uint64(0)
|
||||||
|
osakaTime := uint64(0)
|
||||||
|
config := ¶ms.ChainConfig{
|
||||||
|
ChainID: big.NewInt(1),
|
||||||
|
LondonBlock: big.NewInt(0),
|
||||||
|
BerlinBlock: big.NewInt(0),
|
||||||
|
CancunTime: &cancunTime,
|
||||||
|
PragueTime: &pragueTime,
|
||||||
|
OsakaTime: &osakaTime,
|
||||||
|
BlobScheduleConfig: ¶ms.BlobScheduleConfig{
|
||||||
|
Cancun: params.DefaultCancunBlobConfig,
|
||||||
|
Prague: params.DefaultPragueBlobConfig,
|
||||||
|
Osaka: params.DefaultOsakaBlobConfig,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
chain := &testBlockChain{
|
||||||
|
config: config,
|
||||||
|
basefee: uint256.NewInt(1050),
|
||||||
|
blobfee: uint256.NewInt(105),
|
||||||
|
statedb: statedb,
|
||||||
|
}
|
||||||
|
pool := New(Config{Datadir: t.TempDir()}, chain, nil)
|
||||||
|
if err := pool.Init(1, chain.CurrentBlock(), newReserver()); err != nil {
|
||||||
|
t.Fatalf("failed to create blob pool: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to add legacy blob transactions.
|
||||||
|
var (
|
||||||
|
tx1 = makeMultiBlobTx(0, 1, 1000, 100, 6, 0, key1, types.BlobSidecarVersion0)
|
||||||
|
tx2 = makeMultiBlobTx(0, 1, 800, 70, 6, 6, key2, types.BlobSidecarVersion0)
|
||||||
|
tx3 = makeMultiBlobTx(1, 1, 800, 70, 6, 12, key2, types.BlobSidecarVersion1)
|
||||||
|
)
|
||||||
|
errs := pool.Add([]*types.Transaction{tx1, tx2, tx3}, true)
|
||||||
|
for _, err := range errs {
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to add tx: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
verifyPoolInternals(t, pool)
|
||||||
|
pool.Close()
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetBlobs(t *testing.T) {
|
func TestGetBlobs(t *testing.T) {
|
||||||
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue