Skip to content

Commit a8ab533

Browse files
dvushWazzymandias
andauthored
don't check position of optional txs (ethereum#100)
Co-authored-by: Wasif Iqbal <[email protected]>
1 parent fdec299 commit a8ab533

File tree

2 files changed

+124
-5
lines changed

2 files changed

+124
-5
lines changed

miner/verify_bundles.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ func checkBundlesAtomicity(
185185
var (
186186
firstTxBlockIdx int
187187
firstTxBundleIdx int
188+
firstTxFound = false
188189
)
189190
// 1. locate the first included tx of the bundle
190191
for bundleIdx, tx := range b {
@@ -204,11 +205,22 @@ func checkBundlesAtomicity(
204205
return NewErrBundleTxReverted(bundleHash, tx.hash, bundleIdx)
205206
}
206207

208+
// optional txs can be outside the bundle, so we don't use them to determine ordering of the bundle
209+
if tx.canRevert {
210+
continue
211+
}
212+
207213
firstTxBlockIdx = txInclusion.index
208214
firstTxBundleIdx = bundleIdx
215+
firstTxFound = true
209216
break
210217
}
211218

219+
// none of the txs from the bundle are included
220+
if !firstTxFound {
221+
continue
222+
}
223+
212224
currentBlockTx := firstTxBlockIdx + 1
213225
// locate other txs in the bundle
214226
for idx, tx := range b[firstTxBundleIdx+1:] {
@@ -226,16 +238,21 @@ func checkBundlesAtomicity(
226238
}
227239
}
228240

241+
if txInclusion.reverted && !tx.canRevert {
242+
return NewErrBundleTxReverted(bundleHash, tx.hash, bundleIdx)
243+
}
244+
245+
// we don't do position check for optional txs
246+
if tx.canRevert {
247+
continue
248+
}
249+
229250
// we allow gaps between txs in the bundle,
230251
// but txs must be in the right order
231252
if txInclusion.index < currentBlockTx {
232253
return NewErrBundleTxWrongPlace(bundleHash, tx.hash, bundleIdx, txInclusion.index, currentBlockTx)
233254
}
234255

235-
if txInclusion.reverted && !tx.canRevert {
236-
return NewErrBundleTxReverted(bundleHash, tx.hash, bundleIdx)
237-
}
238-
239256
currentBlockTx = txInclusion.index + 1
240257
}
241258
}

