@@ -27,6 +27,7 @@ import (
27
27
"github.com/ethereum/go-ethereum/common/mclock"
28
28
"github.com/ethereum/go-ethereum/core/txpool"
29
29
"github.com/ethereum/go-ethereum/core/types"
30
+ "github.com/ethereum/go-ethereum/params"
30
31
)
31
32
32
33
var (
@@ -993,15 +994,14 @@ func TestTransactionFetcherTimeoutTimerResets(t *testing.T) {
993
994
})
994
995
}
995
996
996
- // Tests that if thousands of transactions are announces , only a small
997
+ // Tests that if thousands of transactions are announced , only a small
997
998
// number of them will be requested at a time.
998
999
func TestTransactionFetcherRateLimiting (t * testing.T ) {
999
- // Create a slew of transactions and to announce them
1000
+ // Create a slew of transactions and announce them
1000
1001
var hashes []common.Hash
1001
1002
for i := 0 ; i < maxTxAnnounces ; i ++ {
1002
1003
hashes = append (hashes , common.Hash {byte (i / 256 ), byte (i % 256 )})
1003
1004
}
1004
-
1005
1005
testTransactionFetcherParallel (t , txFetcherTest {
1006
1006
init : func () * TxFetcher {
1007
1007
return NewTxFetcher (
@@ -1029,6 +1029,68 @@ func TestTransactionFetcherRateLimiting(t *testing.T) {
1029
1029
})
1030
1030
}
1031
1031
1032
+ // Tests that if huge transactions are announced, only a small number of them will
1033
+ // be requested at a time, to keep the responses below a resonable level.
1034
+ func TestTransactionFetcherBandwidthLimiting (t * testing.T ) {
1035
+ testTransactionFetcherParallel (t , txFetcherTest {
1036
+ init : func () * TxFetcher {
1037
+ return NewTxFetcher (
1038
+ func (common.Hash ) bool { return false },
1039
+ nil ,
1040
+ func (string , []common.Hash ) error { return nil },
1041
+ nil ,
1042
+ )
1043
+ },
1044
+ steps : []interface {}{
1045
+ // Announce mid size transactions from A to verify that multiple
1046
+ // ones can be piled into a single request.
1047
+ doTxNotify {peer : "A" ,
1048
+ hashes : []common.Hash {{0x01 }, {0x02 }, {0x03 }, {0x04 }},
1049
+ types : []byte {types .LegacyTxType , types .LegacyTxType , types .LegacyTxType , types .LegacyTxType },
1050
+ sizes : []uint32 {48 * 1024 , 48 * 1024 , 48 * 1024 , 48 * 1024 },
1051
+ },
1052
+ // Announce exactly on the limit transactions to see that only one
1053
+ // gets requested
1054
+ doTxNotify {peer : "B" ,
1055
+ hashes : []common.Hash {{0x05 }, {0x06 }},
1056
+ types : []byte {types .LegacyTxType , types .LegacyTxType },
1057
+ sizes : []uint32 {maxTxRetrievalSize , maxTxRetrievalSize },
1058
+ },
1059
+ // Announce oversized blob transactions to see that overflows are ok
1060
+ doTxNotify {peer : "C" ,
1061
+ hashes : []common.Hash {{0x07 }, {0x08 }},
1062
+ types : []byte {types .BlobTxType , types .BlobTxType },
1063
+ sizes : []uint32 {params .MaxBlobGasPerBlock , params .MaxBlobGasPerBlock },
1064
+ },
1065
+ doWait {time : txArriveTimeout , step : true },
1066
+ isWaiting (nil ),
1067
+ isScheduledWithMeta {
1068
+ tracking : map [string ][]announce {
1069
+ "A" : {
1070
+ {common.Hash {0x01 }, typeptr (types .LegacyTxType ), sizeptr (48 * 1024 )},
1071
+ {common.Hash {0x02 }, typeptr (types .LegacyTxType ), sizeptr (48 * 1024 )},
1072
+ {common.Hash {0x03 }, typeptr (types .LegacyTxType ), sizeptr (48 * 1024 )},
1073
+ {common.Hash {0x04 }, typeptr (types .LegacyTxType ), sizeptr (48 * 1024 )},
1074
+ },
1075
+ "B" : {
1076
+ {common.Hash {0x05 }, typeptr (types .LegacyTxType ), sizeptr (maxTxRetrievalSize )},
1077
+ {common.Hash {0x06 }, typeptr (types .LegacyTxType ), sizeptr (maxTxRetrievalSize )},
1078
+ },
1079
+ "C" : {
1080
+ {common.Hash {0x07 }, typeptr (types .BlobTxType ), sizeptr (params .MaxBlobGasPerBlock )},
1081
+ {common.Hash {0x08 }, typeptr (types .BlobTxType ), sizeptr (params .MaxBlobGasPerBlock )},
1082
+ },
1083
+ },
1084
+ fetching : map [string ][]common.Hash {
1085
+ "A" : {{0x02 }, {0x03 }, {0x04 }},
1086
+ "B" : {{0x06 }},
1087
+ "C" : {{0x08 }},
1088
+ },
1089
+ },
1090
+ },
1091
+ })
1092
+ }
1093
+
1032
1094
// Tests that then number of transactions a peer is allowed to announce and/or
1033
1095
// request at the same time is hard capped.
1034
1096
func TestTransactionFetcherDoSProtection (t * testing.T ) {
@@ -1664,7 +1726,7 @@ func testTransactionFetcher(t *testing.T, tt txFetcherTest) {
1664
1726
if (meta == nil && (ann .kind != nil || ann .size != nil )) ||
1665
1727
(meta != nil && (ann .kind == nil || ann .size == nil )) ||
1666
1728
(meta != nil && (meta .kind != * ann .kind || meta .size != * ann .size )) {
1667
- t .Errorf ("step %d, peer %s, hash %x: waitslot metadata mismatch: want %v, have %v/%v" , i , peer , ann .hash , meta , ann .kind , ann .size )
1729
+ t .Errorf ("step %d, peer %s, hash %x: waitslot metadata mismatch: want %v, have %v/%v" , i , peer , ann .hash , meta , * ann .kind , * ann .size )
1668
1730
}
1669
1731
}
1670
1732
}
@@ -1733,7 +1795,7 @@ func testTransactionFetcher(t *testing.T, tt txFetcherTest) {
1733
1795
if (meta == nil && (ann .kind != nil || ann .size != nil )) ||
1734
1796
(meta != nil && (ann .kind == nil || ann .size == nil )) ||
1735
1797
(meta != nil && (meta .kind != * ann .kind || meta .size != * ann .size )) {
1736
- t .Errorf ("step %d, peer %s, hash %x: announce metadata mismatch: want %v, have %v/%v" , i , peer , ann .hash , meta , ann .kind , ann .size )
1798
+ t .Errorf ("step %d, peer %s, hash %x: announce metadata mismatch: want %v, have %v/%v" , i , peer , ann .hash , meta , * ann .kind , * ann .size )
1737
1799
}
1738
1800
}
1739
1801
}
0 commit comments