Prague Devnet5 - EIP2935 - Fix edge case when the contract is deployed after the fork (#8211)

Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
This commit is contained in:
Gabriel-Trintinalia
2025-01-31 14:19:47 +08:00
committed by GitHub
parent 68665db454
commit e98412697b
2 changed files with 21 additions and 4 deletions

View File

@@ -68,9 +68,11 @@ public class PragueBlockHashProcessor extends CancunBlockHashProcessor {
super.processBlockHashes(mutableWorldState, currentBlockHeader);
WorldUpdater worldUpdater = mutableWorldState.updater();
final MutableAccount historyStorageAccount = worldUpdater.getOrCreate(historyStorageAddress);
final MutableAccount historyStorageAccount = worldUpdater.getAccount(historyStorageAddress);
if (currentBlockHeader.getNumber() > 0) {
if (historyStorageAccount != null
&& historyStorageAccount.getNonce() > 0
&& currentBlockHeader.getNumber() > 0) {
storeParentHash(historyStorageAccount, currentBlockHeader);
}
worldUpdater.commit();

View File

@@ -45,8 +45,9 @@ class BlockHashProcessorTest {
mutableWorldState = mock(MutableWorldState.class);
worldUpdater = mock(WorldUpdater.class);
account = mock(MutableAccount.class);
when(account.getNonce()).thenReturn(1L);
when(mutableWorldState.updater()).thenReturn(worldUpdater);
when(worldUpdater.getOrCreate(PragueBlockHashProcessor.HISTORY_STORAGE_ADDRESS))
when(worldUpdater.getAccount(PragueBlockHashProcessor.HISTORY_STORAGE_ADDRESS))
.thenReturn(account);
}
@@ -72,7 +73,7 @@ class BlockHashProcessorTest {
mockAncestorHeaders(currentBlockHeader, 0);
processor.processBlockHashes(mutableWorldState, currentBlockHeader);
verifyNoInteractions(account);
verify(account, times(0)).setStorageValue(any(), any());
}
@Test
@@ -89,6 +90,20 @@ class BlockHashProcessorTest {
verifyAccount(0, historicalWindow);
}
@Test
void shouldNotStoreBlockHashIfContractIsNotDeployed() {
when(worldUpdater.getAccount(PragueBlockHashProcessor.HISTORY_STORAGE_ADDRESS))
.thenReturn(null);
long currentBlock = 1;
processor = new PragueBlockHashProcessor();
BlockHeader currentBlockHeader = mockBlockHeader(currentBlock);
mockAncestorHeaders(currentBlockHeader, 0);
processor.processBlockHashes(mutableWorldState, currentBlockHeader);
verifyNoInteractions(account);
}
@Test
void shouldWriteGenesisHashAtSlot0() {
processor = new PragueBlockHashProcessor();