miner/verify_bundles_test.go

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ func TestVerifyBundlesAtomicity(t *testing.T) {
2626
expectedErr error
2727
}{
2828
// Success cases
29+
{
30+
name: "Simple bundle with 1 tx included",
31+
includedBundles: map[common.Hash][]bundleTxData{
32+
common.HexToHash("0xb1"): {
33+
{hash: common.HexToHash("0xb11"), canRevert: false},
34+
},
35+
},
36+
includedTxDataByHash: map[common.Hash]includedTxData{
37+
common.HexToHash("0xb11"): {hash: common.HexToHash("0xb11"), index: 0, reverted: false},
38+
},
39+
privateTxData: nil,
40+
mempoolTxHashes: nil,
41+
expectedErr: nil,
42+
},
2943
{
3044
name: "Simple bundle included",
3145
includedBundles: map[common.Hash][]bundleTxData{
@@ -120,6 +134,24 @@ func TestVerifyBundlesAtomicity(t *testing.T) {
120134
privateTxData: nil,
121135
expectedErr: nil,
122136
},
137+
{
138+
name: "Bundle marked included but none of the txs are included (all optional)",
139+
includedBundles: map[common.Hash][]bundleTxData{
140+
common.HexToHash("0xb1"): {
141+
{hash: common.HexToHash("0xb11"), canRevert: true},
142+
{hash: common.HexToHash("0xb12"), canRevert: true},
143+
{hash: common.HexToHash("0xb13"), canRevert: true},
144+
},
145+
},
146+
includedTxDataByHash: map[common.Hash]includedTxData{
147+
common.HexToHash("0xc1"): {hash: common.HexToHash("0xc1"), index: 0, reverted: false},
148+
},
149+
mempoolTxHashes: map[common.Hash]struct{}{
150+
common.HexToHash("0xc1"): {},
151+
},
152+
privateTxData: nil,
153+
expectedErr: nil,
154+
},
123155
{
124156
name: "Simple bundle included with all revertible tx, last of them is included as success",
125157
includedBundles: map[common.Hash][]bundleTxData{
@@ -185,6 +217,76 @@ func TestVerifyBundlesAtomicity(t *testing.T) {
185217
},
186218
expectedErr: nil,
187219
},
220+
{
221+
name: "Two bundles included, one have optional tx in the middle that gets included as part of other bundle",
222+
includedBundles: map[common.Hash][]bundleTxData{
223+
common.HexToHash("0xb1"): {
224+
{hash: common.HexToHash("0xb00"), canRevert: true},
225+
{hash: common.HexToHash("0xb12"), canRevert: false},
226+
},
227+
common.HexToHash("0xb2"): {
228+
{hash: common.HexToHash("0xb21"), canRevert: false},
229+
{hash: common.HexToHash("0xb00"), canRevert: true},
230+
{hash: common.HexToHash("0xb22"), canRevert: false},
231+
},
232+
},
233+
includedTxDataByHash: map[common.Hash]includedTxData{
234+
common.HexToHash("0xb00"): {hash: common.HexToHash("0xb00"), index: 0, reverted: false},
235+
common.HexToHash("0xb12"): {hash: common.HexToHash("0xb12"), index: 1, reverted: false},
236+
common.HexToHash("0xc1"): {hash: common.HexToHash("0xc1"), index: 2, reverted: true},
237+
common.HexToHash("0xb21"): {hash: common.HexToHash("0xb21"), index: 3, reverted: false},
238+
common.HexToHash("0xb22"): {hash: common.HexToHash("0xb22"), index: 4, reverted: false},
239+
},
240+
privateTxData: nil,
241+
mempoolTxHashes: map[common.Hash]struct{}{
242+
common.HexToHash("0xc1"): {},
243+
},
244+
expectedErr: nil,
245+
},
246+
{
247+
name: "Optional tx in the middle of the bundle was included after the bundle as part of mempool",
248+
includedBundles: map[common.Hash][]bundleTxData{
249+
common.HexToHash("0xb1"): {
250+
{hash: common.HexToHash("0xb11"), canRevert: false},
251+
{hash: common.HexToHash("0xb00"), canRevert: true},
252+
{hash: common.HexToHash("0xb12"), canRevert: false},
253+
},
254+
},
255+
includedTxDataByHash: map[common.Hash]includedTxData{
256+
common.HexToHash("0xb11"): {hash: common.HexToHash("0xb11"), index: 0, reverted: false},
257+
common.HexToHash("0xb12"): {hash: common.HexToHash("0xb12"), index: 1, reverted: false},
258+
common.HexToHash("0xc1"): {hash: common.HexToHash("0xc1"), index: 2, reverted: true},
259+
common.HexToHash("0xb00"): {hash: common.HexToHash("0xb00"), index: 3, reverted: false},
260+
},
261+
privateTxData: nil,
262+
mempoolTxHashes: map[common.Hash]struct{}{
263+
common.HexToHash("0xc1"): {},
264+
common.HexToHash("0xb00"): {},
265+
},
266+
expectedErr: nil,
267+
},
268+
{
269+
name: "Optional tx in the middle of the bundle was included before the bundle as part of mempool",
270+
includedBundles: map[common.Hash][]bundleTxData{
271+
common.HexToHash("0xb1"): {
272+
{hash: common.HexToHash("0xb11"), canRevert: false},
273+
{hash: common.HexToHash("0xb00"), canRevert: true},
274+
{hash: common.HexToHash("0xb12"), canRevert: false},
275+
},
276+
},
277+
includedTxDataByHash: map[common.Hash]includedTxData{
278+
common.HexToHash("0xb00"): {hash: common.HexToHash("0xb00"), index: 0, reverted: false},
279+
common.HexToHash("0xb11"): {hash: common.HexToHash("0xb11"), index: 1, reverted: false},
280+
common.HexToHash("0xb12"): {hash: common.HexToHash("0xb12"), index: 2, reverted: false},
281+
common.HexToHash("0xc1"): {hash: common.HexToHash("0xc1"), index: 3, reverted: true},
282+
},
283+
privateTxData: nil,
284+
mempoolTxHashes: map[common.Hash]struct{}{
285+
common.HexToHash("0xc1"): {},
286+
common.HexToHash("0xb00"): {},
287+
},
288+
expectedErr: nil,
289+
},
188290
{
189291
name: "Private tx from overlapping included bundle included",
190292
includedBundles: map[common.Hash][]bundleTxData{
@@ -423,7 +525,7 @@ func TestVerifyBundlesAtomicity(t *testing.T) {
423525
require.NoError(t, err)
424526
} else {
425527
require.Error(t, err)
426-
require.Equal(t, err, test.expectedErr)
528+
require.Equal(t, test.expectedErr, err)
427529
}
428530
})
429531
}

0 commit comments

Comments
 (0)