Fix while exit condition (#2953) (#2967)

Signed-off-by: Diego López León <dieguitoll@gmail.com>
Co-authored-by: garyschulte <garyschulte@gmail.com>
pull/2979/head
Diego López León 3 years ago committed by GitHub
parent ffc8da3971
commit efee280f83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 40
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateArchiveTest.java

@ -14,6 +14,7 @@
### Bug Fixes
- Do not change the sender balance, but set gas fee to zero, when simulating a transaction without enforcing balance checks. [#2454](https://github.com/hyperledger/besu/pull/2454)
- Ensure genesis block has the default base fee if london is at block 0 [#2920](https://github.com/hyperledger/besu/pull/2920)
- Fixes the exit condition for loading a BonsaiPersistedWorldState for a sibling block of the last one persisted [#2967](https://github.com/hyperledger/besu/pull/2967)
### Early Access Features
- Enable plugins to expose custom JSON-RPC / WebSocket methods [#1317](https://github.com/hyperledger/besu/issues/1317)

@ -39,9 +39,11 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
@ -160,4 +162,42 @@ public class BonsaiWorldStateArchiveTest {
verify(layeredWorldStatesByHash).entrySet();
verifyNoMoreInteractions(layeredWorldStatesByHash);
}
@SuppressWarnings({"unchecked"})
@Test
public void testGetMutableWithStorageConsistencyToRollbackAndRollForwardTheState() {
when(keyValueStorage.startTransaction()).thenReturn(mock(KeyValueStorageTransaction.class));
final BlockHeader genesis = blockBuilder.number(0).buildHeader();
final BlockHeader blockHeaderChainA =
blockBuilder.number(1).timestamp(1).parentHash(genesis.getHash()).buildHeader();
final BlockHeader blockHeaderChainB =
blockBuilder.number(1).timestamp(2).parentHash(genesis.getHash()).buildHeader();
final Map<Bytes32, BonsaiLayeredWorldState> layeredWorldStatesByHash = mock(HashMap.class);
when(layeredWorldStatesByHash.containsKey(any(Bytes32.class))).thenReturn(true);
when(layeredWorldStatesByHash.get(eq(blockHeaderChainA.getHash())))
.thenReturn(mock(BonsaiLayeredWorldState.class, Answers.RETURNS_MOCKS));
when(layeredWorldStatesByHash.get(eq(blockHeaderChainB.getHash())))
.thenReturn(mock(BonsaiLayeredWorldState.class, Answers.RETURNS_MOCKS));
bonsaiWorldStateArchive =
new BonsaiWorldStateArchive(storageProvider, blockchain, 12, layeredWorldStatesByHash);
// initial persisted state hash key
when(blockchain.getBlockHeader(eq(Hash.ZERO))).thenReturn(Optional.of(blockHeaderChainA));
when(blockchain.getBlockHeader(eq(blockHeaderChainB.getHash())))
.thenReturn(Optional.of(blockHeaderChainB));
when(blockchain.getBlockHeader(eq(genesis.getHash()))).thenReturn(Optional.of(genesis));
assertThat(bonsaiWorldStateArchive.getMutable(null, blockHeaderChainB.getHash()))
.containsInstanceOf(BonsaiPersistedWorldState.class);
// verify is trying to get the trie log layers to rollback and roll forward
verify(layeredWorldStatesByHash).containsKey(eq(blockHeaderChainA.getHash()));
verify(layeredWorldStatesByHash).get(eq(blockHeaderChainA.getHash()));
verify(layeredWorldStatesByHash).containsKey(eq(blockHeaderChainB.getHash()));
verify(layeredWorldStatesByHash).get(eq(blockHeaderChainB.getHash()));
verify(layeredWorldStatesByHash).entrySet();
verifyNoMoreInteractions(layeredWorldStatesByHash);
}
}

Loading…
Cancel
Save