mirror of https://github.com/hyperledger/besu
parent
4e63f3c210
commit
6543551778
@ -0,0 +1,42 @@ |
|||||||
|
/* |
||||||
|
* Copyright ConsenSys AG. |
||||||
|
* |
||||||
|
* 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.BlockHeader; |
||||||
|
import org.hyperledger.besu.ethereum.core.Hash; |
||||||
|
|
||||||
|
public class BonsaiInMemoryWorldState extends BonsaiPersistedWorldState { |
||||||
|
|
||||||
|
public BonsaiInMemoryWorldState( |
||||||
|
final BonsaiWorldStateArchive archive, |
||||||
|
final BonsaiWorldStateKeyValueStorage worldStateStorage) { |
||||||
|
super(archive, worldStateStorage); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Hash rootHash() { |
||||||
|
final BonsaiWorldStateKeyValueStorage.Updater updater = worldStateStorage.updater(); |
||||||
|
final Hash calculatedRootHash = calculateRootHash(updater); |
||||||
|
updater.rollback(); |
||||||
|
return Hash.wrap(calculatedRootHash); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void persist(final BlockHeader blockHeader) { |
||||||
|
throw new UnsupportedOperationException("In Memory worldState can not be persisted."); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,70 @@ |
|||||||
|
/* |
||||||
|
* Copyright ConsenSys AG. |
||||||
|
* |
||||||
|
* 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.worldstate.WorldStateStorage; |
||||||
|
import org.hyperledger.besu.plugin.services.storage.KeyValueStorage; |
||||||
|
import org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
|
||||||
|
public class BonsaiInMemoryWorldStateKeyValueStorage extends BonsaiWorldStateKeyValueStorage |
||||||
|
implements WorldStateStorage { |
||||||
|
|
||||||
|
private static final Logger LOG = LogManager.getLogger(); |
||||||
|
|
||||||
|
public BonsaiInMemoryWorldStateKeyValueStorage( |
||||||
|
final KeyValueStorage accountStorage, |
||||||
|
final KeyValueStorage codeStorage, |
||||||
|
final KeyValueStorage storageStorage, |
||||||
|
final KeyValueStorage trieBranchStorage, |
||||||
|
final KeyValueStorage trieLogStorage) { |
||||||
|
super(accountStorage, codeStorage, storageStorage, trieBranchStorage, trieLogStorage); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public InMemoryUpdater updater() { |
||||||
|
return new InMemoryUpdater( |
||||||
|
accountStorage.startTransaction(), |
||||||
|
codeStorage.startTransaction(), |
||||||
|
storageStorage.startTransaction(), |
||||||
|
trieBranchStorage.startTransaction(), |
||||||
|
trieLogStorage.startTransaction()); |
||||||
|
} |
||||||
|
|
||||||
|
public static class InMemoryUpdater extends BonsaiWorldStateKeyValueStorage.Updater |
||||||
|
implements WorldStateStorage.Updater { |
||||||
|
|
||||||
|
public InMemoryUpdater( |
||||||
|
final KeyValueStorageTransaction accountStorageTransaction, |
||||||
|
final KeyValueStorageTransaction codeStorageTransaction, |
||||||
|
final KeyValueStorageTransaction storageStorageTransaction, |
||||||
|
final KeyValueStorageTransaction trieBranchStorageTransaction, |
||||||
|
final KeyValueStorageTransaction trieLogStorageTransaction) { |
||||||
|
super( |
||||||
|
accountStorageTransaction, |
||||||
|
codeStorageTransaction, |
||||||
|
storageStorageTransaction, |
||||||
|
trieBranchStorageTransaction, |
||||||
|
trieLogStorageTransaction); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void commit() { |
||||||
|
LOG.trace("Cannot commit using an in memory key value storage"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue