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

feat: Expose set finalized/safe block in plugin api BlockchainService #7382

Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8868adb
feat: Expose set finalized and safe block in plugin api BlockchainSer…
usmansaleem Jul 26, 2024
364f848
Merge remote-tracking branch 'upstream/main' into besu_plugin_blockch…
usmansaleem Jul 26, 2024
97f2fe4
Merge remote-tracking branch 'upstream/main' into besu_plugin_blockch…
usmansaleem Jul 29, 2024
b8c01a2
Merge remote-tracking branch 'upstream/main' into besu_plugin_blockch…
usmansaleem Jul 30, 2024
0178dcd
check for poa network before setting finalized block
usmansaleem Jul 30, 2024
c65f755
fix init call
usmansaleem Jul 30, 2024
c8f13b8
Check for PoS for finalized and safe block
usmansaleem Jul 30, 2024
df461b2
Merge remote-tracking branch 'upstream/main' into besu_plugin_blockch…
usmansaleem Jul 30, 2024
a73a7bb
revert the init method
usmansaleem Jul 30, 2024
44c0735
changelog
usmansaleem Jul 30, 2024
a91166e
Merge remote-tracking branch 'upstream/main' into besu_plugin_blockch…
usmansaleem Jul 31, 2024
3e89e43
Add BlockchainService set finalized acceptance test
usmansaleem Jul 31, 2024
a52f185
Add BlockchainService set finalized acceptance test
usmansaleem Jul 31, 2024
77e6d87
fix doc sentence
usmansaleem Jul 31, 2024
e3e4da0
AT for set finalized and set safe
usmansaleem Jul 31, 2024
04a09f5
Merge remote-tracking branch 'upstream/main' into besu_plugin_blockch…
usmansaleem Jul 31, 2024
e05ccbc
Merge remote-tracking branch 'upstream/main' into besu_plugin_blockch…
usmansaleem Jul 31, 2024
cbffa16
trigger ci
usmansaleem Jul 31, 2024
bb7ac7d
Merge branch 'main' into besu_plugin_blockchainservice_finalized_block
fab-10 Jul 31, 2024
e2af439
Merge branch 'main' into besu_plugin_blockchainservice_finalized_block
fab-10 Jul 31, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### Breaking Changes

### Additions and Improvements
- Expose set finalized/safe block in plugin api BlockchainService. These method can be used by plugins to set finalized/safe block for a PoA network (such as QBFT, IBFT and Clique).[#7382](https://github.com/hyperledger/besu/pull/7382)

### Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.plugin.Unstable;
Expand All @@ -46,7 +47,7 @@ public class BlockchainServiceImpl implements BlockchainService {
public BlockchainServiceImpl() {}

/**
* Instantiates a new Blockchain service.
* Initialize the Blockchain service.
*
* @param protocolContext the protocol context
* @param protocolSchedule the protocol schedule
Expand Down Expand Up @@ -135,6 +136,37 @@ public Optional<Hash> getFinalizedBlock() {
return blockchain.getFinalized();
}

@Override
public void setFinalizedBlock(final Hash blockHash) {
final var protocolSpec = getProtocolSpec(blockHash);

if (protocolSpec.isPoS()) {
throw new UnsupportedOperationException(
"Marking block as finalized is not supported for PoS networks");
}
blockchain.setFinalized(blockHash);
}

@Override
public void setSafeBlock(final Hash blockHash) {
final var protocolSpec = getProtocolSpec(blockHash);

if (protocolSpec.isPoS()) {
throw new UnsupportedOperationException(
"Marking block as safe is not supported for PoS networks");
}

blockchain.setSafeBlock(blockHash);
}

private ProtocolSpec getProtocolSpec(final Hash blockHash) {
return blockchain
.getBlockByHash(blockHash)
.map(Block::getHeader)
.map(protocolSchedule::getByBlockHeader)
.orElseThrow(() -> new IllegalArgumentException("Block not found: " + blockHash));
}

private static BlockContext blockContext(
final Supplier<BlockHeader> blockHeaderSupplier,
final Supplier<BlockBody> blockBodySupplier) {
Expand Down
2 changes: 1 addition & 1 deletion plugin-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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 = 'oPsVhFhdIkzHqD+jjwRX7dbgeNeKbpCmPjiBWDdMV7o='
knownHash = 'wReIag4O7uSR/8BsL8mG1cOSj6M/ue8DsTiWmk/UOUU='
}
check.dependsOn('checkAPIChanges')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,24 @@ public interface BlockchainService extends BesuService {
* @return the block hash of the finalized block
*/
Optional<Hash> getFinalizedBlock();

/**
* Set the finalized block for non-PoS networks
*
* @param blockHash Hash of the finalized block
* @throws IllegalArgumentException if the block hash is not on the chain
* @throws UnsupportedOperationException if the network is a PoS network
*/
void setFinalizedBlock(Hash blockHash)
throws IllegalArgumentException, UnsupportedOperationException;

/**
* Set the safe block for non-PoS networks
*
* @param blockHash Hash of the finalized block
* @throws IllegalArgumentException if the block hash is not on the chain
* @throws UnsupportedOperationException if the network is a PoS network
*/
void setSafeBlock(Hash blockHash) throws IllegalArgumentException, UnsupportedOperationException;
;
}
Loading