mirror of https://github.com/hyperledger/besu
Feature/fleet mode rebase (#6641)
* fleet mode squash commit rebase Signed-off-by: garyschulte <garyschulte@gmail.com>pull/7134/head
parent
8df6bcaddd
commit
ebb883075f
@ -0,0 +1,44 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu. |
||||||
|
* |
||||||
|
* 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.services; |
||||||
|
|
||||||
|
import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork; |
||||||
|
import org.hyperledger.besu.plugin.services.p2p.P2PService; |
||||||
|
|
||||||
|
/** Service to enable and disable P2P discovery. */ |
||||||
|
public class P2PServiceImpl implements P2PService { |
||||||
|
|
||||||
|
private final P2PNetwork p2PNetwork; |
||||||
|
|
||||||
|
/** |
||||||
|
* Creates a new P2PServiceImpl. |
||||||
|
* |
||||||
|
* @param p2PNetwork the P2P network to enable and disable. |
||||||
|
*/ |
||||||
|
public P2PServiceImpl(final P2PNetwork p2PNetwork) { |
||||||
|
this.p2PNetwork = p2PNetwork; |
||||||
|
} |
||||||
|
|
||||||
|
/** Enables P2P discovery. */ |
||||||
|
@Override |
||||||
|
public void enableDiscovery() { |
||||||
|
p2PNetwork.start(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void disableDiscovery() { |
||||||
|
p2PNetwork.stop(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,82 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu. |
||||||
|
* |
||||||
|
* 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.services; |
||||||
|
|
||||||
|
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; |
||||||
|
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; |
||||||
|
import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; |
||||||
|
import org.hyperledger.besu.ethereum.rlp.RLP; |
||||||
|
import org.hyperledger.besu.plugin.data.BlockBody; |
||||||
|
import org.hyperledger.besu.plugin.data.BlockHeader; |
||||||
|
import org.hyperledger.besu.plugin.data.TransactionReceipt; |
||||||
|
import org.hyperledger.besu.plugin.services.rlp.RlpConverterService; |
||||||
|
|
||||||
|
import org.apache.tuweni.bytes.Bytes; |
||||||
|
|
||||||
|
/** RLP Serialiaztion/Deserialization service. */ |
||||||
|
public class RlpConverterServiceImpl implements RlpConverterService { |
||||||
|
|
||||||
|
private final BlockHeaderFunctions blockHeaderFunctions; |
||||||
|
|
||||||
|
/** |
||||||
|
* Constructor for RlpConverterServiceImpl. |
||||||
|
* |
||||||
|
* @param protocolSchedule the protocol schedule. |
||||||
|
*/ |
||||||
|
public RlpConverterServiceImpl(final ProtocolSchedule protocolSchedule) { |
||||||
|
this.blockHeaderFunctions = ScheduleBasedBlockHeaderFunctions.create(protocolSchedule); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public BlockHeader buildHeaderFromRlp(final Bytes rlp) { |
||||||
|
return org.hyperledger.besu.ethereum.core.BlockHeader.readFrom( |
||||||
|
RLP.input(rlp), blockHeaderFunctions); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public BlockBody buildBodyFromRlp(final Bytes rlp) { |
||||||
|
return org.hyperledger.besu.ethereum.core.BlockBody.readWrappedBodyFrom( |
||||||
|
RLP.input(rlp), blockHeaderFunctions); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public TransactionReceipt buildReceiptFromRlp(final Bytes rlp) { |
||||||
|
return org.hyperledger.besu.ethereum.core.TransactionReceipt.readFrom(RLP.input(rlp)); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Bytes buildRlpFromHeader(final BlockHeader blockHeader) { |
||||||
|
return RLP.encode( |
||||||
|
org.hyperledger.besu.ethereum.core.BlockHeader.convertPluginBlockHeader( |
||||||
|
blockHeader, blockHeaderFunctions) |
||||||
|
::writeTo); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Bytes buildRlpFromBody(final BlockBody blockBody) { |
||||||
|
return RLP.encode( |
||||||
|
rlpOutput -> |
||||||
|
((org.hyperledger.besu.ethereum.core.BlockBody) blockBody) |
||||||
|
.writeWrappedBodyTo(rlpOutput)); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Bytes buildRlpFromReceipt(final TransactionReceipt receipt) { |
||||||
|
return RLP.encode( |
||||||
|
rlpOutput -> |
||||||
|
((org.hyperledger.besu.ethereum.core.TransactionReceipt) receipt) |
||||||
|
.writeToForNetwork(rlpOutput)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,166 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu. |
||||||
|
* |
||||||
|
* 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.services; |
||||||
|
|
||||||
|
import org.hyperledger.besu.consensus.merge.MergeContext; |
||||||
|
import org.hyperledger.besu.datatypes.Hash; |
||||||
|
import org.hyperledger.besu.ethereum.ProtocolContext; |
||||||
|
import org.hyperledger.besu.ethereum.chain.MutableBlockchain; |
||||||
|
import org.hyperledger.besu.ethereum.core.Block; |
||||||
|
import org.hyperledger.besu.ethereum.core.BlockImporter; |
||||||
|
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; |
||||||
|
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; |
||||||
|
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; |
||||||
|
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; |
||||||
|
import org.hyperledger.besu.ethereum.trie.diffbased.common.DiffBasedWorldStateProvider; |
||||||
|
import org.hyperledger.besu.ethereum.trie.diffbased.common.storage.DiffBasedWorldStateKeyValueStorage; |
||||||
|
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; |
||||||
|
import org.hyperledger.besu.plugin.data.BlockBody; |
||||||
|
import org.hyperledger.besu.plugin.data.BlockHeader; |
||||||
|
import org.hyperledger.besu.plugin.services.sync.SynchronizationService; |
||||||
|
|
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
import org.apache.tuweni.bytes.Bytes; |
||||||
|
import org.apache.tuweni.bytes.Bytes32; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
/** Synchronization service. */ |
||||||
|
public class SynchronizationServiceImpl implements SynchronizationService { |
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(SynchronizationServiceImpl.class); |
||||||
|
|
||||||
|
private final ProtocolContext protocolContext; |
||||||
|
private final ProtocolSchedule protocolSchedule; |
||||||
|
|
||||||
|
private final SyncState syncState; |
||||||
|
private final Optional<DiffBasedWorldStateProvider> worldStateArchive; |
||||||
|
|
||||||
|
/** |
||||||
|
* Constructor for SynchronizationServiceImpl. |
||||||
|
* |
||||||
|
* @param protocolContext protocol context |
||||||
|
* @param protocolSchedule protocol schedule |
||||||
|
* @param syncState sync state |
||||||
|
* @param worldStateArchive world state archive |
||||||
|
*/ |
||||||
|
public SynchronizationServiceImpl( |
||||||
|
final ProtocolContext protocolContext, |
||||||
|
final ProtocolSchedule protocolSchedule, |
||||||
|
final SyncState syncState, |
||||||
|
final WorldStateArchive worldStateArchive) { |
||||||
|
this.protocolContext = protocolContext; |
||||||
|
this.protocolSchedule = protocolSchedule; |
||||||
|
this.syncState = syncState; |
||||||
|
this.worldStateArchive = |
||||||
|
Optional.ofNullable(worldStateArchive) |
||||||
|
.filter(z -> z instanceof DiffBasedWorldStateProvider) |
||||||
|
.map(DiffBasedWorldStateProvider.class::cast); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void fireNewUnverifiedForkchoiceEvent( |
||||||
|
final Hash head, final Hash safeBlock, final Hash finalizedBlock) { |
||||||
|
final MergeContext mergeContext = protocolContext.getConsensusContext(MergeContext.class); |
||||||
|
if (mergeContext != null) { |
||||||
|
mergeContext.fireNewUnverifiedForkchoiceEvent(head, safeBlock, finalizedBlock); |
||||||
|
protocolContext.getBlockchain().setFinalized(finalizedBlock); |
||||||
|
protocolContext.getBlockchain().setSafeBlock(safeBlock); |
||||||
|
} else { |
||||||
|
LOG.atWarn() |
||||||
|
.setMessage( |
||||||
|
"The merge context is unavailable, hence the fork choice event cannot be triggered") |
||||||
|
.log(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean setHead(final BlockHeader blockHeader, final BlockBody blockBody) { |
||||||
|
final BlockImporter blockImporter = |
||||||
|
protocolSchedule |
||||||
|
.getByBlockHeader((org.hyperledger.besu.ethereum.core.BlockHeader) blockHeader) |
||||||
|
.getBlockImporter(); |
||||||
|
return blockImporter |
||||||
|
.importBlock( |
||||||
|
protocolContext, |
||||||
|
new Block( |
||||||
|
(org.hyperledger.besu.ethereum.core.BlockHeader) blockHeader, |
||||||
|
(org.hyperledger.besu.ethereum.core.BlockBody) blockBody), |
||||||
|
HeaderValidationMode.SKIP_DETACHED) |
||||||
|
.isImported(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean setHeadUnsafe(final BlockHeader blockHeader, final BlockBody blockBody) { |
||||||
|
final org.hyperledger.besu.ethereum.core.BlockHeader coreHeader = |
||||||
|
(org.hyperledger.besu.ethereum.core.BlockHeader) blockHeader; |
||||||
|
|
||||||
|
final MutableBlockchain blockchain = protocolContext.getBlockchain(); |
||||||
|
|
||||||
|
if (worldStateArchive.flatMap(archive -> archive.getMutable(coreHeader, true)).isPresent()) { |
||||||
|
if (coreHeader.getParentHash().equals(blockchain.getChainHeadHash())) { |
||||||
|
LOG.atDebug() |
||||||
|
.setMessage( |
||||||
|
"Forwarding chain head to the block {} saved from a previous newPayload invocation") |
||||||
|
.addArgument(coreHeader::toLogString) |
||||||
|
.log(); |
||||||
|
return blockchain.forwardToBlock(coreHeader); |
||||||
|
} else { |
||||||
|
LOG.atDebug() |
||||||
|
.setMessage("New head {} is a chain reorg, rewind chain head to it") |
||||||
|
.addArgument(coreHeader::toLogString) |
||||||
|
.log(); |
||||||
|
return blockchain.rewindToBlock(coreHeader.getBlockHash()); |
||||||
|
} |
||||||
|
} else { |
||||||
|
LOG.atWarn() |
||||||
|
.setMessage("The world state is unavailable, setting of head cannot be performed.") |
||||||
|
.log(); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isInitialSyncPhaseDone() { |
||||||
|
return syncState.isInitialSyncPhaseDone(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void disableWorldStateTrie() { |
||||||
|
// TODO maybe find a best way in the future to delete and disable trie
|
||||||
|
worldStateArchive.ifPresent( |
||||||
|
archive -> { |
||||||
|
archive.getDefaultWorldStateConfig().setTrieDisabled(true); |
||||||
|
final DiffBasedWorldStateKeyValueStorage worldStateStorage = |
||||||
|
archive.getWorldStateKeyValueStorage(); |
||||||
|
final Optional<Hash> worldStateBlockHash = worldStateStorage.getWorldStateBlockHash(); |
||||||
|
final Optional<Bytes> worldStateRootHash = worldStateStorage.getWorldStateRootHash(); |
||||||
|
if (worldStateRootHash.isPresent() && worldStateBlockHash.isPresent()) { |
||||||
|
worldStateStorage.clearTrie(); |
||||||
|
// keep root and block hash in the trie branch
|
||||||
|
final DiffBasedWorldStateKeyValueStorage.Updater updater = worldStateStorage.updater(); |
||||||
|
updater.saveWorldState( |
||||||
|
worldStateBlockHash.get(), Bytes32.wrap(worldStateRootHash.get()), Bytes.EMPTY); |
||||||
|
updater.commit(); |
||||||
|
|
||||||
|
// currently only bonsai needs an explicit upgrade to full flat db
|
||||||
|
if (worldStateStorage instanceof BonsaiWorldStateKeyValueStorage bonsaiStorage) { |
||||||
|
bonsaiStorage.upgradeToFullFlatDbMode(); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu. |
||||||
|
* |
||||||
|
* 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.services; |
||||||
|
|
||||||
|
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; |
||||||
|
import org.hyperledger.besu.plugin.services.transactionpool.TransactionPoolService; |
||||||
|
|
||||||
|
/** Service to enable and disable the transaction pool. */ |
||||||
|
public class TransactionPoolServiceImpl implements TransactionPoolService { |
||||||
|
|
||||||
|
private final TransactionPool transactionPool; |
||||||
|
|
||||||
|
/** |
||||||
|
* Creates a new TransactionPoolServiceImpl. |
||||||
|
* |
||||||
|
* @param transactionPool the transaction pool to control |
||||||
|
*/ |
||||||
|
public TransactionPoolServiceImpl(final TransactionPool transactionPool) { |
||||||
|
this.transactionPool = transactionPool; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void disableTransactionPool() { |
||||||
|
transactionPool.setDisabled(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void enableTransactionPool() { |
||||||
|
transactionPool.setEnabled(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,54 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu. |
||||||
|
* |
||||||
|
* 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.services; |
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat; |
||||||
|
|
||||||
|
import org.hyperledger.besu.datatypes.BlobGas; |
||||||
|
import org.hyperledger.besu.datatypes.Hash; |
||||||
|
import org.hyperledger.besu.datatypes.Wei; |
||||||
|
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; |
||||||
|
import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; |
||||||
|
import org.hyperledger.besu.plugin.data.BlockHeader; |
||||||
|
|
||||||
|
import org.apache.tuweni.bytes.Bytes; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
public class RlpConverterServiceImplTest { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testBuildRlpFromHeader() { |
||||||
|
// Arrange
|
||||||
|
RlpConverterServiceImpl rlpConverterServiceImpl = |
||||||
|
new RlpConverterServiceImpl(ProtocolScheduleFixture.MAINNET); |
||||||
|
// header with cancun fields
|
||||||
|
BlockHeader header = |
||||||
|
new BlockHeaderTestFixture() |
||||||
|
.timestamp(1710338135 + 1) |
||||||
|
.baseFeePerGas(Wei.of(1000)) |
||||||
|
.requestsRoot(Hash.ZERO) |
||||||
|
.withdrawalsRoot(Hash.ZERO) |
||||||
|
.blobGasUsed(500L) |
||||||
|
.excessBlobGas(BlobGas.of(500L)) |
||||||
|
.buildHeader(); |
||||||
|
|
||||||
|
Bytes rlpBytes = rlpConverterServiceImpl.buildRlpFromHeader(header); |
||||||
|
BlockHeader deserialized = rlpConverterServiceImpl.buildHeaderFromRlp(rlpBytes); |
||||||
|
// Assert
|
||||||
|
assertThat(header).isEqualTo(deserialized); |
||||||
|
assertThat(header.getBlobGasUsed()).isEqualTo(deserialized.getBlobGasUsed()); |
||||||
|
assertThat(header.getExcessBlobGas()).isEqualTo(deserialized.getExcessBlobGas()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,79 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu. |
||||||
|
* |
||||||
|
* 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.trie.diffbased.common.worldview; |
||||||
|
|
||||||
|
public class DiffBasedWorldStateConfig { |
||||||
|
|
||||||
|
private boolean isFrozen; |
||||||
|
|
||||||
|
private boolean isTrieDisabled; |
||||||
|
|
||||||
|
public DiffBasedWorldStateConfig() { |
||||||
|
this(false, false); |
||||||
|
} |
||||||
|
|
||||||
|
public DiffBasedWorldStateConfig(final boolean isTrieDisabled) { |
||||||
|
this(false, isTrieDisabled); |
||||||
|
} |
||||||
|
|
||||||
|
public DiffBasedWorldStateConfig(final DiffBasedWorldStateConfig config) { |
||||||
|
this(config.isFrozen(), config.isTrieDisabled()); |
||||||
|
} |
||||||
|
|
||||||
|
public DiffBasedWorldStateConfig(final boolean isFrozen, final boolean isTrieDisabled) { |
||||||
|
this.isFrozen = isFrozen; |
||||||
|
this.isTrieDisabled = isTrieDisabled; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if the world state is frozen. When the world state is frozen, it cannot mutate. |
||||||
|
* |
||||||
|
* @return true if the world state is frozen, false otherwise. |
||||||
|
*/ |
||||||
|
public boolean isFrozen() { |
||||||
|
return isFrozen; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets the frozen status of the world state. When the world state is frozen, it cannot mutate. |
||||||
|
* |
||||||
|
* @param frozen the new frozen status to set. |
||||||
|
*/ |
||||||
|
public void setFrozen(final boolean frozen) { |
||||||
|
isFrozen = frozen; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if the trie is disabled for the world state. When the trie is disabled, the world state |
||||||
|
* will only work with the flat database and not the trie. In this mode, it's impossible to verify |
||||||
|
* the state root. |
||||||
|
* |
||||||
|
* @return true if the trie is disabled, false otherwise. |
||||||
|
*/ |
||||||
|
public boolean isTrieDisabled() { |
||||||
|
return isTrieDisabled; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets the disabled status of the trie for the world state. When the trie is disabled, the world |
||||||
|
* state will only work with the flat database and not the trie. In this mode, it's impossible to |
||||||
|
* verify the state root. |
||||||
|
* |
||||||
|
* @param trieDisabled the new disabled status to set for the trie. |
||||||
|
*/ |
||||||
|
public void setTrieDisabled(final boolean trieDisabled) { |
||||||
|
isTrieDisabled = trieDisabled; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,123 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu. |
||||||
|
* |
||||||
|
* 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.trie; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Optional; |
||||||
|
import java.util.concurrent.CompletableFuture; |
||||||
|
import java.util.concurrent.ExecutorService; |
||||||
|
import java.util.function.Consumer; |
||||||
|
import java.util.function.Function; |
||||||
|
|
||||||
|
import org.apache.tuweni.bytes.Bytes; |
||||||
|
import org.apache.tuweni.bytes.Bytes32; |
||||||
|
|
||||||
|
/** |
||||||
|
* A noop {@link MerkleTrie}. |
||||||
|
* |
||||||
|
* @param <V> The type of values of this trie. |
||||||
|
*/ |
||||||
|
public class NoOpMerkleTrie<K extends Bytes, V> implements MerkleTrie<K, V> { |
||||||
|
|
||||||
|
public NoOpMerkleTrie() {} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Optional<V> get(final K key) { |
||||||
|
return Optional.empty(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Optional<V> getPath(final K path) { |
||||||
|
return Optional.empty(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Proof<V> getValueWithProof(final K key) { |
||||||
|
return new Proof<>(Optional.empty(), new ArrayList<>()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void put(final K key, final V value) { |
||||||
|
// noop
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void putPath(final K path, final V value) { |
||||||
|
// noop
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void put(final K key, final PathNodeVisitor<V> putVisitor) { |
||||||
|
// noop
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void remove(final K key) { |
||||||
|
// noop
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void removePath(final K path, final PathNodeVisitor<V> removeVisitor) { |
||||||
|
// noop
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Bytes32 getRootHash() { |
||||||
|
return EMPTY_TRIE_NODE_HASH; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return getClass().getSimpleName() + "[" + getRootHash() + "]"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void commit(final NodeUpdater nodeUpdater) { |
||||||
|
// Nothing to do here
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void commit(final NodeUpdater nodeUpdater, final CommitVisitor<V> commitVisitor) { |
||||||
|
// Nothing to do here
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Map<Bytes32, V> entriesFrom(final Bytes32 startKeyHash, final int limit) { |
||||||
|
return new HashMap<>(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Map<Bytes32, V> entriesFrom(final Function<Node<V>, Map<Bytes32, V>> handler) { |
||||||
|
return new HashMap<>(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void visitAll(final Consumer<Node<V>> nodeConsumer) { |
||||||
|
// noop
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public CompletableFuture<Void> visitAll( |
||||||
|
final Consumer<Node<V>> nodeConsumer, final ExecutorService executorService) { |
||||||
|
return CompletableFuture.completedFuture(null); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void visitLeafs(final TrieIterator.LeafHandler<V> handler) { |
||||||
|
// nopop
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu. |
||||||
|
* |
||||||
|
* 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.p2p; |
||||||
|
|
||||||
|
import org.hyperledger.besu.plugin.services.BesuService; |
||||||
|
|
||||||
|
/** Service to enable and disable P2P service. */ |
||||||
|
public interface P2PService extends BesuService { |
||||||
|
|
||||||
|
/** Enables P2P discovery. */ |
||||||
|
void enableDiscovery(); |
||||||
|
|
||||||
|
/** Disables P2P discovery. */ |
||||||
|
void disableDiscovery(); |
||||||
|
} |
@ -0,0 +1,74 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu. |
||||||
|
* |
||||||
|
* 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.rlp; |
||||||
|
|
||||||
|
import org.hyperledger.besu.plugin.data.BlockBody; |
||||||
|
import org.hyperledger.besu.plugin.data.BlockHeader; |
||||||
|
import org.hyperledger.besu.plugin.data.TransactionReceipt; |
||||||
|
import org.hyperledger.besu.plugin.services.BesuService; |
||||||
|
|
||||||
|
import org.apache.tuweni.bytes.Bytes; |
||||||
|
|
||||||
|
/** RLP Serialiaztion/Deserialization service. */ |
||||||
|
public interface RlpConverterService extends BesuService { |
||||||
|
|
||||||
|
/** |
||||||
|
* Builds a block header from RLP. |
||||||
|
* |
||||||
|
* @param rlp the RLP to build the block header from. |
||||||
|
* @return the block header. |
||||||
|
*/ |
||||||
|
BlockHeader buildHeaderFromRlp(final Bytes rlp); |
||||||
|
|
||||||
|
/** |
||||||
|
* Builds a block body from RLP. |
||||||
|
* |
||||||
|
* @param rlp the RLP to build the block body from. |
||||||
|
* @return the block body. |
||||||
|
*/ |
||||||
|
BlockBody buildBodyFromRlp(final Bytes rlp); |
||||||
|
|
||||||
|
/** |
||||||
|
* Builds a transaction receipt from RLP. |
||||||
|
* |
||||||
|
* @param rlp the RLP to build the transaction receipt from. |
||||||
|
* @return the transaction receipt. |
||||||
|
*/ |
||||||
|
TransactionReceipt buildReceiptFromRlp(final Bytes rlp); |
||||||
|
|
||||||
|
/** |
||||||
|
* RLP encodes a block header. |
||||||
|
* |
||||||
|
* @param blockHeader the block header to build RLP from. |
||||||
|
* @return the RLP. |
||||||
|
*/ |
||||||
|
Bytes buildRlpFromHeader(final BlockHeader blockHeader); |
||||||
|
|
||||||
|
/** |
||||||
|
* RLP encodes a block body. |
||||||
|
* |
||||||
|
* @param blockBody the block body to build RLP from. |
||||||
|
* @return the RLP. |
||||||
|
*/ |
||||||
|
Bytes buildRlpFromBody(final BlockBody blockBody); |
||||||
|
|
||||||
|
/** |
||||||
|
* RLP encodes a transaction receipt. |
||||||
|
* |
||||||
|
* @param receipt the transaction receipt to build RLP from. |
||||||
|
* @return the RLP. |
||||||
|
*/ |
||||||
|
Bytes buildRlpFromReceipt(final TransactionReceipt receipt); |
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu. |
||||||
|
* |
||||||
|
* 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.sync; |
||||||
|
|
||||||
|
import org.hyperledger.besu.datatypes.Hash; |
||||||
|
import org.hyperledger.besu.plugin.data.BlockBody; |
||||||
|
import org.hyperledger.besu.plugin.data.BlockHeader; |
||||||
|
import org.hyperledger.besu.plugin.services.BesuService; |
||||||
|
|
||||||
|
/** Synchronization service wraps the sync state and sync event lifecycle. */ |
||||||
|
public interface SynchronizationService extends BesuService { |
||||||
|
|
||||||
|
/** |
||||||
|
* Enables P2P discovery. |
||||||
|
* |
||||||
|
* @param head the head of the chain. |
||||||
|
* @param safeBlock the safe block. |
||||||
|
* @param finalizedBlock the finalized block. |
||||||
|
*/ |
||||||
|
void fireNewUnverifiedForkchoiceEvent(Hash head, Hash safeBlock, Hash finalizedBlock); |
||||||
|
|
||||||
|
/** |
||||||
|
* Set the head of the chain. |
||||||
|
* |
||||||
|
* @param blockHeader the block header |
||||||
|
* @param blockBody the block body |
||||||
|
* @return true if the head was set, false otherwise. |
||||||
|
*/ |
||||||
|
boolean setHead(final BlockHeader blockHeader, final BlockBody blockBody); |
||||||
|
|
||||||
|
/** |
||||||
|
* Adds the block header and body to the head of the chain directly, without using a block |
||||||
|
* importer or validation. |
||||||
|
* |
||||||
|
* @param blockHeader the block header |
||||||
|
* @param blockBody the block body |
||||||
|
* @return true if the head was set, false otherwise. |
||||||
|
*/ |
||||||
|
boolean setHeadUnsafe(BlockHeader blockHeader, BlockBody blockBody); |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns whether the initial chain and worldstate sync is complete. |
||||||
|
* |
||||||
|
* @return true if the initial sync phase is done, false otherwise. |
||||||
|
*/ |
||||||
|
boolean isInitialSyncPhaseDone(); |
||||||
|
|
||||||
|
/** Disables the worldstate trie for update. */ |
||||||
|
void disableWorldStateTrie(); |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu. |
||||||
|
* |
||||||
|
* 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.sync; |
||||||
|
|
||||||
|
/** interface for worldstate configuration * */ |
||||||
|
public interface WorldStateConfiguration { |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns whether the trie is disabled. |
||||||
|
* |
||||||
|
* @return true if the trie is disabled, false otherwise. |
||||||
|
*/ |
||||||
|
boolean isTrieDisabled(); |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu. |
||||||
|
* |
||||||
|
* 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.transactionpool; |
||||||
|
|
||||||
|
import org.hyperledger.besu.plugin.services.BesuService; |
||||||
|
|
||||||
|
/** Service to enable and disable the transaction pool. */ |
||||||
|
public interface TransactionPoolService extends BesuService { |
||||||
|
/** Enables the transaction pool. */ |
||||||
|
void disableTransactionPool(); |
||||||
|
|
||||||
|
/** Disables the transaction pool. */ |
||||||
|
void enableTransactionPool(); |
||||||
|
} |
Loading…
Reference in new issue