Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions eth/fetcher/tx_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package fetcher

import (
"crypto/sha256"
"errors"
"math/big"
"math/rand"
Expand All @@ -28,7 +29,10 @@ import (
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
)

var (
Expand Down Expand Up @@ -1908,6 +1912,114 @@ func TestTransactionFetcherDropAlternates(t *testing.T) {
})
}

func makeInvalidBlobTx() *types.Transaction {
key, _ := crypto.GenerateKey()
blob := &kzg4844.Blob{byte(0xa)}
commitment, _ := kzg4844.BlobToCommitment(blob)
blobHash := kzg4844.CalcBlobHashV1(sha256.New(), &commitment)
cellProof, _ := kzg4844.ComputeCellProofs(blob)

// Mutate the cell proof
cellProof[0][0] = 0x0

blobtx := &types.BlobTx{
ChainID: uint256.MustFromBig(params.MainnetChainConfig.ChainID),
Nonce: 0,
GasTipCap: uint256.NewInt(100),
GasFeeCap: uint256.NewInt(200),
Gas: 21000,
BlobFeeCap: uint256.NewInt(200),
BlobHashes: []common.Hash{blobHash},
Value: uint256.NewInt(100),
Sidecar: types.NewBlobTxSidecar(types.BlobSidecarVersion1, []kzg4844.Blob{*blob}, []kzg4844.Commitment{commitment}, cellProof),
}
return types.MustSignNewTx(key, types.LatestSigner(params.MainnetChainConfig), blobtx)
}

// This test ensures that the peer will be disconnected for protocol violation
// and all its internal traces should be removed properly.
func TestTransactionProtocolViolation(t *testing.T) {
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelDebug, true)))

var (
badTx = makeInvalidBlobTx()
drop = make(chan struct{}, 1)
)
testTransactionFetcherParallel(t, txFetcherTest{
init: func() *TxFetcher {
return NewTxFetcher(
func(common.Hash) bool { return false },
func(txs []*types.Transaction) []error {
var errs []error
for range txs {
errs = append(errs, txpool.ErrKZGVerificationError)
}
return errs
},
func(a string, b []common.Hash) error {
return nil
},
func(peer string) { drop <- struct{}{} },
)
},
steps: []interface{}{
// Initial announcement to get something into the waitlist
doTxNotify{
peer: "A",
hashes: []common.Hash{testTxs[0].Hash(), badTx.Hash(), testTxs[1].Hash()},
types: []byte{types.LegacyTxType, types.BlobTxType, types.LegacyTxType},
sizes: []uint32{uint32(testTxs[0].Size()), uint32(badTx.Size()), uint32(testTxs[1].Size())},
},
isWaiting(map[string][]announce{
"A": {
{testTxs[0].Hash(), types.LegacyTxType, uint32(testTxs[0].Size())},
{badTx.Hash(), types.BlobTxType, uint32(badTx.Size())},
{testTxs[1].Hash(), types.LegacyTxType, uint32(testTxs[1].Size())},
},
}),
doWait{time: 0, step: true}, // zero time, but the blob fetching should be scheduled

isWaiting(map[string][]announce{
"A": {
{testTxs[0].Hash(), types.LegacyTxType, uint32(testTxs[0].Size())},
{testTxs[1].Hash(), types.LegacyTxType, uint32(testTxs[1].Size())},
},
}),
isScheduled{
tracking: map[string][]announce{
"A": {
{badTx.Hash(), types.BlobTxType, uint32(badTx.Size())},
},
},
fetching: map[string][]common.Hash{
"A": {badTx.Hash()},
},
},

doTxEnqueue{
peer: "A",
txs: []*types.Transaction{badTx},
direct: true,
},
// Some internal traces are left and will be cleaned by a following drop
// operation.
isWaiting(map[string][]announce{
"A": {
{testTxs[0].Hash(), types.LegacyTxType, uint32(testTxs[0].Size())},
{testTxs[1].Hash(), types.LegacyTxType, uint32(testTxs[1].Size())},
},
}),
isScheduled{},
doFunc(func() { <-drop }),

// Simulate the drop operation emitted by the server
doDrop("A"),
isWaiting(nil),
isScheduled{nil, nil, nil},
},
})
}

func testTransactionFetcherParallel(t *testing.T, tt txFetcherTest) {
t.Parallel()
testTransactionFetcher(t, tt)
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
const (
Major = 1 // Major version component of the current release
Minor = 16 // Minor version component of the current release
Patch = 7 // Patch version component of the current release
Patch = 8 // Patch version component of the current release
Meta = "stable" // Version metadata to append to the version string
)

Expand Down