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

Remove noop WithdrawalsProcessor #4943

Merged
merged 2 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ static ProtocolSpecBuilder shanghaiDefinition(
TransactionType.EIP1559),
quorumCompatibilityMode,
SHANGHAI_INIT_CODE_SIZE_LIMIT))
.withdrawalsProcessor(new WithdrawalsProcessor.DefaultWithdrawalsProcessor())
.withdrawalsProcessor(new WithdrawalsProcessor())
.withdrawalsValidator(new WithdrawalsValidator.AllowedWithdrawals())
.name("Shanghai");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,14 @@

import java.util.List;

public interface WithdrawalsProcessor {
public class WithdrawalsProcessor {

void processWithdrawals(final List<Withdrawal> withdrawals, final WorldUpdater worldUpdater);

class NoOpWithdrawalsProcessor implements WithdrawalsProcessor {

@Override
public void processWithdrawals(
final List<Withdrawal> withdrawals, final WorldUpdater worldUpdater) {}
}

class DefaultWithdrawalsProcessor implements WithdrawalsProcessor {

@Override
public void processWithdrawals(
final List<Withdrawal> withdrawals, final WorldUpdater worldUpdater) {
for (final Withdrawal withdrawal : withdrawals) {
final EvmAccount account = worldUpdater.getOrCreate(withdrawal.getAddress());
account.getMutable().incrementBalance(withdrawal.getAmount());
}
worldUpdater.commit();
public void processWithdrawals(
final List<Withdrawal> withdrawals, final WorldUpdater worldUpdater) {
for (final Withdrawal withdrawal : withdrawals) {
final EvmAccount account = worldUpdater.getOrCreate(withdrawal.getAddress());
account.getMutable().incrementBalance(withdrawal.getAmount());
}
worldUpdater.commit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,15 @@

class WithdrawalsProcessorTest {

private final WithdrawalsProcessor.DefaultWithdrawalsProcessor defaultWithdrawalsProcessor =
new WithdrawalsProcessor.DefaultWithdrawalsProcessor();

@Test
void noopProcessor_shouldNotProcessWithdrawals() {
final MutableWorldState worldState =
createWorldStateWithAccounts(List.of(entry("0x1", 1), entry("0x2", 2), entry("0x3", 3)));
final MutableWorldState originalState = worldState.copy();
final WorldUpdater updater = worldState.updater();

final List<Withdrawal> withdrawals =
List.of(
new Withdrawal(
UInt64.valueOf(100),
UInt64.valueOf(1000),
Address.fromHexString("0x1"),
Wei.of(100)),
new Withdrawal(
UInt64.valueOf(200),
UInt64.valueOf(2000),
Address.fromHexString("0x2"),
Wei.of(200)));
final WithdrawalsProcessor noopWithdrawalsProcessor =
new WithdrawalsProcessor.NoOpWithdrawalsProcessor();
noopWithdrawalsProcessor.processWithdrawals(withdrawals, updater);

assertThat(worldState.get(Address.fromHexString("0x1")).getBalance()).isEqualTo(Wei.of(1));
assertThat(worldState.get(Address.fromHexString("0x2")).getBalance()).isEqualTo(Wei.of(2));
assertThat(worldState.get(Address.fromHexString("0x3")).getBalance()).isEqualTo(Wei.of(3));
assertThat(originalState).isEqualTo(worldState);
}

@Test
void defaultProcessor_shouldProcessEmptyWithdrawalsWithoutChangingWorldState() {
final MutableWorldState worldState =
createWorldStateWithAccounts(List.of(entry("0x1", 1), entry("0x2", 2), entry("0x3", 3)));
final MutableWorldState originalState = worldState.copy();
final WorldUpdater updater = worldState.updater();

defaultWithdrawalsProcessor.processWithdrawals(Collections.emptyList(), updater);
final WithdrawalsProcessor withdrawalsProcessor = new WithdrawalsProcessor();
withdrawalsProcessor.processWithdrawals(Collections.emptyList(), updater);

assertThat(worldState.get(Address.fromHexString("0x1")).getBalance()).isEqualTo(Wei.of(1));
assertThat(worldState.get(Address.fromHexString("0x2")).getBalance()).isEqualTo(Wei.of(2));
Expand All @@ -98,7 +67,8 @@ void defaultProcessor_shouldProcessWithdrawalsUpdatingExistingAccountsBalance()
UInt64.valueOf(2000),
Address.fromHexString("0x2"),
Wei.of(200)));
defaultWithdrawalsProcessor.processWithdrawals(withdrawals, updater);
final WithdrawalsProcessor withdrawalsProcessor = new WithdrawalsProcessor();
withdrawalsProcessor.processWithdrawals(withdrawals, updater);

assertThat(worldState.get(Address.fromHexString("0x1")).getBalance()).isEqualTo(Wei.of(101));
assertThat(worldState.get(Address.fromHexString("0x2")).getBalance()).isEqualTo(Wei.of(202));
Expand All @@ -122,7 +92,8 @@ void defaultProcessor_shouldProcessWithdrawalsUpdatingEmptyAccountsBalance() {
UInt64.valueOf(2000),
Address.fromHexString("0x2"),
Wei.of(200)));
defaultWithdrawalsProcessor.processWithdrawals(withdrawals, updater);
final WithdrawalsProcessor withdrawalsProcessor = new WithdrawalsProcessor();
withdrawalsProcessor.processWithdrawals(withdrawals, updater);

assertThat(worldState.get(Address.fromHexString("0x1")).getBalance()).isEqualTo(Wei.of(100));
assertThat(worldState.get(Address.fromHexString("0x2")).getBalance()).isEqualTo(Wei.of(200));
Expand Down