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(transcation):#195 fixed min_confirmation bug on verify transaction #199

Merged
merged 23 commits into from
Aug 16, 2021

Conversation

cnlangzi
Copy link
Contributor

@cnlangzi cnlangzi commented Aug 9, 2021

fixed #195 ,and improved error message

@cnlangzi cnlangzi changed the title fix(transcation):#195 fixed min_confirmation bug on veriry transaction fix(transcation):#195 fixed min_confirmation bug on verify transaction Aug 9, 2021
@cnlangzi cnlangzi requested a review from moldis August 9, 2021 16:19
@cnlangzi cnlangzi requested a review from Sriep August 10, 2021 02:50
@Sriep
Copy link
Contributor

Sriep commented Aug 11, 2021

Need to make corresponding changes to zbox and zwallet so the PR can be manually integration tested.

For testing use

 go get github.com/0chain/gosdk@5cd687300fd776d80f3dada97bfdc210955380a0

in zbox or zwallet root to point to your gosdk branch . Change 5cd687300fd776d80f3dada97bfdc210955380a0 to latest fix/min-confirm commit.

@cnlangzi
Copy link
Contributor Author

Dayi Chen 23 hours ago
@piers Shepperson Unit test is fixed. please help to check it if you get some time left. thanks.
👀
1

Piers Shepperson 22 hours ago
So there is no way to change the .zcn file once started?

Dayi Chen 22 hours ago
chang it via conf.Load('stream.yaml') on zbox cli startup if it has valid --config argument . I have raised an issue for it 0chain/zboxcli#82 (edited)

Dayi Chen 22 hours ago
some examples are on https://github.com/0chain/gosdk/blob/fix/min_confirm/zboxcore/conf/conf_test.go

Piers Shepperson 22 hours ago
Do we read the .zcn details anew with each different zbox or zwallet command?

Dayi Chen 22 hours ago
No. it always is same in a zbox/zwallet instance

Dayi Chen 21 hours ago
it was read on zbox/zwallet startup , and shared with all commands.

Dayi Chen 21 hours ago
It was done in main without other checking.

Piers Shepperson 21 hours ago
But zbox and zwallet just run one command and end. So it should be reading in the .zcn stuff each time.
My point is that global objects are bad and should be avoided if possible https://github.com/0chain/gosdk/blob/fix/min_confirm/zboxcore/conf/conf.go#L22
So why can't you just call conf.Load as part of each sdk call? Probably just before you need it.

Dayi Chen 21 hours ago
No, we have more calls in live/sync cmd now. (edited)

Dayi Chen 21 hours ago
zbox is long running, and upload/download will be called for many times

Dayi Chen 21 hours ago
Yes. it is fine to remove LoadDefault on init. but for now, we need to add it on any applicatons(zbox/zwallet).

Dayi Chen 21 hours ago
I got it. It is better. let me update it

Dayi Chen 21 hours ago
wait a sec.

Piers Shepperson 21 hours ago
When I use zbox I can change the wallet between zbox commands to change to a different user. Or change the network to point to a different network. Ok will wait for change. (edited)

Dayi Chen 21 hours ago
Only developer might do it. for user, it will not happen on zbox is running

Dayi Chen 21 hours ago
it break everything on zbox/zwallet

Dayi Chen 21 hours ago
not just config

Dayi Chen 21 hours ago
for it, we should add fsnotify to monitor config file

Dayi Chen 21 hours ago
but it is unnecessary. zbox/zwallet is a cli , not application like 0boxsyncwindows/0boxmacsync (edited)

Dayi Chen 21 hours ago
a cmd will check config many times, that is why i move it to a global variable. it prevent us to read and parse it again and again

Piers Shepperson 21 hours ago
But won't zbox reinitialise gosdk on each cli command anyway. You read it in the same number of times just in different ways. (edited)

Dayi Chen 21 hours ago
It is better to remove LoadDefault in init. Because gosdk is imported in many repos. I am not sure whether it is required in all repos . eg zcncore

Dayi Chen 21 hours ago
no, let me explain it more

Dayi Chen 21 hours ago
./zbox upload is a command. but many requests are executed .eg get info from sharders, post data to miners, get metadata from blobbers, get network from 0dns...etc

Dayi Chen 21 hours ago
all of them will ask conf for settings

Piers Shepperson 21 hours ago
Yes and?

Dayi Chen 21 hours ago
if conf is not a global variable, we need load and parse it for each request

Dayi Chen 21 hours ago
a command has many requests. each request need to load and parse config by itself

Dayi Chen 21 hours ago
do you think it is better to save it into a global variable for them?

Piers Shepperson 21 hours ago
Ok so zbox should be able to control the config file. By default gosdk reads in the config on each call. But there is the option for the caller to set the config with a call.

Dayi Chen 21 hours ago
config is a global settings for zbox/zwallet. Should we really need to add customizable feature for each method call instead of shared variable?

Dayi Chen 21 hours ago
I agreed It is better to remove LoadDefault in init

Dayi Chen 21 hours ago
and let zbox/zwallet to call Load to init it

Dayi Chen 21 hours ago
but it is better to load and parse it once, and share it in sub requests in a command (edited)

Piers Shepperson 21 hours ago
Simple gosdk call
zbox: `sdk.DoSomthing
gosdk: no config in input so load.Cofig
DoSomething
Multiple gosdk calls
zbox: get config from gosdk
zbox: sdk.DoSomting(got config)
zbox sdk.DoSomethingElse(got config in input data somwehre)
gosdk: DoSomething uses config given by zbox.
gosdk: DoSometingElse uses config given by zbox
(edited)

Piers Shepperson 21 hours ago
Will have to modify the multi-sdk call zbox commands. (edited)

Dayi Chen 21 hours ago
Yes. it is best to pass config as method input. but there are real a lot of methods should be refactored? do you think it is fine to do it now? (edited)

Dayi Chen 21 hours ago
like I did in blobber

Dayi Chen 21 hours ago
almost methods need to be refactored on gosdk (edited)

Piers Shepperson 21 hours ago
Maybe in first PR you can just do the simple case. Read the config file in on each sdk call.
Then raise an issue to allow the caller to get the config from gosdk then pass it into sdk calls that want to use that config. This feels like a good way to do it to me.

Dayi Chen 21 hours ago
transaction bug is for all calls. if it is changed, and all calls need be updated (edited)

Piers Shepperson 21 hours ago
I did not follow that last point.

Dayi Chen 21 hours ago
OK. let me review code first

Dayi Chen 21 hours ago
github push seem have some problem. I can't push it. I will try to push it tomorrow. and back you. thanks a lot

Dayi Chen 21 hours ago
https://www.githubstatus.com/

Dayi Chen 21 hours ago
github services are Degraded now

Piers Shepperson 21 hours ago
Yes I just tried to push to 0chain, did not work. Glad its not just me:sweat_smile: (edited)
😂
1

Dayi Chen 20 hours ago
I thought it was my problem until check status

Dayi Chen 20 hours ago
talk to you tomorrow
👍
1

Dayi Chen 20 hours ago
gitbub is back. I have got PR updated. please help me double check it. thanks

Dayi Chen 20 hours ago
I will back to fix tomorrow if it has other issues. thanks. bye for now

Dayi Chen 20 hours ago
ignore it. there are more code need be refactored. I will back you tomorrow. thanks
👍
1

Dayi Chen 20 hours ago
related code has been refactored.

Dayi Chen 3 hours ago
@piers Shepperson please help to review it again if you get some time left.
👍
1

Piers Shepperson 2 hours ago
Sorry which one is this.

Dayi Chen 2 hours ago
@piers Shepperson #199
👀
1

Piers Shepperson 35 minutes ago
My IDE can't find anywhere conf.LoadDefault or conf.Load is used outside of tests and conf?
You have added a conf.Config object as a paramter to various things e.g. CommitFolderChange but you nowhere in gosdk do you make a conf.Config object.
Is the intention to modify zbox and zwallet to call conf.Load and then enter in commitFolderChange and any other API calls that need it? (edited)

Piers Shepperson 32 minutes ago
If so you should do those modifications to zbox, zwallet first, so you can integration test them.

Dayi Chen 21 minutes ago
yes. we need update them in sdk first, and release a new version. Zbox/zwallet need to update sdk with new vesion

Dayi Chen 21 minutes ago
So first gosdk, and zbox zwallet

Dayi Chen 20 minutes ago
https://0chain.slack.com/archives/D021MTJV1EK/p1628610551037900?thread_ts=1628584516.000400&channel=D021MTJV1EK&message_ts=1628610551.037900

Piers Shepperson
Simple gosdk call

  1. zbox: `sdk.DoSomthing
  2. gosdk: no config in input so load.Cofig
  3. DoSomething
    Multiple gosdk calls
    Show more
    Direct Message | Yesterday at 23:49 | View reply

Dayi Chen 20 minutes ago
That is implemented with your idea

Dayi Chen 16 minutes ago
Gosdk has been upgraded. And I will upgrade zbox and zwallet. I can’t upgrade zbox /zwallet now

Piers Shepperson 15 minutes ago
Where is the 2. gosdk: no config in input so loadConfig bit.
AFAICT neither conf.Load nor conf.LoadDefault are used in gosdk. (edited)

Dayi Chen 14 minutes ago
https://0chain.slack.com/archives/D021MTJV1EK/p1628610551037900?thread_ts=1628584516.000400&channel=D021MTJV1EK&message_ts=1628610551.037900

Piers Shepperson
Simple gosdk call

  1. zbox: `sdk.DoSomthing
  2. gosdk: no config in input so load.Cofig
  3. DoSomething
    Multiple gosdk calls
    Show more
    Direct Message | Yesterday at 23:49 | View reply

Dayi Chen 14 minutes ago
Config should be loaded in zbox. Right?

Dayi Chen 13 minutes ago
gosdk always use it as input?

Dayi Chen 10 minutes ago
What should be changed now?let me know. I will follow your idea. But zbox and zwallet should be upgraded after gosdk

Dayi Chen 8 minutes ago
Btw, could we update discussion in review instead of slack?

Piers Shepperson 8 minutes ago
ok

Dayi Chen 7 minutes ago
Thanks. Please mark what should be updated, and how on pr review. I will discuss and update it

@cnlangzi
Copy link
Contributor Author

Need to make corresponding changes to zbox and zwallet so the PR can be manually integration tested.

For testing use

 go get github.com/0chain/gosdk@5cd687300fd776d80f3dada97bfdc210955380a0

in zbox or zwallet root to point to your gosdk branch . Change 5cd687300fd776d80f3dada97bfdc210955380a0 to latest fix/min-confirm commit.

I would suggest to upgrade gosdk first. And upgrade zbox/zwallet after then. Nothing will be broken. Because zbox/zwallet is working on current gosdk version before we upgrade it.

@cnlangzi
Copy link
Contributor Author

if we have zbox/zwallet upgrade with local version, could you let me know we should how to review the PR on zbox/zwallet without new gosdk?

@Sriep
Copy link
Contributor

Sriep commented Aug 11, 2021

I don't like the idea of unnecessarily merging untested code.
Also added issue #204

@cnlangzi
Copy link
Contributor Author

I don't like the idea of unnecessarily merging untested code.
Also added issue #204

Is it a circle?

@Sriep
Copy link
Contributor

Sriep commented Aug 11, 2021

#199 (comment)
Explains how to test zbox and zwallet against your gosdk branch.
Don't understand circle reference.

@cnlangzi
Copy link
Contributor Author

I don't like the idea of unnecessarily merging untested code.
Also added issue #204

all unit tests are passed ,right? https://github.com/0chain/gosdk/actions/runs/1119656429

@Sriep
Copy link
Contributor

Sriep commented Aug 11, 2021

All unit tests have passed, but this is mainly a regression test. Integration testing is necessary to test new gosdk changes work.

All PRs should be integration tested on a running chain before merging. This goes double for gosdk as gosdk is a library, not an executable, so its code can only be tested from an application like zbox or zwallet.

@cnlangzi
Copy link
Contributor Author

Need to make corresponding changes to zbox and zwallet so the PR can be manually integration tested.
For testing use

 go get github.com/0chain/gosdk@5cd687300fd776d80f3dada97bfdc210955380a0

in zbox or zwallet root to point to your gosdk branch . Change 5cd687300fd776d80f3dada97bfdc210955380a0 to latest fix/min-confirm commit.

I would suggest to upgrade gosdk first. And upgrade zbox/zwallet after then. Nothing will be broken. Because zbox/zwallet is working on current gosdk version before we upgrade it.

We have raised an upgrade task on zbox 0chain/zboxcli#82 . Is it still not ok? They can be done one by one , right?

@Sriep
Copy link
Contributor

Sriep commented Aug 11, 2021

Not sure what you mean.

  1. These changes need to be integration tested.
  2. We need to make changes to zbox and zwallet to make use of this PRs changes.
  3. Modify the go.mod and go.sum files in the new zbox and zwallet branches to point to this PR's gosdk branch for testing fix(transcation):#195 fixed min_confirmation bug on verify transaction #199 (comment).
  4. Manually integration test the new gosdk, zbox and zwallet changes.
  5. Once integration testing is successful the gosdk changes can be merged into staging.
  6. The zbox and zwallet PRs will need to be changed so the go.mod and go.sum point to the new gosdk head . Use go get github.com/0chain/gosdk@<gosdk head commit> again.
  7. zbox and zwallet can now be merged.

@cnlangzi
Copy link
Contributor Author

cnlangzi commented Aug 11, 2021 via email

@Sriep
Copy link
Contributor

Sriep commented Aug 11, 2021

The gosdk code has not been tested yet. I don't see any good reason to unnecessarily merge untested code.

Also, I have been asked not to merge any code that I have not personally tested on a running chain, and I can't do this unless there is a compatible zbox or zwallet.

@Sriep
Copy link
Contributor

Sriep commented Aug 11, 2021

The process is probably easier than it seems. Once you get used to using

go get github.com/0chain/gosdk@<commit>

it's quite straightforward.

@cnlangzi
Copy link
Contributor Author

cnlangzi commented Aug 11, 2021 via email

core/conf/config.go Outdated Show resolved Hide resolved
core/conf/config_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@moldis moldis left a comment

Choose a reason for hiding this comment

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

Mostly looks fine, just minor code cleanup

@cnlangzi cnlangzi marked this pull request as draft August 13, 2021 15:16
@cnlangzi cnlangzi marked this pull request as ready for review August 14, 2021 01:20
@cnlangzi cnlangzi requested review from moldis and Sriep August 14, 2021 01:25
@cnlangzi
Copy link
Contributor Author

@Sriep @moldis please help me to review this PR again. thanks.

@Sriep
Copy link
Contributor

Sriep commented Aug 14, 2021

Code should be reiviewed after it has been tested and shown to work. You have a soultion that might work the next step is to test it. untill it is tested there is no expectation that the code works.

So i suggest making the necessary changes to zbox and zwallet, creating Prs with thoes changes, starting up a chain and using zbox to post some transactions. You can then singel step though your code and check that it works.That will make fixing any issues that much easier.

@cnlangzi
Copy link
Contributor Author

Hi man, it is done . And you can check it from git if you don’t believe it.

talk is cheap, let's show it in code

@Sriep @moldis I have refactored code again based on your reviews.

About global variable issue. I am prefer to do it in global variable too. It prevents to introduce break changes as less as possible. so I have reverted code to global variable. But Load is moved out from gosdk. zbox/zwallet has to load it by itself, and set global variable by transaction.SetConfig. eg

https://github.com/0chain/zwalletcli/blob/bac54c67d98defb4a4593c7ac2b44cfd7fd5494b/cmd/root.go#L84

https://github.com/0chain/zboxcli/blob/8f4a1801e47aeeae2bd7ace92c25599d85b62a58/cmd/root.go#L98

@Sriep please check 0chain/zwalletcli@bac54c6 and 0chain/zboxcli@8f4a180 . is it fine for you to review this PR now?

please help me to review this PR again @Sriep @moldis thanks.

@Sriep
Copy link
Contributor

Sriep commented Aug 14, 2021

Great, you have created zbox and zwallet PRs. I should be testing some issues later, I'll take the opportunity to check the PRs' code then.

@Sriep
Copy link
Contributor

Sriep commented Aug 15, 2021

I tested zwallet 0chain/zwalletcli#36 and the changes work fine.

If I understand correctly there are a subset of gosdk API methods that require a previous call to conf.LoadConfigFile so that gosdk has access to the config details.

Do we have this documented anywhere, with a list of API methods that require a previous call toconf.LoadConfigFile?

@cnlangzi
Copy link
Contributor Author

cnlangzi commented Aug 15, 2021 via email

@Sriep
Copy link
Contributor

Sriep commented Aug 15, 2021

It is good that the correct error message is thrown. I assume you have integration tested the other parts of the PR. I just checked that the changes were not breaking general usage for other developers. Code reviews aren't used to check the code works, testing does that.

However, this PR introduces changes to how gosdk work that a user would not normally expect, so should be documented somewhere. At least in the readme.mb.

As this is a public API it would be nice to add these details to the documentation to be picked up by go.doc. However, we don't seem to support go.doc so probably can skip that here. We should probably add an issue about supporting go.doc.

But check with @saswata to see if there is anywhere else that documented gosdk and needs to be updated.

@cnlangzi cnlangzi merged commit 520f39c into master Aug 16, 2021
@cnlangzi cnlangzi deleted the fix/min_confirm branch August 16, 2021 09:49
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.

min_confirmation doesn't work.
3 participants