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

Bonsai snapshot worldstate #4409

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
spdx headers, test and comment cleanup
Signed-off-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
garyschulte committed Oct 13, 2022
commit 3791664497677e994ea4af23c9a3ffd1ae283d1c
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Increased level of detail in JSON-RPC parameter error log messages [#4510](https://github.com/hyperledger/besu/pull/4510)
- New unstable configuration options to set the maximum time, in milliseconds, a PoS block creation jobs is allowed to run [#4519](https://github.com/hyperledger/besu/pull/4519)
- Tune EthScheduler thread pools to avoid to recreate too many threads [#4529](https://github.com/hyperledger/besu/pull/4529)
- RocksDB snapshot based worldstate and plugin-api addition of Snapshot interfaces [#4409](https://github.com/hyperledger/besu/pull/4409)

### Bug Fixes
- Corrects emission of blockadded events when rewinding during a re-org. Fix for [#4495](https://github.com/hyperledger/besu/issues/4495)
Expand Down Expand Up @@ -88,6 +89,7 @@ https://hyperledger.jfrog.io/hyperledger/besu-binaries/besu/22.7.5/besu-22.7.5.t
### Additions and Improvements
- Allow free gas networks in the London fee market [#4061](https://github.com/hyperledger/besu/issues/4061)
- Upgrade besu-native to 0.6.0 and use Blake2bf native implementation if available by default [#4264](https://github.com/hyperledger/besu/pull/4264)
<<<<<<< HEAD
- Resets engine QoS timer with every call to the engine API instead of only when ExchangeTransitionConfiguration is called [#4411](https://github.com/hyperledger/besu/issues/4411)
- ExchangeTransitionConfiguration mismatch will only submit a debug log not a warning anymore [#4411](https://github.com/hyperledger/besu/issues/4411)
- Upgrade besu-native to 0.6.1 and include linux arm64 build of bls12-381 [#4416](https://github.com/hyperledger/besu/pull/4416)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public BonsaiWorldStateArchive getArchive() {

@Override
public MutableWorldState copy() {
// TODO: consider returning a snapshot rather than a copy here.
BonsaiInMemoryWorldStateKeyValueStorage bonsaiInMemoryWorldStateKeyValueStorage =
new BonsaiInMemoryWorldStateKeyValueStorage(
worldStateStorage.accountStorage,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
package org.hyperledger.besu.ethereum.bonsai;

import org.hyperledger.besu.ethereum.core.MutableWorldState;
Expand Down Expand Up @@ -45,9 +60,9 @@ public static BonsaiSnapshotWorldState create(

@Override
public MutableWorldState copy() {
// TODO: find out if we can stack transaction based snapshots, so perhaps we return a new
// transaction based
// worldstate. For now we just return ourself rather than a copy.
// The copy method interface doesn't make much sense in this context since
// this class is a snapshot based copy of the worldstate and *is* an
// independent/isolated version of the worldstate, so just return ourselves.
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
package org.hyperledger.besu.ethereum.bonsai;

import org.hyperledger.besu.datatypes.Hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ public Optional<MutableWorldState> getMutable(

@Override
public Optional<MutableWorldState> getMutable(final Hash rootHash, final Hash blockHash) {
return rollMutableStateToBlockHash(persistedState, blockHash);
return rollMutableStateToBlockHash(persistedState, blockHash)
.map(MutableWorldState.class::cast);
}

private <T extends BonsaiPersistedWorldState>
Optional<MutableWorldState> rollMutableStateToBlockHash(
final T mutableState, final Hash blockHash) {
private <T extends BonsaiPersistedWorldState> Optional<T> rollMutableStateToBlockHash(
final T mutableState, final Hash blockHash) {
if (blockHash.equals(mutableState.blockHash())) {
return Optional.of(mutableState);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
package org.hyperledger.besu.ethereum.core;

public interface SnapshotMutableWorldState extends MutableWorldState, AutoCloseable {}
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ public KeyValueStorage getStorageBySegmentIdentifier(final SegmentIdentifier seg
@Override
public SnappableKeyValueStorage getSnappableStorageBySegmentIdentifier(
final SegmentIdentifier segment) {
// TODO: this is an expedient cast for now, we should add some safety and/or fix the storage
// hierarchy
return (SnappableKeyValueStorage) storageInstances.computeIfAbsent(segment, storageCreator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -224,39 +223,6 @@ public void testSnapshotRollToTrieLogBlockHash() {
assertThat(isolatedRollBack.get().rootHash()).isEqualTo(block1.getHeader().getStateRoot());
}

/**
* this is an initial negative test case. we should expect this to fail with a mutable and
* non-persisting copy of the persisted state.
*/
@Test
@Ignore("this is expected to fail without getting an isolated mutable copy")
public void testCopyNonIsolation() {
var tx1 = burnTransaction(sender1, 0L, Address.ZERO);
Block oneTx = forTransactions(List.of(tx1));

MutableWorldState firstWorldState = archive.getMutable();
var res = executeBlock(firstWorldState, oneTx);

assertThat(res.isSuccessful()).isTrue();
// get a copy of this worldstate after it has persisted, then save the account val
var isolated = archive.getMutable(oneTx.getHeader().getStateRoot(), oneTx.getHash(), false);
Address beforeAddress = extractAddress.apply(accounts.get(1));
var before = isolated.get().get(beforeAddress);

// build and execute another block
var tx2 = burnTransaction(sender1, 1L, beforeAddress);

Block oneMoreTx = forTransactions(List.of(tx2));

var res2 =
executeBlock(archive.getMutable(oneTx.getHeader().getNumber(), true).get(), oneMoreTx);
assertThat(res2.isSuccessful()).isTrue();

// compare the cached account value to the current account value from the mutable worldstate
var after = isolated.get().get(beforeAddress);
assertThat(after.getBalance()).isNotEqualTo(before.getBalance());
}

@Test
public void assertCloseDisposesOfStateWithoutCommitting() {
Address testAddress = Address.fromHexString("0xdeadbeef");
Expand Down
2 changes: 1 addition & 1 deletion plugin-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files
knownHash = '04i5t63zL2UxFKrdlfGMMt099SejaywYvtkgpn9jUE0='
knownHash = 'XC8yUiSOLc+dKdIFk8l9aEsc6w3EqedptcH53kvfag4='
}
check.dependsOn('checkAPIChanges')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
package org.hyperledger.besu.plugin.services.storage;

public interface SnappableKeyValueStorage extends KeyValueStorage {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
package org.hyperledger.besu.plugin.services.storage;

public interface SnappedKeyValueStorage extends KeyValueStorage {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
package org.hyperledger.besu.plugin.services.storage.rocksdb.segmented;

import static java.util.stream.Collectors.toUnmodifiableSet;
Expand Down Expand Up @@ -51,7 +66,8 @@ public Set<byte[]> getAllKeysThat(final Predicate<byte[]> returnCondition) {

@Override
public KeyValueStorageTransaction startTransaction() throws StorageException {
// TODO: we should probably return a wrapped transaction
// The use of a transaction on a transaction based key value store is dubious
// at best. return our snapshot transaction instead.
return snapTx;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
package org.hyperledger.besu.plugin.services.storage.rocksdb.segmented;

import org.hyperledger.besu.plugin.services.exception.StorageException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.rocksdb.OptimisticTransactionDB;
import org.rocksdb.Statistics;
import org.rocksdb.TransactionDB;

@RunWith(MockitoJUnitRunner.class)
public class RocksDBMetricsTest {
Expand All @@ -49,7 +49,7 @@ public class RocksDBMetricsTest {
@Mock private LabelledMetric<OperationTimer> labelledMetricOperationTimerMock;
@Mock private LabelledMetric<Counter> labelledMetricCounterMock;
@Mock private OperationTimer operationTimerMock;
@Mock private TransactionDB db;
@Mock private OptimisticTransactionDB db;
@Mock private Statistics stats;

@Rule public final TemporaryFolder folder = new TemporaryFolder();
Expand Down