Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth/catalyst: use setcanonical instead of sethead in simulated fork #30465

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion eth/catalyst/simulated_beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ func (c *SimulatedBeacon) Fork(parentHash common.Hash) error {
if parent == nil {
return errors.New("parent not found")
}
return c.eth.BlockChain().SetHead(parent.NumberU64())
_, err := c.eth.BlockChain().SetCanonical(parent)
return err
}

// AdjustTime creates a new block with an adjusted timestamp.
Expand Down
10 changes: 4 additions & 6 deletions ethclient/simulated/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ func TestFork(t *testing.T) {
// 2. Send a transaction.
// 3. Check that the TX is included in block 1.
// 4. Fork by using the parent block as ancestor.
// 5. Mine a block, Re-send the transaction and mine another one.
// 6. Check that the TX is now included in block 2.
// 5. Mine a block. We expect the out-forked tx to have trickled to the pool, and into the new block.
// 6. Check that the TX is now included in (the new) block 1.
func TestForkResendTx(t *testing.T) {
t.Parallel()
testAddr := crypto.PubkeyToAddress(testKey.PublicKey)
Expand Down Expand Up @@ -228,15 +228,13 @@ func TestForkResendTx(t *testing.T) {
if err := sim.Fork(parent.Hash()); err != nil {
t.Errorf("forking: %v", err)
}

// 5.
sim.Commit()
if err := client.SendTransaction(ctx, tx); err != nil {
Copy link
Contributor

@zhiqiangxu zhiqiangxu Sep 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the 2nd SendTransaction can be omitted if the tx is expected to be picked up automatically?

t.Fatalf("sending transaction: %v", err)
t.Logf("sending transaction: %v", err)
}
sim.Commit()
receipt, _ = client.TransactionReceipt(ctx, tx.Hash())
if h := receipt.BlockNumber.Uint64(); h != 2 {
if h := receipt.BlockNumber.Uint64(); h != 1 {
t.Errorf("TX included in wrong block: %d", h)
}
}
Expand Down