Skip to content

Commit e67d5f8

Browse files
authored
eth/catalyst: use setcanonical instead of sethead in simulated fork (#30465)
Fixes #30448
1 parent cfe25c7 commit e67d5f8

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

eth/catalyst/simulated_beacon.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ func (c *SimulatedBeacon) Fork(parentHash common.Hash) error {
306306
if parent == nil {
307307
return errors.New("parent not found")
308308
}
309-
return c.eth.BlockChain().SetHead(parent.NumberU64())
309+
_, err := c.eth.BlockChain().SetCanonical(parent)
310+
return err
310311
}
311312

312313
// AdjustTime creates a new block with an adjusted timestamp.

ethclient/simulated/backend_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ func TestFork(t *testing.T) {
194194
// 2. Send a transaction.
195195
// 3. Check that the TX is included in block 1.
196196
// 4. Fork by using the parent block as ancestor.
197-
// 5. Mine a block, Re-send the transaction and mine another one.
198-
// 6. Check that the TX is now included in block 2.
197+
// 5. Mine a block. We expect the out-forked tx to have trickled to the pool, and into the new block.
198+
// 6. Check that the TX is now included in (the new) block 1.
199199
func TestForkResendTx(t *testing.T) {
200200
t.Parallel()
201201
testAddr := crypto.PubkeyToAddress(testKey.PublicKey)
@@ -231,12 +231,8 @@ func TestForkResendTx(t *testing.T) {
231231

232232
// 5.
233233
sim.Commit()
234-
if err := client.SendTransaction(ctx, tx); err != nil {
235-
t.Fatalf("sending transaction: %v", err)
236-
}
237-
sim.Commit()
238234
receipt, _ = client.TransactionReceipt(ctx, tx.Hash())
239-
if h := receipt.BlockNumber.Uint64(); h != 2 {
235+
if h := receipt.BlockNumber.Uint64(); h != 1 {
240236
t.Errorf("TX included in wrong block: %d", h)
241237
}
242238
}

0 commit comments

Comments
 (0)