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

Mark addresses used #207

Merged
merged 1 commit into from
Mar 10, 2015
Merged

Conversation

tuxcanfly
Copy link
Contributor

Added a database flag on Address to mark used addresses and prevent address re-use.

Refs #196

@tuxcanfly tuxcanfly force-pushed the single-use-addr branch 5 times, most recently from 6feb9dc to 3aca99a Compare March 3, 2015 13:20
@davecgh
Copy link
Member

davecgh commented Mar 3, 2015

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)
Copy link
Member

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.

@davecgh
Copy link
Member

davecgh commented Mar 3, 2015

While I see there is code to make sure invoking Used on the address gives the expected result, I don't see any tests which actually mark an address used and expect it to be true. Please add a test for this.

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 testMarkedUsed function that is invoked from testManagerAPI, probably just before the testChangePassphrase call. You can examine the create flag in the test context to determine whether the addresses should already be marked used or not.

rootBucket := tx.RootBucket()
mainBucket := tx.RootBucket().Bucket(mainBucketName)

_, err := rootBucket.CreateBucketIfNotExists(usedAddrBucketName)
Copy link
Member

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.

Copy link
Contributor Author

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?

@tuxcanfly tuxcanfly force-pushed the single-use-addr branch 4 times, most recently from 5e3df03 to 90fdd95 Compare March 3, 2015 14:45
@@ -730,6 +745,8 @@ func fetchAddress(tx walletdb.Tx, addressID []byte) (interface{}, error) {
if err != nil {
return nil, err
}
used := fetchAddressUsed(tx, addrHash)
Copy link
Member

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)

@davecgh
Copy link
Member

davecgh commented Mar 3, 2015

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).

@tuxcanfly tuxcanfly force-pushed the single-use-addr branch 4 times, most recently from ea59cf4 to 40f010e Compare March 4, 2015 15:42
@tuxcanfly
Copy link
Contributor Author

@davecgh Found an issue when adding tests. The used flag is only loaded once on the first fetch, so if a ManagedAddress was marked used after it's in the cache, it will have stale data. I guess one way is to always query the db on Used. Or maybe delete the cache key on marking used. Will check and push a fix for this. Thanks.

@davecgh
Copy link
Member

davecgh commented Mar 4, 2015

@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
Copy link
Member

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.

@tuxcanfly tuxcanfly force-pushed the single-use-addr branch 3 times, most recently from dde9829 to f331a07 Compare March 7, 2015 14:47
@davecgh davecgh mentioned this pull request Mar 9, 2015
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

CreateBucket

@davecgh
Copy link
Member

davecgh commented Mar 10, 2015

Alright, latest changes look good. I think the only thing left on this one is the requested additional tests.

@tuxcanfly tuxcanfly force-pushed the single-use-addr branch 3 times, most recently from 85022a4 to 24f23a8 Compare March 10, 2015 16:25
@tuxcanfly
Copy link
Contributor Author

@davecgh Updated the test to make cover the initial unmarked case.

@davecgh
Copy link
Member

davecgh commented Mar 10, 2015

OK

@conformal-deploy conformal-deploy merged commit 85fe722 into btcsuite:master Mar 10, 2015
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.

None yet

3 participants