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

Fix getting epoch number. #4279

Merged
merged 1 commit into from
Jan 10, 2023
Merged

Conversation

Frozen
Copy link
Contributor

@Frozen Frozen commented Sep 12, 2022

Issue

Test

Unit Test Coverage

Before:

<!-- copy/paste 'go test -cover' result in the directory you made change -->

After:

<!-- copy/paste 'go test -cover' result in the directory you made change -->

Test/Run Logs

Operational Checklist

  1. Does this PR introduce backward-incompatible changes to the on-disk data structure and/or the over-the-wire protocol?. (If no, skip to question 8.)

    YES|NO

  2. Describe the migration plan.. For each flag epoch, describe what changes take place at the flag epoch, the anticipated interactions between upgraded/non-upgraded nodes, and any special operational considerations for the migration.

  3. Describe how the plan was tested.

  4. How much minimum baking period after the last flag epoch should we allow on Pangaea before promotion onto mainnet?

  5. What are the planned flag epoch numbers and their ETAs on Pangaea?

  6. What are the planned flag epoch numbers and their ETAs on mainnet?

    Note that this must be enough to cover baking period on Pangaea.

  7. What should node operators know about this planned change?

  8. Does this PR introduce backward-incompatible changes NOT related to on-disk data structure and/or over-the-wire protocol? (If no, continue to question 11.)

    YES|NO

  9. Does the existing node.sh continue to work with this change?

  10. What should node operators know about this change?

  11. Does this PR introduce significant changes to the operational requirements of the node software, such as >20% increase in CPU, memory, and/or disk usage?

TODO

@sophoah
Copy link
Contributor

sophoah commented Sep 28, 2022

hey Konstantin, the code you are pushing was working fine before, it only recently it showed the weird issue we had at node start on testnet. Do you have an explanation for the issue (ie why we just have that issue now) ? I am worried shard.Schedule.CalcEpochNumber(blockNum) might be called somewhere else and the same issue may happened in another edge case scenario

@Frozen
Copy link
Contributor Author

Frozen commented Sep 28, 2022

It's difficult to say, that all calls of that method are correct, but exactly this line is really weird, because calculate epoch when we already have epoch doesn't make any sense. And this why i want to test it on testnet before.

@MaxMustermann2
Copy link
Contributor

Some more color on this PR:

Within InitConsensusWithValidators a node is supposed to determine the BLS keys with which it will sign the blocks. This is done once at startup, and again at epoch change as part of the regular syncing process (via UpdateConsensusInformation). The inaccurate epoch number calculation, fixed in this PR, does not directly impact the epoch number of the block produced. It is calculated by the below code after each block of all shards.

func (w *Worker) GetNewEpoch() *big.Int {
parent := w.chain.CurrentBlock()
epoch := new(big.Int).Set(parent.Header().Epoch())
shardState, err := parent.Header().GetShardState()
if err == nil &&
shardState.Epoch != nil &&
w.config.IsStaking(shardState.Epoch) {
// For shard state of staking epochs, the shard state will
// have an epoch and it will decide the next epoch for following blocks
epoch = new(big.Int).Set(shardState.Epoch)
} else {
if parent.IsLastBlockInEpoch() && parent.NumberU64() != 0 {
// if parent has proposed a new shard state it increases by 1, except for genesis block.
epoch = epoch.Add(epoch, common.Big1)
}
}
return epoch
}

Within our testing, this bug was discovered as a potential cause to the following issue (but it was not). A specific external validator's BLS key was retained in committee, even though it was not voting. Another key was added to that validator, which never got elected. This is because the shardState is repeated at the next epoch if there are no auction winners - which happened because it was the singular validator.

if len(completedEPoSRound.AuctionWinners) == 0 {
utils.Logger().Warn().Msg("No elected validators in the new epoch!!! Reuse old shard state.")
return stakerReader.ReadShardState(big.NewInt(0).Sub(epoch, big.NewInt(1)))
}

@ONECasey ONECasey changed the base branch from main to dev January 6, 2023 19:38
@ONECasey
Copy link
Contributor

ONECasey commented Jan 6, 2023

This will be merged to dev once state sync has been merged to main. Lets create a testing plan for devnet/testnet

