Skip to content

Commit

Permalink
feat(snap): add extra checks; update snap discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovchyk committed Nov 22, 2024
1 parent 230fe0e commit 31ee435
Show file tree
Hide file tree
Showing 55 changed files with 839 additions and 179 deletions.
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
10 changes: 9 additions & 1 deletion rskj-core/src/main/java/co/rsk/core/bc/BlockChainImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class BlockChainImpl implements Blockchain {
private static final Logger logger = LoggerFactory.getLogger("blockchain");
private static final PanicProcessor panicProcessor = new PanicProcessor();

private final Genesis genesis;
private final BlockStore blockStore;
private final ReceiptStore receiptStore;
private final TransactionPool transactionPool;
Expand All @@ -94,13 +95,15 @@ public class BlockChainImpl implements Blockchain {
private final BlockExecutor blockExecutor;
private boolean noValidation;

public BlockChainImpl(BlockStore blockStore,
public BlockChainImpl(Genesis genesis,
BlockStore blockStore,
ReceiptStore receiptStore,
TransactionPool transactionPool,
EthereumListener listener,
BlockValidator blockValidator,
BlockExecutor blockExecutor,
StateRootHandler stateRootHandler) {
this.genesis = genesis;
this.blockStore = blockStore;
this.receiptStore = receiptStore;
this.listener = listener;
Expand Down Expand Up @@ -421,6 +424,11 @@ public Block getBestBlock() {
return this.status.getBestBlock();
}

@Override
public Genesis getGenesisBlock() {
return this.genesis;
}

public void setNoValidation(boolean noValidation) {
this.noValidation = noValidation;
}
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

0 comments on commit 31ee435

Please sign in to comment.