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

Author a sibling block in case best block's slot is same as current slot #2827

Merged
merged 62 commits into from
Sep 26, 2022

Conversation

kishansagathiya
Copy link
Contributor

@kishansagathiya kishansagathiya commented Sep 13, 2022

Changes

Copy of #2726 with the merge fix

  • There were files ending with _test.go which were not actually tests, but just things that were getting used in test files. I had to remove _test from them in order to use that helper code to be used in other packages.
  • createTestService in babe tests had some un-necessary conditions. Removed them. It also helps me with the test that I have written.
  • Remove some extra redundant code that created TransactionState
  • Used actual block import handler instead of a fake one.

Tests

go test -tags integration github.com/ChainSafe/gossamer

Issues

Primary Reviewer

@timwu20

kishansagathiya and others added 20 commits July 18, 2022 12:11
the current slot, we should author a new block as child of best block's
parent.

This would create forks in the chain which would get resolved
eventually.
- Split out (CGO related) helper functions from `imports.go` to `lib/runtime/wasmer/helpers.go`
- Move pointer size helper functions to `lib/runtime/wasmer/helpers.go`
- Change `toWasmMemorySized` to NOT take a size argument (unneeded)
- Clarify all comments for helper functions
- Update all error wrappings
- Review variable names
  - Use `ptr` instead of `out` for 32 bit pointers
  - Use `pointerSize` instead of `span` for 64 bit pointers size
  - Name return values
  - Other minor renamings such as `res` to `result`, `enc` to `encodedResult`
- Optimizations:
  - `storageAppend`: use slice capacity allocation, `copy` and remove unneeded `append`s
  - `toKillStorageResultEnum`: use `copy` instead of `append`
  - `toWasmMemoryOptional`: remove unneeded variable copy
@codecov
Copy link

codecov bot commented Sep 13, 2022

Codecov Report

Merging #2827 (bb1a02c) into development (37fda37) will increase coverage by 0.00%.
The diff coverage is 0.00%.

Additional details and impacted files
@@             Coverage Diff              @@
##           development    #2827   +/-   ##
============================================
  Coverage        63.37%   63.38%           
============================================
  Files              217      217           
  Lines            27062    27088   +26     
============================================
+ Hits             17150    17169   +19     
- Misses            8348     8353    +5     
- Partials          1564     1566    +2     

kishansagathiya and others added 7 commits September 21, 2022 16:05
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
kishansagathiya and others added 2 commits September 21, 2022 23:20
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
@kishansagathiya
Copy link
Contributor Author

@EclesioMeloJunior

@kishansagathiya looking at substrate code I notice they have a method to report equivocations, is it related to this PR? should we implement it? https://github.com/paritytech/substrate/blob/c24431eb6a95197550b30715a4c124be1aea79de/client/consensus/babe/src/lib.rs#L1224

This is a really good find. I went through that piece of code and tried to figure out what it does. It appears to me that we should report equivocations. I have created an issue for that #2853. Take a look at it, let me know your thoughts.

Copy link
Member

@EclesioMeloJunior EclesioMeloJunior left a comment

Choose a reason for hiding this comment

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

LGTM, just a small unneeded comment

lib/babe/babe_integration_test.go Outdated Show resolved Hide resolved
if err != nil {
return fmt.Errorf("could not get header for hash %s: %w", parentHeader.ParentHash, err)
}
if newParentHeader == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Uh should we create an issue for that? Sounds kinda strange we can't find the parent header right?

lib/babe/mocks/network.go Show resolved Hide resolved
currentSlot := Slot{
start: time.Now(),
duration: b.constants.slotDuration,
number: slotNum,
}

parent, err := b.getParentForBlockAuthoring(slotNum)
if err != nil {
return fmt.Errorf("could not get parent for claiming slot %d: %w", slotNum, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

the slotNum argument should be bundled in the error context by getParentForBlockAuthoring, not here. Also shouldn't it be for block authoring instead of for claiming slot?

Suggested change
return fmt.Errorf("could not get parent for claiming slot %d: %w", slotNum, err)
return fmt.Errorf("could not get parent for block authoring: %w", err)

"github.com/stretchr/testify/require"
)

// NewTestService creates a new test core service
func NewTestService(t *testing.T, cfg *core.Config) *core.Service {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this function is used in only one place in the babe package, please remove all the nil checks below and inject a fully configured cfg to NewTestService. All these nil checks are just confusing and prone to error/hard to debug. You might be able to remove unused config fields too eventually.

authorityIndex uint32,
preRuntimeDigest *types.PreRuntimeDigest,
) error {
func (b *Service) getParentForBlockAuthoring(slotNum uint64) (*types.Header, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please add a unit test for this function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gets tested TestService_HandleSlotWithSameSlot and TestService_HandleSlotWithLaggingSlot.

Copy link
Contributor

@qdm12 qdm12 Sep 22, 2022

Choose a reason for hiding this comment

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

These are integration tests, not unit tests. We want a unit test because:

  • it should cover all code paths (unlike integ tests)
  • it should be fast
  • it's easier to spot a bug with a unit test than through an integ test

Copy link
Contributor

Choose a reason for hiding this comment

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

@qdm12 please remember this was a PR that was already approved before. The lack of existing unit tests in the babe package is known. I don't think it makes sense to add scope to this PR now by just unit testing this function, and not handleSlot as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like new code added should be unit tested, but up to you if you feel it's not necessary. I wasn't referring to unit testing handleSlot, that's indeed out of scope.

lib/babe/babe_integration_test.go Show resolved Hide resolved
Co-authored-by: Eclésio Junior <eclesiomelo.1@gmail.com>
@kishansagathiya kishansagathiya merged commit 1262e73 into development Sep 26, 2022
@kishansagathiya kishansagathiya deleted the kishan/fix/slot-number-must-increase branch September 26, 2022 15:56
@github-actions
Copy link

🎉 This PR is included in version 0.7.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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