From fac1741b50d26ad5c57565d219a28b2dca5dfc6c Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 11 Dec 2024 14:07:00 +0100 Subject: [PATCH] Using Supplier to make the authorizer thread safe Signed-off-by: Fabio Di Fabio --- .../besu/ethereum/core/CodeDelegation.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/CodeDelegation.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/CodeDelegation.java index ef38a982224..ecf1da973f3 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/CodeDelegation.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/CodeDelegation.java @@ -42,8 +42,8 @@ public class CodeDelegation implements org.hyperledger.besu.datatypes.CodeDelega private final Address address; private final long nonce; private final SECPSignature signature; - private Optional
authorizer = Optional.empty(); - private boolean isAuthorityComputed = false; + private final Supplier> authorizerSupplier = + Suppliers.memoize(this::computeAuthority); /** * An access list entry as defined in EIP-7702 @@ -107,12 +107,7 @@ public SECPSignature signature() { @Override public Optional
authorizer() { - if (!isAuthorityComputed) { - authorizer = computeAuthority(); - isAuthorityComputed = true; - } - - return authorizer; + return authorizerSupplier.get(); } @Override