@@ -27,6 +27,7 @@ import (
27
27
"os"
28
28
"path/filepath"
29
29
"reflect"
30
+ "slices"
30
31
"sync"
31
32
"testing"
32
33
@@ -47,11 +48,12 @@ import (
47
48
)
48
49
49
50
var (
50
- testBlobs []* kzg4844.Blob
51
- testBlobCommits []kzg4844.Commitment
52
- testBlobProofs []kzg4844.Proof
53
- testBlobVHashes [][32 ]byte
54
- testBlobIndices = make (map [[32 ]byte ]int )
51
+ testBlobs []* kzg4844.Blob
52
+ testBlobCommits []kzg4844.Commitment
53
+ testBlobProofs []kzg4844.Proof
54
+ testBlobCellProofs [][]kzg4844.Proof
55
+ testBlobVHashes [][32 ]byte
56
+ testBlobIndices = make (map [[32 ]byte ]int )
55
57
)
56
58
57
59
const testMaxBlobsPerBlock = 6
@@ -67,6 +69,9 @@ func init() {
67
69
testBlobProof , _ := kzg4844 .ComputeBlobProof (testBlob , testBlobCommit )
68
70
testBlobProofs = append (testBlobProofs , testBlobProof )
69
71
72
+ testBlobCellProof , _ := kzg4844 .ComputeCellProofs (testBlob )
73
+ testBlobCellProofs = append (testBlobCellProofs , testBlobCellProof )
74
+
70
75
testBlobVHash := kzg4844 .CalcBlobHashV1 (sha256 .New (), & testBlobCommit )
71
76
testBlobIndices [testBlobVHash ] = len (testBlobVHashes )
72
77
testBlobVHashes = append (testBlobVHashes , testBlobVHash )
@@ -416,24 +421,40 @@ func verifyBlobRetrievals(t *testing.T, pool *BlobPool) {
416
421
hashes = append (hashes , tx .vhashes ... )
417
422
}
418
423
}
419
- blobs , _ , proofs , err := pool .GetBlobs (hashes , types .BlobSidecarVersion0 )
424
+ blobs1 , _ , proofs1 , err := pool .GetBlobs (hashes , types .BlobSidecarVersion0 )
425
+ if err != nil {
426
+ t .Fatal (err )
427
+ }
428
+ blobs2 , _ , proofs2 , err := pool .GetBlobs (hashes , types .BlobSidecarVersion1 )
420
429
if err != nil {
421
430
t .Fatal (err )
422
431
}
423
432
// Cross validate what we received vs what we wanted
424
- if len (blobs ) != len (hashes ) || len (proofs ) != len (hashes ) {
425
- t .Errorf ("retrieved blobs/proofs size mismatch: have %d/%d, want %d" , len (blobs ), len (proofs ), len (hashes ))
433
+ if len (blobs1 ) != len (hashes ) || len (proofs1 ) != len (hashes ) {
434
+ t .Errorf ("retrieved blobs/proofs size mismatch: have %d/%d, want %d" , len (blobs1 ), len (proofs1 ), len (hashes ))
435
+ return
436
+ }
437
+ if len (blobs2 ) != len (hashes ) || len (proofs2 ) != len (hashes ) {
438
+ t .Errorf ("retrieved blobs/proofs size mismatch: have %d/%d, want blobs %d, want proofs: %d" , len (blobs2 ), len (proofs2 ), len (hashes ), len (hashes ))
426
439
return
427
440
}
428
441
for i , hash := range hashes {
429
442
// If an item is missing, but shouldn't, error
430
- if blobs [i ] == nil || proofs [i ] == nil {
443
+ if blobs1 [i ] == nil || proofs1 [i ] == nil {
444
+ t .Errorf ("tracked blob retrieval failed: item %d, hash %x" , i , hash )
445
+ continue
446
+ }
447
+ if blobs2 [i ] == nil || proofs2 [i ] == nil {
431
448
t .Errorf ("tracked blob retrieval failed: item %d, hash %x" , i , hash )
432
449
continue
433
450
}
434
451
// Item retrieved, make sure it matches the expectation
435
452
index := testBlobIndices [hash ]
436
- if * blobs [i ] != * testBlobs [index ] || proofs [i ][0 ] != testBlobProofs [index ] {
453
+ if * blobs1 [i ] != * testBlobs [index ] || proofs1 [i ][0 ] != testBlobProofs [index ] {
454
+ t .Errorf ("retrieved blob or proof mismatch: item %d, hash %x" , i , hash )
455
+ continue
456
+ }
457
+ if * blobs2 [i ] != * testBlobs [index ] || ! slices .Equal (proofs2 [i ], testBlobCellProofs [index ]) {
437
458
t .Errorf ("retrieved blob or proof mismatch: item %d, hash %x" , i , hash )
438
459
continue
439
460
}
@@ -1668,6 +1689,66 @@ func TestAdd(t *testing.T) {
1668
1689
}
1669
1690
}
1670
1691
1692
+ // Tests that adding the transactions with legacy sidecar and expect them to
1693
+ // be converted to new format correctly.
1694
+ func TestAddLegacyBlobTx (t * testing.T ) {
1695
+ var (
1696
+ key1 , _ = crypto .GenerateKey ()
1697
+ key2 , _ = crypto .GenerateKey ()
1698
+
1699
+ addr1 = crypto .PubkeyToAddress (key1 .PublicKey )
1700
+ addr2 = crypto .PubkeyToAddress (key2 .PublicKey )
1701
+ )
1702
+
1703
+ statedb , _ := state .New (types .EmptyRootHash , state .NewDatabaseForTesting ())
1704
+ statedb .AddBalance (addr1 , uint256 .NewInt (1_000_000_000 ), tracing .BalanceChangeUnspecified )
1705
+ statedb .AddBalance (addr2 , uint256 .NewInt (1_000_000_000 ), tracing .BalanceChangeUnspecified )
1706
+ statedb .Commit (0 , true , false )
1707
+
1708
+ // Make Prague-enabled custom chain config.
1709
+ cancunTime := uint64 (0 )
1710
+ pragueTime := uint64 (0 )
1711
+ osakaTime := uint64 (0 )
1712
+ config := & params.ChainConfig {
1713
+ ChainID : big .NewInt (1 ),
1714
+ LondonBlock : big .NewInt (0 ),
1715
+ BerlinBlock : big .NewInt (0 ),
1716
+ CancunTime : & cancunTime ,
1717
+ PragueTime : & pragueTime ,
1718
+ OsakaTime : & osakaTime ,
1719
+ BlobScheduleConfig : & params.BlobScheduleConfig {
1720
+ Cancun : params .DefaultCancunBlobConfig ,
1721
+ Prague : params .DefaultPragueBlobConfig ,
1722
+ Osaka : params .DefaultOsakaBlobConfig ,
1723
+ },
1724
+ }
1725
+ chain := & testBlockChain {
1726
+ config : config ,
1727
+ basefee : uint256 .NewInt (1050 ),
1728
+ blobfee : uint256 .NewInt (105 ),
1729
+ statedb : statedb ,
1730
+ }
1731
+ pool := New (Config {Datadir : t .TempDir ()}, chain , nil )
1732
+ if err := pool .Init (1 , chain .CurrentBlock (), newReserver ()); err != nil {
1733
+ t .Fatalf ("failed to create blob pool: %v" , err )
1734
+ }
1735
+
1736
+ // Attempt to add legacy blob transactions.
1737
+ var (
1738
+ tx1 = makeMultiBlobTx (0 , 1 , 1000 , 100 , 6 , 0 , key1 , types .BlobSidecarVersion0 )
1739
+ tx2 = makeMultiBlobTx (0 , 1 , 800 , 70 , 6 , 6 , key2 , types .BlobSidecarVersion0 )
1740
+ tx3 = makeMultiBlobTx (1 , 1 , 800 , 70 , 6 , 12 , key2 , types .BlobSidecarVersion1 )
1741
+ )
1742
+ errs := pool .Add ([]* types.Transaction {tx1 , tx2 , tx3 }, true )
1743
+ for _ , err := range errs {
1744
+ if err != nil {
1745
+ t .Fatalf ("failed to add tx: %v" , err )
1746
+ }
1747
+ }
1748
+ verifyPoolInternals (t , pool )
1749
+ pool .Close ()
1750
+ }
1751
+
1671
1752
func TestGetBlobs (t * testing.T ) {
1672
1753
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true)))
1673
1754
0 commit comments