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

SimulatedBackend: Cannot use AdjustTime after Fork #25220

Closed
DragonDev1906 opened this issue Jul 1, 2022 · 1 comment · Fixed by #25225
Closed

SimulatedBackend: Cannot use AdjustTime after Fork #25220

DragonDev1906 opened this issue Jul 1, 2022 · 1 comment · Fixed by #25225
Labels

Comments

@DragonDev1906
Copy link
Contributor

DragonDev1906 commented Jul 1, 2022

System information

OS & Version: Linux
Commit hash : de1cecb (master)

Expected behaviour

When using AdjustTime directly after a Fork, the following Commit should still create a block in the side-chain, the same goes for all other AdjustTime and Commit calls afterwards.

Actual behaviour

AdjustTime uses the current head (b.blockchain.CurrentBlock()), which is the canonical head and thus not the block we just rolled back to when calling Fork. Thus the following call to Commit creates a block with parent h3 instead of with parent h1, resulting in the same bahavior as if Fork was never called.

Fix

Use b.blockchain.GetBlockByHash(b.pendingBlock.ParentHash()) instead of b.blockchain.CurrentBlock() in SimulatedBackend.AdjustTime.

Steps to reproduce the behaviour

// Create a new SimulatedBackend (should be possible without allocations)
sb := backends.NewSimulatedBackend(
		core.GenesisAlloc{},
		30_000_000,
	)
sb.Commit() // h1
h1 := sb.Blockchain().CurrentHeader().Hash()
sb.Commit() // h2
sb.Fork(context.Background(), h1)
sb.AdjustTime(1 * time.Second)
sb.Commit() // Should have h1 as parent but has h2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
@DragonDev1906 and others