8000 fix: rebuild binary if it has been deleted or modified by lumtis · Pull Request #712 · ignite/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: rebuild binary if it has been deleted or modified #712

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

Merged
merged 17 commits into from
Feb 2, 2021
Merged

Conversation

lumtis
Copy link
Contributor
@lumtis lumtis commented Feb 1, 2021

From the discussion: #707

Build the binary and skip the initialization phase if the binary has been deleted but the source code has not been modified.

@lumtis lumtis requested review from fadeev and ilgooz as code owners February 1, 2021 10:19
@fadeev
Copy link
Contributor
fadeev commented Feb 1, 2021

I've got an issue.

  • starport serve a scaffolded chain.
  • Introduce a bug, see the bug printed to the terminal (fine so far)
  • ctrl+c
  • starport serve, chain's binary works fine.

@lumtis
Copy link
Contributor Author
lumtis commented Feb 1, 2021

I've got an issue.

  • starport serve a scaffolded chain.
  • Introduce a bug, see the bug printed to the terminal (fine so far)
  • ctrl+c
  • starport serve, chain's binary works fine.

You mean you introduce a bug, and it is not caught on a second serve?
What is the introduced bug?

@fadeev
Copy link
Contributor
fadeev commented Feb 1, 2021

Syntax error in a handler of the default module.

@fadeev
Copy link
Contributor
fadeev commented Feb 1, 2021

Yes, when I serve the second time it works fine (even though there is a bug in the code).

@lumtis
Copy link
Contributor Author
lumtis commented Feb 1, 2021

Good catch👍
It is a bug not only related to this branch: #713

Copy link
Member
@ilgooz ilgooz left a comment

Choose a reason for hiding this comment

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

This is good, but I still think that we should try to match source's hash with the binary's hash in addition to this impl in order to secure a determenistic behavior. Otherwise, starport may use a totally different binary because it has the same name. ~this can be done in a seperate PR also.

@@ -185,3 +185,20 @@ func (c *Chain) buildProto(ctx context.Context) error {

return nil
}

func (c *Chain) isBuilt() (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

@lumtis
Copy link
Contributor Author
lumtis commented Feb 2, 2021

This is good, but I still think that we should try to match source's hash with the binary's hash in addition to this impl in order to secure a determenistic behavior. Otherwise, starport may use a totally different binary because it has the same name. ~this can be done in a seperate PR also.

That's a good point. It can become a problem if the user work with different branch or if we implement a workspace system in the future so let's address it in this PR.

I don't think we even need to implement a mapping of a source checksum to binary. We just store the binary checksum along with the source checksum and save it at each build and build again each time this checksum is different. So it will also return true if the binary don't exist.

I'm also thinking, based on this problematic, we can consider that if the binary is different. Then it may be possible that the user has done some eventual side-effect actions that make the current database eventually incorrect. It this case we must reimport the genesis as well instead of just building the binary

@lumtis lumtis added this to the v0.14 milestone Feb 2, 2021
@lumtis lumtis changed the title fix: build binary if it has been deleted fix: build binary if it has been deleted or modified Feb 2, 2021
@lumtis lumtis changed the title fix: build binary if it has been deleted or modified fix: rebuild binary if it has been deleted or modified Feb 2, 2021
@lumtis lumtis requested a review from ilgooz February 2, 2021 12:52
if strings.Contains(err.Error(), "file not found") {
binaryModified = true
} else {
return err
Copy link
Member

Choose a reason for hiding this comment

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

Can we refactor the whole section by using early returns? I think code becomes much more readable that way.

Copy link
Contributor Author
@lumtis lumtis Feb 2, 2021

Choose a reason for hiding this comment

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

What do you mean with the "whole section"?
This part can actually be reversed for better clarity, tell me if it's good like this

Copy link
Member

Choose a reason for hiding this comment

The re 8000 ason will be displayed to describe this comment to others. Learn more.

I mean something like this:

binaryName, err := c.Binary()
if err != nil {
    return err
}

binaryPath, err := exec.LookPath(binaryName)

if !errors.Is(err, exec.ErrNotFound) {
	return err
}

binaryModified := err != nil

if err == nil {
	binaryModified, err = dirchange.HasDirChecksumChanged("", []string{binaryPath}, saveDir, binaryChecksum)
	if err != nil {
		return err
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I personally find it a bit less clear. We check the err even if it's nil and binaryModified := err != nil is a bit ambiguous IMO

Copy link
Member

Choose a reason for hiding this comment

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

What about the moving errors.Is to upper level part?

Copy link
Contributor Author

Choose a reason for hiding 6D40 this comment

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

What do you think of:

binaryPath, err := exec.LookPath(binaryName)
if err != nil && !errors.Is(err, exec.ErrNotFound) {
       return err
}
if errors.Is(err, exec.ErrNotFound) {
       binaryModified = true
}  else {
       binaryModified, err = dirchange.HasDirChecksumChanged("", []string{binaryPath}, saveDir, binaryChecksum)
       if err != nil {
	      return err
       }
}

Copy link
Member

Choose a reason for hiding this comment

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

I think current way is just fine. 👍

lumtis and others added 2 commits February 2, 2021 14:14
Co-authored-by: İlker G. Öztürk <ilkergoktugozturk@gmail.com>
@lumtis lumtis requested a review from ilgooz February 2, 2021 13:31
Copy link
Contributor
@fadeev fadeev left a comment

Choose a reason for hiding this comment

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

Working good so far 🙂

@lumtis lumtis merged commit a7f4b53 into develop Feb 2, 2021
@lumtis lumtis deleted the fix/no-binary branch February 2, 2021 16:52
Jchicode pushed a commit to Jchicode/cli that referenced this pull request Aug 9, 2023
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
0