use of org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule in project besu by hyperledger.
the class ForkIdsTest method testForkId.
@Test
public void testForkId() {
final GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromConfig(EthNetworkConfig.jsonConfig(chainName));
final GenesisConfigOptions configOptions = genesisConfigFile.getConfigOptions();
final ProtocolSchedule schedule = MainnetProtocolSchedule.fromConfig(configOptions, EvmConfiguration.DEFAULT);
final GenesisState genesisState = GenesisState.fromConfig(genesisConfigFile, schedule);
final Blockchain mockBlockchain = mock(Blockchain.class);
when(mockBlockchain.getGenesisBlock()).thenReturn(genesisState.getBlock());
final AtomicLong blockNumber = new AtomicLong();
when(mockBlockchain.getChainHeadBlockNumber()).thenAnswer(o -> blockNumber.get());
final ForkIdManager forkIdManager = new ForkIdManager(mockBlockchain, genesisConfigFile.getForks(), false);
final var actualForkIds = Streams.concat(((MutableProtocolSchedule) schedule).streamMilestoneBlocks(), Stream.of(Long.MAX_VALUE)).map(block -> {
blockNumber.set(block);
return forkIdManager.getForkIdForChainHead();
}).collect(Collectors.toList());
assertThat(actualForkIds).containsExactlyElementsOf(expectedForkIds);
}
use of org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule in project besu by hyperledger.
the class BlockMinerTest method singleSpecSchedule.
private ProtocolSchedule singleSpecSchedule(final ProtocolSpec protocolSpec) {
final MutableProtocolSchedule protocolSchedule = new MutableProtocolSchedule(Optional.of(BigInteger.valueOf(1234)));
protocolSchedule.putMilestone(0, protocolSpec);
return protocolSchedule;
}
use of org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule in project besu by hyperledger.
the class CombinedProtocolScheduleFactory method create.
public ProtocolSchedule create(final NavigableSet<ForkSpec<ProtocolSchedule>> forkSpecs, final Optional<BigInteger> chainId) {
final MutableProtocolSchedule combinedProtocolSchedule = new MutableProtocolSchedule(chainId);
for (ForkSpec<ProtocolSchedule> spec : forkSpecs) {
checkState(spec.getValue() instanceof MutableProtocolSchedule, "Consensus migration requires a MutableProtocolSchedule");
final MutableProtocolSchedule protocolSchedule = (MutableProtocolSchedule) spec.getValue();
final Optional<Long> endBlock = Optional.ofNullable(forkSpecs.higher(spec)).map(ForkSpec::getBlock);
protocolSchedule.getScheduledProtocolSpecs().stream().filter(protocolSpecMatchesConsensusBlockRange(spec.getBlock(), endBlock)).forEach(s -> combinedProtocolSchedule.putMilestone(s.getBlock(), s.getSpec()));
// our consensus mechanism's BesuControllerBuilder so any additional rules are applied
if (spec.getBlock() > 0) {
combinedProtocolSchedule.putMilestone(spec.getBlock(), protocolSchedule.getByBlockNumber(spec.getBlock()));
}
}
return combinedProtocolSchedule;
}
use of org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule in project besu by hyperledger.
the class VMReferenceTest method runTest.
@Override
protected void runTest() {
final MutableWorldState worldState = new DefaultMutableWorldState(spec.getInitialWorldState());
final EnvironmentInformation execEnv = spec.getExec();
final ProtocolSpec protocolSpec = MainnetProtocolSpecs.frontierDefinition(OptionalInt.empty(), OptionalInt.empty(), false, EvmConfiguration.DEFAULT).privacyParameters(PrivacyParameters.DEFAULT).privateTransactionValidatorBuilder(() -> new PrivateTransactionValidator(CHAIN_ID)).badBlocksManager(new BadBlockManager()).build(new MutableProtocolSchedule(CHAIN_ID));
final ReferenceTestBlockchain blockchain = new ReferenceTestBlockchain(execEnv.getBlockHeader().getNumber());
final MessageFrame frame = MessageFrame.builder().type(MessageFrame.Type.MESSAGE_CALL).messageFrameStack(new ArrayDeque<>()).worldUpdater(worldState.updater()).initialGas(spec.getExec().getGas()).contract(execEnv.getAccountAddress()).address(execEnv.getAccountAddress()).originator(execEnv.getOriginAddress()).gasPrice(execEnv.getGasPrice()).inputData(execEnv.getData()).sender(execEnv.getCallerAddress()).value(execEnv.getValue()).apparentValue(execEnv.getValue()).code(execEnv.getCode()).blockValues(execEnv.getBlockHeader()).depth(execEnv.getDepth()).completer(c -> {
}).miningBeneficiary(execEnv.getBlockHeader().getCoinbase()).blockHashLookup(new BlockHashLookup(execEnv.getBlockHeader(), blockchain)).maxStackSize(MessageFrame.DEFAULT_MAX_STACK_SIZE).build();
// This is normally set inside the containing message executing the code.
frame.setState(MessageFrame.State.CODE_EXECUTING);
protocolSpec.getEvm().runToHalt(frame, OperationTracer.NO_TRACING);
if (spec.isExceptionHaltExpected()) {
assertThat(frame.getState() == MessageFrame.State.EXCEPTIONAL_HALT).withFailMessage("VM should have exceptionally halted").isTrue();
} else {
// This is normally performed when the message processor executing the VM
// executes to completion successfully.
frame.getWorldUpdater().commit();
assertThat(frame.getState() == MessageFrame.State.EXCEPTIONAL_HALT).withFailMessage("VM should not have exceptionally halted with " + frame.getExceptionalHaltReason()).isFalse();
assertThat(frame.getOutputData()).withFailMessage("VM output differs").isEqualTo(spec.getOut());
assertThat(worldState.rootHash()).withFailMessage("Final world state differs").isEqualTo(spec.getFinalWorldState().rootHash());
final Gas actualGas = frame.getRemainingGas();
final Gas expectedGas = spec.getFinalGas();
final Gas difference = (expectedGas.compareTo(actualGas) > 0) ? expectedGas.minus(actualGas) : actualGas.minus(expectedGas);
assertThat(actualGas).withFailMessage("Final gas does not match, with difference of %s", difference).isEqualTo(expectedGas);
}
}
Aggregations