-
Notifications
You must be signed in to change notification settings - Fork 602
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
Mark addresses used #207
Mark addresses used #207
Conversation
6feb9dc
to
3aca99a
Compare
I haven't looked very closely yet, but please define functions before they're used to be consistent with the rest of the code. |
@@ -1228,6 +1262,12 @@ func upgradeManager(namespace walletdb.Namespace) error { | |||
return managerError(ErrDatabase, str, err) | |||
} | |||
|
|||
_, err = rootBucket.CreateBucketIfNotExists(usedAddrBucketName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment here that this bucket was added in version 2.
While I see there is code to make sure invoking It should be done in the same fashion as the others such that it is marked and tested, the manager is closed and reopened, and it is tested again to ensure it is still marked used. Note that all of that is already handled via the TestManager function, so you'd just want to add a |
rootBucket := tx.RootBucket() | ||
mainBucket := tx.RootBucket().Bucket(mainBucketName) | ||
|
||
_, err := rootBucket.CreateBucketIfNotExists(usedAddrBucketName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already done above, so I don't see any reason to do it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I thought we might need this for migrating existing db but I guess upgradeManager
takes care of that. If we don't need this, should we keep the existing version number since we don't need any upgrades?
5e3df03
to
90fdd95
Compare
@@ -730,6 +745,8 @@ func fetchAddress(tx walletdb.Tx, addressID []byte) (interface{}, error) { | |||
if err != nil { | |||
return nil, err | |||
} | |||
used := fetchAddressUsed(tx, addrHash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need the extra local here:
row.used = fetchAddressUsed(tx, addrHash)
This will need to updated for #209. Without handling that upcoming change, the database could be left without the bucket being created (even if this one went in first). |
ea59cf4
to
40f010e
Compare
@davecgh Found an issue when adding tests. The |
@tuxcanfly: I suspected there might be something like that. Glad adding the tests found it. |
|
||
if version < 2 { | ||
// The manager is now at version 2. | ||
version = 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move this after the call to upgradeToVersion2
as the sample shows. No point in changing it only to change it back imo.
Also, the comment about there currently being no upgrades should be modified since it's no longer true.
dde9829
to
f331a07
Compare
@@ -1243,6 +1276,13 @@ func createManagerNS(namespace walletdb.Namespace) error { | |||
return managerError(ErrDatabase, str, err) | |||
} | |||
|
|||
// usedAddrBucketName bucket was added after manager version 1 release | |||
_, err = rootBucket.CreateBucketIfNotExists(usedAddrBucketName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CreateBucket
Alright, latest changes look good. I think the only thing left on this one is the requested additional tests. |
85022a4
to
24f23a8
Compare
@davecgh Updated the test to make cover the initial unmarked case. |
OK |
24f23a8
to
7d85ed4
Compare
7d85ed4
to
85fe722
Compare
Added a database flag on Address to mark used addresses and prevent address re-use.
Refs #196