Skip to content

NetUpgrade: 1 enum for NetUpgrade - #70

Merged
TheQuantumPhysicist merged 11 commits into
masterfrom
feat/chain/netupgrade
Jan 28, 2022
Merged

NetUpgrade: 1 enum for NetUpgrade#70
TheQuantumPhysicist merged 11 commits into
masterfrom
feat/chain/netupgrade

Conversation

@b-yap

@b-yap b-yap commented Jan 19, 2022

Copy link
Copy Markdown
Contributor

This is continuation of #65

implement TryFrom for POWConfig, to generate this config from the upgrade version and the chain_type.
simplify netupgrade. Moved to its own package in the chain package.

b-yap added 2 commits January 19, 2022 16:55
This is continuation of #65

implement `TryFrom` for POWConfig, to generate this config from the upgrade version and the chain_type.
simplify netupgrade. Moved to its own package in the chain package.
@b-yap b-yap changed the title NetUpgrade: 1 enum to rule them all NetUpgrade: 1 enum for NetUpgrade Jan 19, 2022
Comment thread common/src/chain/config.rs Outdated
Comment thread common/src/chain/upgrades/netupgrade.rs
Comment thread common/src/chain/upgrades/netupgrade.rs Outdated
Comment thread common/src/chain/upgrades/netupgrade.rs
Comment thread common/src/chain/upgrades/pow.rs Outdated
Comment thread common/src/primitives/height.rs Outdated
Comment thread common/src/chain/upgrades/netupgrade.rs
Comment thread common/src/chain/upgrades/netupgrade.rs Outdated
Comment thread common/src/chain/upgrades/netupgrade.rs Outdated
}

#[derive(Debug, Clone)]
pub struct NetUpgrade(Vec<(BlockHeight, UpgradeVersion)>);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be called NetUpgrades?


#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
#[repr(u8)]
pub enum UpgradeVersion {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the interest of making this testable and useful at the same time, this has to be passed to NetUpgrades as a generic. You then create an enum for testing, which is private for this crate, and the ChainConfig then uses one that's for real mainnet, testnet, etc.

Comment thread common/src/chain/upgrades/netupgrade.rs Outdated
b-yap added 2 commits January 24, 2022 16:55
fix uppercase names
no more skipping numbers
NetUpgrades is of generic <T>
updated the `is_activated` function, to only those needed for checking.
binary search for "is_activated" checking
Comment thread common/src/chain/upgrades/netupgrade.rs Outdated
Comment thread common/src/chain/upgrades/netupgrade.rs Outdated
Comment thread common/src/chain/upgrades/pow.rs Outdated
@b-yap
b-yap force-pushed the feat/chain/netupgrade branch from c1d015b to 382cb72 Compare January 26, 2022 07:43
Comment thread common/src/primitives/height.rs Outdated
self.0
}

pub fn checked_mul(&self, rhs: u64) -> Option<Self> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Quite frankly I don't want to have all these operations with block height... do we need them all? I liked the one from Anton with just +1, because that's all we may need.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is it called checked_ml when it does this self.0.checked_add(rhs).map(BlockHeight::new)?

And then checked_add below contains checked_mul... Is there something weird I'm missing or is this just transposed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yep. You're 100% right. Lots of typos. But I want them all dead anyway. There's no need to do arithmetic with block heights other than +1.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed

@iljakuklic iljakuklic Jan 27, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Adding amounts (other than 1) to block height is useful for time locks. Agreed multiplication does not make much sense.

At risk of over-engineering this, there could be two types

  1. BlockHeight (unsigned quantity)
  2. BlockDistance (could be signed or unsigned quantity, both have some merit and different tradeoffs)

With operations:

  • BlockHeight.next() -> BlockHeight
  • BlockHeight + BlockDistance -> BlockHeight (or Option<BlockHeight> if distance is signed)
  • BlockHeight - BlockHeight -> BlockDistance (or Option<BlockDistance> if distance is unsigned)
  • BlockHeight + BlockHeight is NOT defined
  • BlockDistance + BlockDistance -> BlockDistance
  • Both BlockHeight and BlockDistance have Eq, Ord and such
  • From<u64> for BlockHeight
  • From<u64/i64> for BlockDistance (depending on whether distance is signed or not)
  • Absolute time locks are represented as BlockHeight
  • Relative time locks are represented as BlockDistance

This is somewhat similar to the distinction between Instant and Duration in std::time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i have updated the checked_add (facepalm) and removed other functions.
@iljakuklic i added a TODO with the link of your comment here, just in case:
https://github.com/mintlayer/mintlayer-core/pull/70/files#diff-3ca7280eaab4d55cd3c25c5117f12fbbb434f06c8c013b3093cc91a5513cf7a0R10

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't mind at all to have a BlockDistance (which should be signed, btw), but all in good time.

What's the point of having BlockHeight if it's just another number where we can add, subtract, multiply and calculate its logarithm with base 1.335 and its gamma function? We want to limit the operations to exclusively what we need.

The diff I see, Carla, seems fine for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't mind at all to have a BlockDistance (which should be signed, btw), but all in good time.

My initial instinct was also to have a signed BlockDistance but then, if relative time locks were to be represented as BlockDistance, it would allow for negative time locks and that's somewhat weird.

Just to clarify, I do not propose the unsigned block time would be an absolute value of distance of two blocks. BlockHeight(20) - BlockHeight(30) would give None, not 10.

Comment thread common/src/primitives/height.rs Outdated
Comment thread common/src/chain/upgrades/netupgrade.rs Outdated
@TheQuantumPhysicist
TheQuantumPhysicist marked this pull request as ready for review January 27, 2022 12:16
@TheQuantumPhysicist

Copy link
Copy Markdown
Contributor

The PR looks fine except for the few things I mentioned. Please fix them and let's merge this tomorrow.

Comment thread common/src/chain/upgrades/netupgrade.rs Outdated
only `checked_add` function left;
updated `.sort` to `.sort_unstable`.
@TheQuantumPhysicist
TheQuantumPhysicist merged commit 3b950d7 into master Jan 28, 2022
@TheQuantumPhysicist
TheQuantumPhysicist deleted the feat/chain/netupgrade branch January 28, 2022 05:51
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.

5 participants