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

feat(snap): add extra checks; update snap discovery #2860

Open
wants to merge 8 commits into
base: snap-v4-final
Choose a base branch
from
68 changes: 68 additions & 0 deletions rskj-core/src/main/java/co/rsk/RskContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ public class RskContext implements NodeContext, NodeBootstrapper {
private ProofOfWorkRule proofOfWorkRule;
private ForkDetectionDataRule forkDetectionDataRule;
private BlockParentDependantValidationRule blockParentDependantValidationRule;
private BlockParentDependantValidationRule snapBlockParentDependantValidationRule;
private BlockValidationRule blockValidationRule;
private BlockValidationRule snapBlockValidationRule;
private BlockValidationRule minerServerBlockValidationRule;
private BlockValidator blockValidator;
private BlockValidator blockHeaderValidator;
Expand Down Expand Up @@ -1133,6 +1135,33 @@ public synchronized BlockValidationRule getBlockValidationRule() {
return blockValidationRule;
}

public synchronized BlockValidationRule getSnapBlockValidationRule() {
checkIfNotClosed();

if (snapBlockValidationRule == null) {
final RskSystemProperties rskSystemProperties = getRskSystemProperties();
final Constants commonConstants = rskSystemProperties.getNetworkConstants();
final BlockTimeStampValidationRule blockTimeStampValidationRule = new BlockTimeStampValidationRule(
commonConstants.getNewBlockMaxSecondsInTheFuture(),
rskSystemProperties.getActivationConfig(),
rskSystemProperties.getNetworkConstants()
);
snapBlockValidationRule = new BlockCompositeRule(
new TxsMinGasPriceRule(),
new BlockTxsMaxGasPriceRule(rskSystemProperties.getActivationConfig()),
new BlockRootValidationRule(rskSystemProperties.getActivationConfig()),
getProofOfWorkRule(),
new RemascValidationRule(),
blockTimeStampValidationRule,
new GasLimitRule(commonConstants.getMinGasLimit()),
new ExtraDataRule(commonConstants.getMaximumExtraDataSize()),
new ValidTxExecutionSublistsEdgesRule(getRskSystemProperties().getActivationConfig())
);
}

return snapBlockValidationRule;
}

public synchronized BlockParentDependantValidationRule getBlockParentDependantValidationRule() {
checkIfNotClosed();

Expand All @@ -1151,6 +1180,23 @@ public synchronized BlockParentDependantValidationRule getBlockParentDependantVa
return blockParentDependantValidationRule;
}

public synchronized BlockParentDependantValidationRule getSnapBlockParentDependantValidationRule() {
checkIfNotClosed();

if (snapBlockParentDependantValidationRule == null) {
Constants commonConstants = getRskSystemProperties().getNetworkConstants();
snapBlockParentDependantValidationRule = new BlockParentCompositeRule(
new BlockTxsFieldsValidationRule(getBlockTxSignatureCache()),
new PrevMinGasPriceRule(),
new BlockParentNumberRule(),
new BlockDifficultyRule(getDifficultyCalculator()),
new BlockParentGasLimitRule(commonConstants.getGasLimitBoundDivisor())
);
}

return snapBlockParentDependantValidationRule;
}

public synchronized org.ethereum.db.BlockStore buildBlockStore(String databaseDir) {
checkIfNotClosed();

Expand Down Expand Up @@ -2010,12 +2056,34 @@ private SyncPool getSyncPool() {

private SnapshotProcessor getSnapshotProcessor() {
if (snapshotProcessor == null) {
final RskSystemProperties rskSystemProperties = getRskSystemProperties();
final Constants commonConstants = rskSystemProperties.getNetworkConstants();
final BlockTimeStampValidationRule blockTimeStampValidationRule = new BlockTimeStampValidationRule(
commonConstants.getNewBlockMaxSecondsInTheFuture(),
rskSystemProperties.getActivationConfig(),
rskSystemProperties.getNetworkConstants()
);

snapshotProcessor = new SnapshotProcessor(
getBlockchain(),
getTrieStore(),
getPeersInformation(),
getBlockStore(),
getTransactionPool(),
getSnapBlockParentDependantValidationRule(),
getSnapBlockValidationRule(),
new BlockHeaderParentCompositeRule(
new PrevMinGasPriceRule(),
new BlockParentNumberRule(),
blockTimeStampValidationRule,
new BlockDifficultyRule(getDifficultyCalculator()),
new BlockParentGasLimitRule(commonConstants.getGasLimitBoundDivisor())
),
new BlockHeaderCompositeRule(
getProofOfWorkRule(),
blockTimeStampValidationRule,
new ValidGasUsedRule()
),
getRskSystemProperties().getSnapshotChunkSize(),
getRskSystemProperties().isSnapshotParallelEnabled()
);
Expand Down
15 changes: 0 additions & 15 deletions rskj-core/src/main/java/co/rsk/config/RskSystemProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,17 +430,6 @@ public int getLongSyncLimit() {
public boolean isServerSnapshotSyncEnabled() { return configFromFiles.getBoolean("sync.snapshot.server.enabled");}
public boolean isClientSnapshotSyncEnabled() { return configFromFiles.getBoolean(PROPERTY_SNAP_CLIENT_ENABLED);}

@Override
public List<String> peerCapabilities() {
List<String> capabilities = super.peerCapabilities();

if (isSnapshotSyncEnabled()) {
capabilities.add(Capability.SNAP);
}

return capabilities;
}

public int getSnapshotChunkTimeout() {
return configFromFiles.getInt("sync.snapshot.client.chunkRequestTimeout");
}
Expand Down Expand Up @@ -570,10 +559,6 @@ public GasPriceCalculator.GasCalculatorType getGasCalculatorType() {
return gasCalculatorType;
}

public boolean isSnapshotSyncEnabled(){
return isServerSnapshotSyncEnabled() || isClientSnapshotSyncEnabled();
}

private void fetchMethodTimeout(Config configElement, Map<String, Long> methodTimeoutMap) {
configElement.getObject("methods.timeout")
.unwrapped()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public class BlockValidatorImpl implements BlockValidator {

private static final Logger logger = LoggerFactory.getLogger("blocksyncservice");

private BlockStore blockStore;
private final BlockStore blockStore;

private BlockParentDependantValidationRule blockParentValidator;
private final BlockParentDependantValidationRule blockParentValidator;

private BlockValidationRule blockValidator;
private final BlockValidationRule blockValidator;

public BlockValidatorImpl(BlockStore blockStore, BlockParentDependantValidationRule blockParentValidator, BlockValidationRule blockValidator) {
this.blockStore = blockStore;
Expand Down
Loading