Skip to content

Commit

Permalink
narrows dependencies of BlockchainService (#7882)
Browse files Browse the repository at this point in the history
Signed-off-by: jflo <justin+github@florentine.us>
  • Loading branch information
jflo authored Nov 19, 2024
1 parent 37ea028 commit dc81641
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ RpcEndpointServiceImpl provideRpcEndpointService() {
@Singleton
BlockchainServiceImpl provideBlockchainService(final BesuController besuController) {
BlockchainServiceImpl retval = new BlockchainServiceImpl();
retval.init(besuController.getProtocolContext(), besuController.getProtocolSchedule());
retval.init(
besuController.getProtocolContext().getBlockchain(),
besuController.getProtocolSchedule());
return retval;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ private Runner buildRunner() {

private void startPlugins(final Runner runner) {
blockchainServiceImpl.init(
besuController.getProtocolContext(), besuController.getProtocolSchedule());
besuController.getProtocolContext().getBlockchain(), besuController.getProtocolSchedule());
transactionSimulationServiceImpl.init(
besuController.getProtocolContext().getBlockchain(),
new TransactionSimulator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
Expand All @@ -40,7 +39,6 @@
@Unstable
public class BlockchainServiceImpl implements BlockchainService {

private ProtocolContext protocolContext;
private ProtocolSchedule protocolSchedule;
private MutableBlockchain blockchain;

Expand All @@ -50,13 +48,12 @@ public BlockchainServiceImpl() {}
/**
* Initialize the Blockchain service.
*
* @param protocolContext the protocol context
* @param blockchain the blockchain
* @param protocolSchedule the protocol schedule
*/
public void init(final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule) {
this.protocolContext = protocolContext;
public void init(final MutableBlockchain blockchain, final ProtocolSchedule protocolSchedule) {
this.protocolSchedule = protocolSchedule;
this.blockchain = protocolContext.getBlockchain();
this.blockchain = blockchain;
}

/**
Expand All @@ -67,25 +64,24 @@ public void init(final ProtocolContext protocolContext, final ProtocolSchedule p
*/
@Override
public Optional<BlockContext> getBlockByNumber(final long number) {
return protocolContext
.getBlockchain()
return blockchain
.getBlockByNumber(number)
.map(block -> blockContext(block::getHeader, block::getBody));
}

@Override
public Hash getChainHeadHash() {
return protocolContext.getBlockchain().getChainHeadHash();
return blockchain.getChainHeadHash();
}

@Override
public BlockHeader getChainHeadHeader() {
return protocolContext.getBlockchain().getChainHeadHeader();
return blockchain.getChainHeadHeader();
}

@Override
public Optional<Wei> getNextBlockBaseFee() {
final var chainHeadHeader = protocolContext.getBlockchain().getChainHeadHeader();
final var chainHeadHeader = blockchain.getChainHeadHeader();
final var protocolSpec =
protocolSchedule.getForNextBlockHeader(chainHeadHeader, System.currentTimeMillis());
return Optional.of(protocolSpec.getFeeMarket())
Expand Down

0 comments on commit dc81641

Please sign in to comment.