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: support drand quicknet #3873

Merged
merged 16 commits into from
Jan 22, 2024
Merged

feat: support drand quicknet #3873

merged 16 commits into from
Jan 22, 2024

Conversation

hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Jan 15, 2024

Summary of changes

Changes introduced in this pull request:

  • Implement quicket beacon verification with unit tests
  • Refactor mainnet beacon verification to support batching with unit tests and replace bls_signatues::verify_messages which is designed to verify bls messages in tipsets instead of beacons
  • Make beacon verification cache size bounded. (HashMap -> LruCache)
  • Add network upgrade logic (referencing feat: implement FIP-0063 filecoin-project/lotus#11572)
  • Add Quicknet config with unit tests
  • Some naming and comment updates
  • Refactor verify_bls_aggregate

Reference issue to close (if applicable)

Closes #3763

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@hanabi1224 hanabi1224 force-pushed the hm/drand-quicknet branch 4 times, most recently from c1d9ed6 to 9e96b1e Compare January 15, 2024 11:33
@@ -75,17 +74,10 @@ impl BeaconSchedule {
parent_epoch: ChainEpoch,
prev: &BeaconEntry,
) -> Result<Vec<BeaconEntry>, anyhow::Error> {
let (cb_epoch, curr_beacon) = self.beacon_for_epoch(epoch)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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


let chain_info = &config.chain_info;

if cfg!(debug_assertions) && config.network_type == DrandNetwork::Mainnet {
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 has been covered by unit tests

};
// Signature
let sig = Signature::from_bytes(curr.data())?;
let sig_match = bls_signatures::verify_messages(&sig, &[&digest], &[self.pub_key.key()?]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bls_signatures::verify_messages is designed for validating bls_messages in full tipsets, with 1 signature and a list of (message, public key) pairs to validate. While for drand beacon verification, there are 1 public key and a list of (message, signature) pairs to validate, so re-writing the logic to allow benefiting from parallelization.

.beacon_for_epoch(parent_epoch)
.map_err(|e| Error::Validation(e.to_string()))?;

if cb_epoch != pb_epoch {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hanabi1224 hanabi1224 marked this pull request as ready for review January 16, 2024 07:50
@hanabi1224 hanabi1224 requested a review from a team as a code owner January 16, 2024 07:50
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and aatifsyed and removed request for a team January 16, 2024 07:50
@hanabi1224 hanabi1224 changed the title [WIP] feat: support drand quicket feat: support drand quicket Jan 16, 2024
Copy link
Contributor

@aatifsyed aatifsyed left a comment

Choose a reason for hiding this comment

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

Not expert-review, just a few nits

Cargo.toml Outdated
@@ -26,6 +26,8 @@ bls-signatures = { version = "0.15", default-features = false, features = [
"multicore",
"blst-portable",
] } # prevent SIGINT on CI runners by using portable assembly
blst = { version = "0.3", features = ["portable"] }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised that we need both these libraries - it looks like we're only using blst::BLST_ERROR - can you confirm this is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, it should be ok to downcast to anyhow::Error here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

blst removed

let max_round = curr_beacon.max_beacon_round_for_epoch(network_version, epoch);
// We don't expect this to ever be the case
Copy link
Contributor

Choose a reason for hiding this comment

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

should we log or panic! on this branch?

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 comment and logic are from the lotus PR, I'm not 100% sure if it's true and I'd be careful adding panic here that might crash forest in some edge cases

        // We don't expect this to ever be the case
	if maxRound == prev.Round {
		return nil, nil
	}

Copy link
Member

Choose a reason for hiding this comment

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

let's add at least a massive error log so there's a chance it catches our attention, just in case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@LesnyRumcajs Log added, please re-approve if it looks good.

src/beacon/drand.rs Show resolved Hide resolved
src/beacon/drand.rs Show resolved Hide resolved
@@ -170,6 +170,11 @@ pub(super) static DRAND_SCHEDULE: [DrandPoint<'static>; 2] = [
height: SMOKE_HEIGHT,
config: &DRAND_MAINNET,
},
DrandPoint {
// height is TDB
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to update the right height to perform the upgrade later. It should be the Pineapple upgrade Epoch but it's not defined in forest yet.

@aatifsyed aatifsyed changed the title feat: support drand quicket feat: support drand quicknet Jan 17, 2024
hanabi1224 and others added 3 commits January 17, 2024 21:25
Co-authored-by: Aatif Syed <38045910+aatifsyed@users.noreply.github.com>
@LesnyRumcajs
Copy link
Member

@hanabi1224 shall we remove the changes included in #3887 from this PR?

@hanabi1224
Copy link
Contributor Author

@hanabi1224 shall we remove the changes included in #3887 from this PR?

@LesnyRumcajs I plan to merge this after #3887 so the changes will be gone after resolving merge conflicts, sounds good?

let entry = curr_beacon.entry(cur).await?;
cur = entry.round() - 1;
out.push(entry);
// We only ever need one entry after nv22 (FIP-0063)
Copy link
Member

Choose a reason for hiding this comment

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

the quicknet change will be at exactly the same epoch as the nv22 upgrade?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic and comments here replicate lotus, and yes, I think the planned upgrade epoch is the pineapple upgrade

Copy link
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

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

Did you manage to test it on a devnet?

src/networks/devnet/mod.rs Outdated Show resolved Hide resolved
src/networks/mainnet/mod.rs Outdated Show resolved Hide resolved
@hanabi1224
Copy link
Contributor Author

hanabi1224 commented Jan 19, 2024

Did you manage to test it on a devnet?

@LesnyRumcajs Not yet, that would require the miner changes ready on lotus side as discussed in the sync call. On our side, I believe I just need to update the lotus tag and devnet upgrade epoch accordingly and it will be covered by the devnet checks CI job

@hanabi1224
Copy link
Contributor Author

hanabi1224 commented Jan 22, 2024

@hanabi1224 shall we remove the changes included in #3887 from this PR?

@LesnyRumcajs removed.

@hanabi1224 hanabi1224 added this pull request to the merge queue Jan 22, 2024
Merged via the queue into main with commit fa4e286 Jan 22, 2024
27 checks passed
@hanabi1224 hanabi1224 deleted the hm/drand-quicknet branch January 22, 2024 09:30
cur = entry.round() - 1;
out.push(entry);
// We only ever need one entry after nv22 (FIP-0063)
if network_version > NetworkVersion::V21 {
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 if epoch is between PineappleUpgradeHeight and PineappleUpgradeHeight + 10

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.

Support drand quicknet
3 participants