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

Add command to download a contract #209

Merged
merged 40 commits into from
Apr 19, 2022
Merged

Add command to download a contract #209

merged 40 commits into from
Apr 19, 2022

Conversation

ixje
Copy link
Contributor

@ixje ixje commented Mar 15, 2022

…from a remote network into our local chain of choice. This is part of an effort to make it easier to make our development (private) chain reflect the final network we want to deploy on. This is part 1, where part 2 will be on the neo3-visual-tracker repo. The end result could look like shown in the video.

contract-download-generate-2022-03-15_12.27.05.mp4

.

@ixje
Copy link
Contributor Author

ixje commented Mar 15, 2022

The one thing I dislike about the current implementation is that the way of parameter entry to the download command is inconvenient. Selecting the destination chain is ok, then you can still have the contract hash you want to download on your clipboard for pasting, but the RPC url of the source chain (where we download the contract from) has to be typed manually. You can't seem to switch windows without losing the drop down box.

I thought about having the option to store the "source rpc url" in some configuration file such that it can be selected from a list (or if the input field is empty takes the value from the config). What would be the right place? The neo-servers.json file perhaps?

@devhawk
Copy link
Contributor

devhawk commented Mar 16, 2022

The one thing I dislike about the current implementation is that the way of parameter entry to the download command is inconvenient. Selecting the destination chain is ok, then you can still have the contract hash you want to download on your clipboard for pasting, but the RPC url of the source chain (where we download the contract from) has to be typed manually. You can't seem to switch windows without losing the drop down box.

I left a comment about this in the code. TL;DR user should be able to specify 'mainnet' or 'testnet' in addition to a full URL.

I thought about having the option to store the "source rpc url" in some configuration file such that it can be selected from a list (or if the input field is empty takes the value from the config). What would be the right place? The neo-servers.json file perhaps?

Express doesn't know anything about the neo-servers.json file. Not sure this command would get enough use to warrant adding that support

@ixje
Copy link
Contributor Author

ixje commented Mar 18, 2022

I thought about having the option to store the "source rpc url" in some configuration file such that it can be selected from a list (or if the input field is empty takes the value from the config). What would be the right place? The neo-servers.json file perhaps?

Express doesn't know anything about the neo-servers.json file. Not sure this command would get enough use to warrant adding that support

We can ignore this comment. It's actually for the visual-tracker side

@ixje
Copy link
Contributor Author

ixje commented Mar 21, 2022

Note that I did not yet move all logic down to NodeUtility.PersistContract (Formerly known as ExpressOracle) as per #209 (comment)

Btw do you prefer 1 commit per issue or are you fine with the 1 commit for all I've been doing so far?

@devhawk
Copy link
Contributor

devhawk commented Mar 21, 2022

Btw do you prefer 1 commit per issue or are you fine with the 1 commit for all I've been doing so far?

I don't typically review commit by commit. I like looking at all the changes at once. So whatever works better for you

@ixje ixje requested a review from devhawk April 12, 2022 07:33
Comment on lines 339 to 340
var stateEquals = localContract.ToJson().ToByteArray(false)
.SequenceEqual(state.ToJson().ToByteArray(false));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is probably a better way of doing this, but at least it works (where Equals and == don't).

// to avoid having contracts with duplicate id's. This is important because the contract id is part of the
// StorageContext used with Storage syscalls and else we'll potentially override storage keys or iterate
// over keys that shouldn't exist for one of the contracts.
if (state.Id <= LastUsedContractId(snapshot))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Why not just always use the next available ID? Since we have to handle the case where the local id != remote id, why not simplify the logic?

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 tried to keep it the same as the remote contract whenever possible. Always using the last is also an option.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's simpler just to issue a new local contract id

ContractCommand.OverwriteForce.StorageOnly => (false, false),
_ => throw new NotSupportedException($"Invalid OverwriteForce value {force}"),
};

Copy link
Contributor

Choose a reason for hiding this comment

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

Note, I pulled GetSnapshot into PersistContract so that the snapshot lifetime can be managed with a using statement

ContractCommand.OverwriteForce.All => (true, true),
ContractCommand.OverwriteForce.ContractOnly => (true, false),
ContractCommand.OverwriteForce.None => (false, false),
ContractCommand.OverwriteForce.StorageOnly => (false, false),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
ContractCommand.OverwriteForce.StorageOnly => (false, false),
ContractCommand.OverwriteForce.StorageOnly => (false, true),

Copy link
Contributor

Choose a reason for hiding this comment

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

Ouch, bad copy/paste error

Comment on lines 345 to 348
if (!localContract.Hash.Equals(state.Hash)
|| localContract.UpdateCounter != state.UpdateCounter
|| !localContract.Nef.ToArray().SequenceEqual(state.Nef.ToArray())
|| !localContract.Manifest.ToJson().ToByteArray(false).SequenceEqual(state.Manifest.ToJson().ToByteArray(false)))
Copy link
Contributor Author

@ixje ixje Apr 15, 2022

Choose a reason for hiding this comment

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

At this point we found a contract locally with the same hash as state.hash (the remote contract) at L313. Therefore

!localContract.Hash.Equals(state.Hash)

is always false and seems unnecessary to check again.

With the force argument being StorageOnly || NONE. The only check we should do here is making sure that the contract didn't change which otherwise looks fine.

I thought #209 (comment)) requested a detailed error what is wrong but those changes are now gone and we actually get a generic error instead. Why is that?

src/neoxp/Node/NodeUtility.cs Outdated Show resolved Hide resolved
@ixje
Copy link
Contributor Author

ixje commented Apr 15, 2022

I tried downloading the PolicyContract which already exists but got no error, which seems incorrect.

@ixje
Copy link
Contributor Author

ixje commented Apr 15, 2022 via email

@devhawk devhawk requested a review from JohndeVadoss April 19, 2022 15:21
@devhawk
Copy link
Contributor

devhawk commented Apr 19, 2022

This looks ready to go. I'll have @JohndeVadoss give it a quick once over before merging

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