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

Add tests validating 32 byte chainwork checkpoints can be processed once RSKIP454 is activated #2865

Open
wants to merge 3 commits into
base: use-serializeAndDeserializeCompactV2-in-RepositoryBtcBlockStoreWithCache
Choose a base branch
from

Conversation

nathanieliov
Copy link
Contributor

Description

Add tests validating 32 byte chainwork checkpoints can be processed once RSKIP454 is activated

How Has This Been Tested?

Unit tests

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Tests for the changes have been added (for bug fixes / features)
  • Requires Activation Code (Hard Fork)

@nathanieliov nathanieliov requested a review from a team as a code owner November 27, 2024 03:28
Copy link

github-actions bot commented Nov 27, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

BridgeSupport bridgeSupport = arrangeBridgeSupport(bridgeTestNetConstants,
activationsBeforeForks);

// Force instantiation of blockstore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing exactly what's being said. Check this:

private StoredBlock getBtcBlockchainChainHead() throws IOException, BlockStoreException {

Basically, we are testing how checkpoints are read and then store in the RepositoryBtcBlockStoreWithCache.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my concern is: why is this needed? maybe an explanatory comment to add a bit more context

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored

assertEquals(checkpoint.getHeight(), bridgeSupport.getBtcBlockchainBestChainHeight());
}

private BridgeSupport arrangeBridgeSupport(BridgeConstants bridgeTestNetConstants,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big fan of this. Can't we set the bridgeSupport in the general setup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to build the bridgeSupport using different bridgeConstants and different activations depending on the use case. This is why I don't put it there, but I'm reorganizing the tests, and let's see if you find it easier to follow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored

"12-byte-chainwork-mix-format.production.checkpoints"
}
)
void testInitialChainHeadWithBtcCheckpoints_whenCheckpointsWith12BytesChainWork_before_RSKIP454_ok(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add the arrange, act, assert sections as we've been doing? I find the tests a bit hard to follow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

- Put magical number into meaningful constant variable
- Put assertion blocks into methods with meaningful names
Copy link
Contributor

@apancorb apancorb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


@BeforeEach
void setUpOnEachTest() {
bridgeConstants = new BridgeRegTestConstants();
bridgeConstants = bridgeRegTestConstants;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is weird, can't we use bridgeRegTestConstants directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

assertEquals(checkpoint.getHeight(), bridgeSupport.getBtcBlockchainBestChainHeight());
}

private void arrangeBridgeSupport() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private void arrangeBridgeSupport() {
private void arrangeBridgeSupport(bridgeConstants, activations) {

wdyt? to avoid doing the

bridgeConstants = specificConstants
activations = specificActivations

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, i'd set the bridgeSupport in the general setup, and create it again when needed in specific tests.
In general we've been trying to avoid using these type of methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole class needs a refactor for the other methods that are not being touched. But this is out of the scope of this task.

Anyway, regarding using this approach for arrangement in a test, I think you may be referencing the name arrangeBridgeSupport, which could be different. I accept that. But this is the same approach we've been using lately. I got inspired by changes in the svp project. E.g., https://github.com/rsksmart/rskj/blob/add-federation-context/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java#L1148C18-L1148C49

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added your suggestion

Copy link
Contributor

@jeremy-then jeremy-then left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

* Time to use in CheckpointManager adjust checkpoint backwards by a week to account for possible clock drift in the block headers.
* For more detail please see {@link CheckpointManager#checkpoint(NetworkParameters, InputStream, co.rsk.bitcoinj.store.BtcBlockStore, long)}
*/
private static final long checkpointTimeAdjustmentForPossibleCLockDrift = weekInSeconds;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static final long checkpointTimeAdjustmentForPossibleCLockDrift = weekInSeconds;
private static final long checkpointTimeAdjustmentForPossibleClockDrift = weekInSeconds;

just a little typo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, this variable is just being used here.
I'd remove it and use weekInSeconds directly, and move the explanatory comment to where its being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -155,88 +174,151 @@ void setUpOnEachTest() {
LockingCapMainNetConstants.getInstance(),
signatureCache
);

track = createRepository().startTracking();
arrangeBridgeSupport(bridgeRegTestConstants, activations);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i insist, don't do this. we don't want a method for arranging the bridge support, that's why we created the bridge support builder.

Copy link
Contributor

@julia-zack julia-zack Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, let's use mainnet for general setup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainnet doesn't work for the rest of the tests. Refactoring this test class is out of the scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your proposal for avoid recreating the bridge support when we need an specific BridgeSupport on certain test cases?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recreate it inside the test. Do not create an arrangeBridgeSupport method.

Copy link
Contributor Author

@nathanieliov nathanieliov Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Got rid of arrangeBridgeSupport.

.build();
// arrange
activations = activationsBeforeForks;
bridgeRegTestConstants = bridgeRegTestConstants;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 333 to 335
activations = activationsBeforeForks;
bridgeRegTestConstants = bridgeRegTestConstants;
arrangeBridgeSupport(bridgeRegTestConstants, activations);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
activations = activationsBeforeForks;
bridgeRegTestConstants = bridgeRegTestConstants;
arrangeBridgeSupport(bridgeRegTestConstants, activations);
arrangeBridgeSupport(bridgeRegTestConstants, activationsBeforeForks);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nathanieliov nathanieliov force-pushed the add-textual-checkpoints-support branch 2 times, most recently from 69feb2c to 7db7156 Compare November 29, 2024 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants