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

Conversation

usmansaleem
Copy link
Member

@usmansaleem usmansaleem commented Jul 26, 2024

PR description

feat: Expose set finalized/safe block in plugin api BlockchainService. This method can be used by plugins to set finalized/safe block for a POA network (such as QBFT, IBFT and Clique).

Fixed Issue(s)

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests

…ainservice_finalized_block

Signed-off-by: Usman Saleem <[email protected]>
Copy link
Contributor

@fab-10 fab-10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty straightforward, just thinking if we need to support some kind of checks, and allow to set these values only if we are not running a PoS network?

@usmansaleem usmansaleem changed the title feat: Expose set finalized and safe block in plugin api BlockchainService feat: Expose set finalized block in plugin api BlockchainService Jul 30, 2024
Signed-off-by: Usman Saleem <[email protected]>
* @param blockHash Hash of the finalized block
* @throws UnsupportedOperationException if the network is not a POA network
*/
void setFinalizedBlock(Hash blockHash);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need the setSafeBlock method

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -135,6 +142,17 @@ public Optional<Hash> getFinalizedBlock() {
return blockchain.getFinalized();
}

@Override
public void setFinalizedBlock(final Hash blockHash) {
if (genesisConfigOptionsSupplier != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking the genesis isn't going to work for chains that transition to POS.

You could use the protocolSchedule to check the chain is POS for given blockHash by doing something like
protocolSchedule.getByBlockHeader(blockchain.getBlockHeader(blockHash).get()).isPoS()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

…ainservice_finalized_block

Signed-off-by: Usman Saleem <[email protected]>
Signed-off-by: Usman Saleem <[email protected]>
Signed-off-by: Usman Saleem <[email protected]>
Copy link
Contributor

@fab-10 fab-10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM: consider adding few tests

@usmansaleem usmansaleem changed the title feat: Expose set finalized block in plugin api BlockchainService feat: Expose set finalized/safe block in plugin api BlockchainService Jul 31, 2024

@Test
@DisplayName("Calling updateFinalizedBlockV1 will set finalized block")
public void canUpdateFinalizedBlock() throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also test the updateSafeBlock method

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

…ainservice_finalized_block

Signed-off-by: Usman Saleem <[email protected]>
@usmansaleem usmansaleem enabled auto-merge (squash) July 31, 2024 08:00
@usmansaleem usmansaleem merged commit 9d92ae8 into hyperledger:main Jul 31, 2024
40 checks passed
gconnect pushed a commit to gconnect/besu that referenced this pull request Aug 26, 2024
…hyperledger#7382)

* feat: Expose set finalized and safe block in plugin-api BlockchainService
* check for poa network before setting finalized block
* changelog
* Add BlockchainService set finalized acceptance test

---------

Signed-off-by: Usman Saleem <[email protected]>
Signed-off-by: gconnect <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants