Skip to content

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

Merged
usmansaleem merged 20 commits intobesu-eth:mainfrom
usmansaleem:besu_plugin_blockchainservice_finalized_block
Jul 31, 2024
Merged

feat: Expose set finalized/safe block in plugin api BlockchainService#7382
usmansaleem merged 20 commits intobesu-eth:mainfrom
usmansaleem:besu_plugin_blockchainservice_finalized_block

Conversation

@usmansaleem
Copy link
Copy Markdown
Contributor

@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

…vice

Signed-off-by: Usman Saleem <usman@usmans.info>
…ainservice_finalized_block

Signed-off-by: Usman Saleem <usman@usmans.info>
Copy link
Copy Markdown
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?

…ainservice_finalized_block

Signed-off-by: Usman Saleem <usman@usmans.info>
…ainservice_finalized_block

Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: Usman Saleem <usman@usmans.info>
@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 <usman@usmans.info>
* @param blockHash Hash of the finalized block
* @throws UnsupportedOperationException if the network is not a POA network
*/
void setFinalizedBlock(Hash blockHash);
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.


@Override
public void setFinalizedBlock(final Hash blockHash) {
if (genesisConfigOptionsSupplier != null) {
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

Signed-off-by: Usman Saleem <usman@usmans.info>
…ainservice_finalized_block

Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: Usman Saleem <usman@usmans.info>
Copy link
Copy Markdown
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
…ainservice_finalized_block

Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: Usman Saleem <usman@usmans.info>

@Test
@DisplayName("Calling updateFinalizedBlockV1 will set finalized block")
public void canUpdateFinalizedBlock() throws IOException {
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

Signed-off-by: Usman Saleem <usman@usmans.info>
…ainservice_finalized_block

Signed-off-by: Usman Saleem <usman@usmans.info>
…ainservice_finalized_block

Signed-off-by: Usman Saleem <usman@usmans.info>
@usmansaleem usmansaleem enabled auto-merge (squash) July 31, 2024 08:00
@usmansaleem usmansaleem merged commit 9d92ae8 into besu-eth:main Jul 31, 2024
gconnect pushed a commit to gconnect/besu that referenced this pull request Aug 26, 2024
…besu-eth#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 <usman@usmans.info>
Signed-off-by: gconnect <agatevureglory@gmail.com>
@usmansaleem usmansaleem deleted the besu_plugin_blockchainservice_finalized_block branch January 9, 2025 00:15
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