@ONECasey ONECasey added the Next Release Use this label for the next release label Jan 6, 2023
@ONECasey ONECasey merged commit 4c0a28d into harmony-one:dev Jan 10, 2023
ONECasey added a commit that referenced this pull request Jan 12, 2023
* Rebase dev branch to current main branch (#4318)

* add openssl compatibility on m2 chips using darwin (#4302)

Adds support for OpenSSL on MacOS Ventura using m2 chips.

* [dumpdb] ensure each cross link is dumped (#4311)

* bump libp2p to version 0.24.0 and update its dependencies and relevant tests (#4315)

* Removed legacy syncing peer provider. (#4260)

* Removed legacy syncing peer provider.

* Fix localnet.

* Fix migrate version.

* Rebased on main.

* Fix formatting.

* Remove blockchain dependency from engine. (#4310)

* Consensus doesn't require anymore `Node` as a circular dependency.

* Rebased upon main.

* Removed engine beacon chain dependency.

* Fixed nil error.

* Fixed error.

* bump libp2p to version 0.24.0 and update its dependencies and relevant tests

* fix format, remove wrongly added configs

* add back wrongly deleted comment

* fix travis go checker

Co-authored-by: Konstantin <[email protected]>
Co-authored-by: “GheisMohammadi” <“[email protected]”>

* bump libp2p to version 0.24.0 and update its dependencies and relevant tests (#4315)

* Removed legacy syncing peer provider. (#4260)

* Removed legacy syncing peer provider.

* Fix localnet.

* Fix migrate version.

* Rebased on main.

* Fix formatting.

* Remove blockchain dependency from engine. (#4310)

* Consensus doesn't require anymore `Node` as a circular dependency.

* Rebased upon main.

* Removed engine beacon chain dependency.

* Fixed nil error.

* Fixed error.

* bump libp2p to version 0.24.0 and update its dependencies and relevant tests

* fix format, remove wrongly added configs

* add back wrongly deleted comment

* fix travis go checker

Co-authored-by: Konstantin <[email protected]>
Co-authored-by: “GheisMohammadi” <“[email protected]”>

* Fix for consensus stuck. (#4307)

* Added check for block validity.

* Starts new view change if block invalid.

* Revert "Starts new view change if block invalid."

This reverts commit e889fa5.

* staged dns sync v1.0 (#4316)

* staged dns sync v1.0

* enabled stream downloader for localnet

* fix code review issues

* remove extra lock

Co-authored-by: “GheisMohammadi” <“[email protected]”>

* add description for closing client and change randomize process to ma… (#4276)

* add description for closing client and change randomize process to make sure only online nodes are added to sync config

* fix sync test

* fix legacy limitNumPeers test

* add WaitForEachPeerToConnect to node configs to make parallel peer connection optional

Co-authored-by: “GheisMohammadi” <“[email protected]”>

* Small fixes and code cleanup for network stack.  (#4320)

* staged dns sync v1.0

* enabled stream downloader for localnet

* fix code review issues

* remove extra lock

* staged dns sync v1.0

* Fixed, code clean up and other.

* Fixed, code clean up and other.

* Fixed, code clean up and other.

* Fix config.

Co-authored-by: “GheisMohammadi” <“[email protected]”>

* Fix not disable cache in archival mode (#4322)

* Feature registry (#4324)

* Registry for services.

* Test.

* Reverted comment.

* Fix.

* Slash fix (#4284)

* Implementation of new slashing rate calculation

* Write tests for then new slashing rate calculation

* Add engine.applySlashing tests

* fix #4059

Co-authored-by: Alex Brezas <[email protected]>
Co-authored-by: Dimitris Lamprinos <[email protected]>

* Bump github.com/aws/aws-sdk-go from 1.30.1 to 1.33.0 (#4325) (#4328)

Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.30.1 to 1.33.0.
- [Release notes](https://github.com/aws/aws-sdk-go/releases)
- [Changelog](https://github.com/aws/aws-sdk-go/blob/v1.33.0/CHANGELOG.md)
- [Commits](aws/aws-sdk-go@v1.30.1...v1.33.0)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump github.com/btcsuite/btcd from 0.21.0-beta to 0.23.2 (#4327) (#4329)

Bumps [github.com/btcsuite/btcd](https://github.com/btcsuite/btcd) from 0.21.0-beta to 0.23.2.
- [Release notes](https://github.com/btcsuite/btcd/releases)
- [Changelog](https://github.com/btcsuite/btcd/blob/master/CHANGES)
- [Commits](btcsuite/btcd@v0.21.0-beta...v0.23.2)

---
updated-dependencies:
- dependency-name: github.com/btcsuite/btcd
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix epoch chain initialization issue (#4331)

* Fix getting epoch number. (#4279)

* feat: update dockerfile with some enhacement (#4250)

* feat: update dockerfile with some enhancement

* [docker] fix: update golang version

Co-authored-by: MaxMustermann2 <[email protected]>

* [build] github action update (#4336)

* [ops] update github action files

* [ops] add debug message in github action

* [ops] fix GPG action variable

* [ops] fix macos-12 build

* [ops] fix macos-12 build

* [ops] fix macos-12 build

* [ops] fix macos-12 build

* [ops] fix macos-12 build

* [ops] fix macos-12 build

* [cmd] update year version (#4334)

* chore(build): upgrade golang to 1.19 (#4335)

* chore(build): upgrade golang to 1.19

* chore(build): run `go mod tidy`

* chore(build): run `goimports -w -e ${file}`

* chore(build): revert github ci changes

* chore(build): pin golang version to 1.19.5

* chore(build): fix protoc version on gen files

* chore(build): fix protoc-gen-go to v1.26.0 (#4337)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Max <[email protected]>
Co-authored-by: Gheis <[email protected]>
Co-authored-by: Konstantin <[email protected]>
Co-authored-by: “GheisMohammadi” <“[email protected]”>
Co-authored-by: Danny Willis <[email protected]>
Co-authored-by: PeekPI <[email protected]>
Co-authored-by: Alex Brezas <[email protected]>
Co-authored-by: Dimitris Lamprinos <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Gheis Mohammadi <[email protected]>
Co-authored-by: Jason Yi <[email protected]>
Co-authored-by: Soph <[email protected]>
ONECasey added a commit that referenced this pull request Jan 17, 2023
* Rebase dev branch to current main branch (#4318)

* add openssl compatibility on m2 chips using darwin (#4302)

Adds support for OpenSSL on MacOS Ventura using m2 chips.

* [dumpdb] ensure each cross link is dumped (#4311)

* bump libp2p to version 0.24.0 and update its dependencies and relevant tests (#4315)

* Removed legacy syncing peer provider. (#4260)

* Removed legacy syncing peer provider.

* Fix localnet.

* Fix migrate version.

* Rebased on main.

* Fix formatting.

* Remove blockchain dependency from engine. (#4310)

* Consensus doesn't require anymore `Node` as a circular dependency.

* Rebased upon main.

* Removed engine beacon chain dependency.

* Fixed nil error.

* Fixed error.

* bump libp2p to version 0.24.0 and update its dependencies and relevant tests

* fix format, remove wrongly added configs

* add back wrongly deleted comment

* fix travis go checker

Co-authored-by: Konstantin <[email protected]>
Co-authored-by: “GheisMohammadi” <“[email protected]”>

* bump libp2p to version 0.24.0 and update its dependencies and relevant tests (#4315)

* Removed legacy syncing peer provider. (#4260)

* Removed legacy syncing peer provider.

* Fix localnet.

* Fix migrate version.

* Rebased on main.

* Fix formatting.

* Remove blockchain dependency from engine. (#4310)

* Consensus doesn't require anymore `Node` as a circular dependency.

* Rebased upon main.

* Removed engine beacon chain dependency.

* Fixed nil error.

* Fixed error.

* bump libp2p to version 0.24.0 and update its dependencies and relevant tests

* fix format, remove wrongly added configs

* add back wrongly deleted comment

* fix travis go checker

Co-authored-by: Konstantin <[email protected]>
Co-authored-by: “GheisMohammadi” <“[email protected]”>

* Fix for consensus stuck. (#4307)

* Added check for block validity.

* Starts new view change if block invalid.

* Revert "Starts new view change if block invalid."

This reverts commit e889fa5.

* staged dns sync v1.0 (#4316)

* staged dns sync v1.0

* enabled stream downloader for localnet

* fix code review issues

* remove extra lock

Co-authored-by: “GheisMohammadi” <“[email protected]”>

* add description for closing client and change randomize process to ma… (#4276)

* add description for closing client and change randomize process to make sure only online nodes are added to sync config

* fix sync test

* fix legacy limitNumPeers test

* add WaitForEachPeerToConnect to node configs to make parallel peer connection optional

Co-authored-by: “GheisMohammadi” <“[email protected]”>

* Small fixes and code cleanup for network stack.  (#4320)

* staged dns sync v1.0

* enabled stream downloader for localnet

* fix code review issues

* remove extra lock

* staged dns sync v1.0

* Fixed, code clean up and other.

* Fixed, code clean up and other.

* Fixed, code clean up and other.

* Fix config.

Co-authored-by: “GheisMohammadi” <“[email protected]”>

* Fix not disable cache in archival mode (#4322)

* Feature registry (#4324)

* Registry for services.

* Test.

* Reverted comment.

* Fix.

* Slash fix (#4284)

* Implementation of new slashing rate calculation

* Write tests for then new slashing rate calculation

* Add engine.applySlashing tests

* fix #4059

Co-authored-by: Alex Brezas <[email protected]>
Co-authored-by: Dimitris Lamprinos <[email protected]>

* Bump github.com/aws/aws-sdk-go from 1.30.1 to 1.33.0 (#4325) (#4328)

Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.30.1 to 1.33.0.
- [Release notes](https://github.com/aws/aws-sdk-go/releases)
- [Changelog](https://github.com/aws/aws-sdk-go/blob/v1.33.0/CHANGELOG.md)
- [Commits](aws/aws-sdk-go@v1.30.1...v1.33.0)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump github.com/btcsuite/btcd from 0.21.0-beta to 0.23.2 (#4327) (#4329)

Bumps [github.com/btcsuite/btcd](https://github.com/btcsuite/btcd) from 0.21.0-beta to 0.23.2.
- [Release notes](https://github.com/btcsuite/btcd/releases)
- [Changelog](https://github.com/btcsuite/btcd/blob/master/CHANGES)
- [Commits](btcsuite/btcd@v0.21.0-beta...v0.23.2)

---
updated-dependencies:
- dependency-name: github.com/btcsuite/btcd
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix epoch chain initialization issue (#4331)

* Fix getting epoch number. (#4279)

* feat: update dockerfile with some enhacement (#4250)

* feat: update dockerfile with some enhancement

* [docker] fix: update golang version

Co-authored-by: MaxMustermann2 <[email protected]>

* [build] github action update (#4336)

* [ops] update github action files

* [ops] add debug message in github action

* [ops] fix GPG action variable

* [ops] fix macos-12 build

* [ops] fix macos-12 build

* [ops] fix macos-12 build

* [ops] fix macos-12 build

* [ops] fix macos-12 build

* [ops] fix macos-12 build

* [cmd] update year version (#4334)

* chore(build): upgrade golang to 1.19 (#4335)

* chore(build): upgrade golang to 1.19

* chore(build): run `go mod tidy`

* chore(build): run `goimports -w -e ${file}`

* chore(build): revert github ci changes

* chore(build): pin golang version to 1.19.5

* chore(build): fix protoc version on gen files

* chore(build): fix protoc-gen-go to v1.26.0 (#4337)

* fix config migration issue (#4338)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Max <[email protected]>
Co-authored-by: Gheis <[email protected]>
Co-authored-by: Konstantin <[email protected]>
Co-authored-by: “GheisMohammadi” <“[email protected]”>
Co-authored-by: Danny Willis <[email protected]>
Co-authored-by: PeekPI <[email protected]>
Co-authored-by: Alex Brezas <[email protected]>
Co-authored-by: Dimitris Lamprinos <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Gheis Mohammadi <[email protected]>
Co-authored-by: Jason Yi <[email protected]>
Co-authored-by: Soph <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Next Release Use this label for the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants