Skip to content

disable bal for transaction selection when not activated#9189

Merged
jframe merged 5 commits intobesu-eth:mainfrom
matkt:bal-trx-selector-issue
Sep 19, 2025
Merged

disable bal for transaction selection when not activated#9189
jframe merged 5 commits intobesu-eth:mainfrom
matkt:bal-trx-selector-issue

Conversation

@matkt
Copy link
Copy Markdown
Contributor

@matkt matkt commented Sep 18, 2025

PR description

Should disable bal for transaction selection when not activated

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:

  • spotless: ./gradlew spotlessApply
  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests
  • hive tests: Engine or other RPCs modified?

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
maybeBlockAccessListBuilder =
protocolSpec
.getBlockAccessListFactory()
.filter(BlockAccessListFactory::isEnabled)
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.

This should be BlockAccessListFactory::isForkEnabled - including BALs built blocks without the fork being active might lead to building invalid blocks.

Copy link
Copy Markdown
Contributor Author

@matkt matkt Sep 18, 2025

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

@mirgee mirgee Sep 18, 2025

Choose a reason for hiding this comment

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

Well, currently newProtocolSpec.getBlockAccessListFactory.isPresent() is equivalent to BlockAccessListFactory::isForkEnabled, because if the factory is present it means that the BAL fork is enabled. But it is true that this may not be true in general so the check should be more specific.

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.

modified the code in order to have a isForkActivated for block creation ; transaction evaluation and simulation/ To be safe for fusaka

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Copy link
Copy Markdown
Contributor

@jflo jflo left a comment

Choose a reason for hiding this comment

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

I think this might work to clear fusaka, but will likely break other stuff. I suggest revisiting the design and removing any knowledge of "why" it is active from the BlockAccessListFactory

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
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, just a question and a suggestion

Comment on lines +373 to +375
for (final var pendingAction : selectedTxPendingActions) {
pendingAction.run();
}
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.

From what I can see there is no pending action that rely on the state to be committed, so it is fine to running the pending actions before the state commits.

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.

Ok thanks

Comment on lines +521 to +524
if (txWorldStateUpdater
instanceof StackedUpdater<?, ?> stackedUpdater) {
blockAccessListBuilder.addTransactionLevelAccessList(
transactionAccessList, stackedUpdater);
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.

Why this check about the type? and if the type does not match it is fine to just ignore?

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.

For now we are not yet compatible with Journaled updater. This is a work that will have to do. For now, no particular problem because it's just experimental.

Comment on lines +166 to +168
maybeBlockAccessListBuilder =
protocolSpec
.getBlockAccessListFactory()
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.

Non blocking suggestion, to keep the clean of all the checks about the presence or not of the BAL builder, what if instead having the factory that just return a NoOp BAL builder when it is disabled?

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.

nit: Also prefer the NoopBal approach.

nit: Whether Noop or Optional, I prefer that the fork-dependent wiring happens in MainnetProtocolSpecs rather than in-line in this constructor, since that is our common convention.

e.g. similar approach to NoBlobSchedule https://github.com/hyperledger/besu/blob/3227dd647d1b52c06fd1cd624ae0ad1d5577c413/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java#L81

https://github.com/hyperledger/besu/blob/3227dd647d1b52c06fd1cd624ae0ad1d5577c413/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java#L758-L762

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.

Looking at the code a bit more I see it is indeed wired into the MainnetProtocolSpecs futureEipsDefinition, so I'm not sure why we need the extra isForkActivated filter, shouldn't the class just not exist for Osaka?

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.

No, because for testing reasons for the moment the option can be activated by flag and also by fork. The idea is to be able to test BAL on the current mainnet too

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.

@mirgee Do you remember exactly why re used this solution. I forgot the main reason. At first there was a noop but that was changed.

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.

@matkt I am not sure I understand the question - what aspect of the solution are we talking about? There never was a noop builder in the first iteration. I think that the code can be refactored to use a noop builder, but I wouldn't say it's the first priority right now.

Comment on lines -474 to -476
if (txWorldStateUpdater instanceof StackedUpdater<?, ?> stackedUpdater) {
balBuilder.addTransactionLevelAccessList(transactionAccessList, stackedUpdater);
}
Copy link
Copy Markdown
Contributor

@jframe jframe Sep 18, 2025

Choose a reason for hiding this comment

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

just a question. why was the balBuilder.addTransactionLevelAccessList call moved from here to later to the handleTransactionSelected 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.

Because that way we are sure to add only the transactions that are selected in the bal and not those that are in timeout. The reason for the bug you had.

Copy link
Copy Markdown
Contributor

@siladu siladu left a comment

Choose a reason for hiding this comment

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

Approving for expediency but couple of things to revisit, esp test coverage.

Comment on lines +166 to +168
maybeBlockAccessListBuilder =
protocolSpec
.getBlockAccessListFactory()
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.

nit: Also prefer the NoopBal approach.

nit: Whether Noop or Optional, I prefer that the fork-dependent wiring happens in MainnetProtocolSpecs rather than in-line in this constructor, since that is our common convention.

e.g. similar approach to NoBlobSchedule https://github.com/hyperledger/besu/blob/3227dd647d1b52c06fd1cd624ae0ad1d5577c413/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java#L81

https://github.com/hyperledger/besu/blob/3227dd647d1b52c06fd1cd624ae0ad1d5577c413/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java#L758-L762

Comment on lines +166 to +168
maybeBlockAccessListBuilder =
protocolSpec
.getBlockAccessListFactory()
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.

Looking at the code a bit more I see it is indeed wired into the MainnetProtocolSpecs futureEipsDefinition, so I'm not sure why we need the extra isForkActivated filter, shouldn't the class just not exist for Osaka?

}

@Test
public void blockAccessListShouldNotIncludesAccountWithoutBalSupport() {
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.

nit: This test doesn't appear to exercise the code that was causing the exception: #9186
(in BlockTransactionSelector.buildTransactionListForBlock)

Ideally, we'd ensure blockAccessListBuilder.build() never gets called.

@jframe jframe merged commit 0677923 into besu-eth:main Sep 19, 2025
56 of 65 checks passed
@matkt
Copy link
Copy Markdown
Contributor Author

matkt commented Sep 19, 2025

Approving for expediency but couple of things to revisit, esp test coverage.

There is a references test but we can't merge it yet.

AliZDev-v0 pushed a commit to AliZDev-v0/besu that referenced this pull request Sep 20, 2025
* disable bal for transaction selection when not activated

Signed-off-by: Karim Taam <karim.t2am@gmail.com>

* disable bal for block creation and simulator  when not activated

Signed-off-by: Karim Taam <karim.t2am@gmail.com>

* update bal only for selected transaction

Signed-off-by: Karim Taam <karim.t2am@gmail.com>

* move pending task during block creation before commit for BAL

Signed-off-by: Karim Taam <karim.t2am@gmail.com>

---------

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Ali <alijakparov.kz@gmail.com>
AliZDev-v0 pushed a commit to AliZDev-v0/besu that referenced this pull request Oct 5, 2025
* disable bal for transaction selection when not activated

Signed-off-by: Karim Taam <karim.t2am@gmail.com>

* disable bal for block creation and simulator  when not activated

Signed-off-by: Karim Taam <karim.t2am@gmail.com>

* update bal only for selected transaction

Signed-off-by: Karim Taam <karim.t2am@gmail.com>

* move pending task during block creation before commit for BAL

Signed-off-by: Karim Taam <karim.t2am@gmail.com>

---------

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Ali <alijakparov.kz@gmail.com>
Signed-off-by: Ali Zhagparov <alijakparov.kz@gmail.com>
jflo pushed a commit to jflo/besu that referenced this pull request Oct 13, 2025
* disable bal for transaction selection when not activated

Signed-off-by: Karim Taam <karim.t2am@gmail.com>

* disable bal for block creation and simulator  when not activated

Signed-off-by: Karim Taam <karim.t2am@gmail.com>

* update bal only for selected transaction

Signed-off-by: Karim Taam <karim.t2am@gmail.com>

* move pending task during block creation before commit for BAL

Signed-off-by: Karim Taam <karim.t2am@gmail.com>

---------

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: jflo <justin+github@florentine.us>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants