Skip to content

Commit

Permalink
Using Supplier to make the authorizer thread safe
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 committed Dec 11, 2024
1 parent a497985 commit fac1741
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Address> authorizer = Optional.empty();
private boolean isAuthorityComputed = false;
private final Supplier<Optional<Address>> authorizerSupplier =
Suppliers.memoize(this::computeAuthority);

/**
* An access list entry as defined in EIP-7702
Expand Down Expand Up @@ -107,12 +107,7 @@ public SECPSignature signature() {

@Override
public Optional<Address> authorizer() {
if (!isAuthorityComputed) {
authorizer = computeAuthority();
isAuthorityComputed = true;
}

return authorizer;
return authorizerSupplier.get();
}

@Override
Expand Down

0 comments on commit fac1741

Please sign in to comment.