Skip to content

NetUpgrade in the ChainConfig. - #65

Closed
b-yap wants to merge 10 commits into
masterfrom
feat/chain/net_upgrades
Closed

NetUpgrade in the ChainConfig.#65
b-yap wants to merge 10 commits into
masterfrom
feat/chain/net_upgrades

Conversation

@b-yap

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

Copy link
Copy Markdown
Contributor

netupgrades, initial push.

TODO: provide the height boundaries of an upgrade.

This draft PR needs #64

altonen and others added 7 commits January 17, 2022 19:35
Fix couple of old fields and add nonce field to Ping/Pong so that
the protocol is slightly more robust when accepting a Pong from
remote peer.
Ping/Pong is used to test the aliveness of the remote peer and it
works by periodically sending a Ping message and expecting a response
to it within some predefined time period.

This commit implements this functionality as a state machine on
top of the asynchronous protocol by introducing substates to
the default listening state of the `PeerState` enum.

This allows the Ping/Pong functionality to follow a certain path
and catch errors where appropriate while still allowing the remote
peer to essentially send anything they want, as long as they reply
to the Ping message in time and with correct nonce.
Instead of matching both state and message type at the same time,
match the state first, then call an appropriate function for that
state and match the message type in that function to handle the
(state, message type) combination.

Additionally, add some comments, reword an error message and rename
a few tests functions to be more descriptive.
rename util directory to uint; move the uint file to the uint directory;
ran clippy.

for compact to uint256, `TryFrom` is implemented
…segregated the tests;

added max function on BlockHeight and implement saturating for the same type
@b-yap
b-yap requested a review from muursh January 17, 2022 11:36
@b-yap

b-yap commented Jan 17, 2022

Copy link
Copy Markdown
Contributor Author

@TheQuantumPhysicist is it correct to assume:
When generating a chainconfig, by default the NetUpgrades map must have at least 1 key-value pair:
key: BlockHeight zero
value: NetUpgrade of type genesis
?

@b-yap
b-yap changed the base branch from master to feat/block_production January 17, 2022 11:43
@b-yap
b-yap changed the base branch from feat/block_production to master January 17, 2022 11:44
@@ -27,6 +28,8 @@ pub struct ChainConfig {
#[allow(dead_code)]
height_checkpoint_data: BTreeMap<BlockHeight, HashType>,

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.

Please change HashType from Vec<u8> to H256.

Comment thread common/src/chain/net_upgrade.rs Outdated
}

//Note: it doesn't have to be 1000. Could be 1000, or 10000
min_height = min_height.saturating_sub(1000);

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.

This is very wrong... you should never use O(N) complexity like this. Worst case scenario, you use the BTreeMap and then do a lower_bound algorithm while handling corner cases.

This is an article about it on stackoverflow:
https://stackoverflow.com/questions/48575866/how-to-get-the-lower-bound-and-upper-bound-of-an-element-in-a-btreeset

This comes out of the box in C++... I don't know if it's there in rust:
https://www.cplusplus.com/reference/map/map/lower_bound/

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.

done

Comment thread common/src/chain/net_upgrade.rs Outdated

fn version_num_from_height(&self, height: BlockHeight) -> NetUpgradeVersion {
{
if height == BlockHeight::zero() {

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 doesn't version_type_from_height handle zero?!

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.

update

height.rs : fix clippy issue
config.rs : apply comments from Sam about HashType to H256; and adding block zero by default in the net_upgrades field of ChainConfig
@b-yap
b-yap changed the base branch from master to feat/block_production January 18, 2022 04:41
@b-yap
b-yap changed the base branch from feat/block_production to master January 18, 2022 04:41
@b-yap
b-yap changed the base branch from master to feat/block_production January 18, 2022 04:57
@b-yap
b-yap changed the base branch from feat/block_production to master January 18, 2022 05:19
Comment thread common/src/chain/net_upgrade.rs Outdated
}
}

pub trait NetUpgradesExt {

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 do we need this trait? Why not just impl NetUprageConfig.

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.

well in the ChainConfig, the netupgrade field looks like this: BTreeMap<BlockHeight, NetUpgradeType>
The NetUpgradeConfig is generated from the NetUpgradeType and theChainType.

The functions is_upgrade_activated and height_range version_type_from_height are for the Btreemap, not the config.

I should probably rename NetUpgradeConfig to.. ExtraConfig or something, which is still an enum.

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.

basically I've treated POW and POS as the same version (in terms of number. Like, these types are both version 1) but their configurations are different. The only time POW or POS configuration is shown, is from a "debug" of ChainConfig {:?}, or probably when saving this as a json and into a file or something.

I'll check on that tomorrow, first thing, the debug.

@altonen

altonen commented Jan 18, 2022

Copy link
Copy Markdown
Contributor

I think there was a problem with rebase because it seems you've co-authored some P2P commits and in doing so, the commit hashes have changed so git treats them as different commits. I don't now how to fix this in Github but you can create a new branch that has the latest master, cherry-pick your changes from this branch to that branch, close this PR and create a new PR for the new branch.

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 closed this Jan 19, 2022
b-yap added a commit that referenced this pull request Jan 19, 2022
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 deleted the feat/chain/net_upgrades branch January 19, 2022 08:58
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.

3 participants