waddrmgr/db: store birthday block verification status
In this commit, we add a new key/value pair to the waddrmgr's sync bucket to store the verification status of the birthday block. This verification status determines whether the wallet has verified the correctness of its birthday block through its sanity check on startup.
This commit is contained in:
parent
4f5baed780
commit
6568c433fe
1 changed files with 46 additions and 4 deletions
|
@ -253,10 +253,11 @@ var (
|
|||
watchingOnlyName = []byte("watchonly")
|
||||
|
||||
// Sync related key names (sync bucket).
|
||||
syncedToName = []byte("syncedto")
|
||||
startBlockName = []byte("startblock")
|
||||
birthdayName = []byte("birthday")
|
||||
birthdayBlockName = []byte("birthdayblock")
|
||||
syncedToName = []byte("syncedto")
|
||||
startBlockName = []byte("startblock")
|
||||
birthdayName = []byte("birthday")
|
||||
birthdayBlockName = []byte("birthdayblock")
|
||||
birthdayBlockVerifiedName = []byte("birthdayblockverified")
|
||||
)
|
||||
|
||||
// uint32ToBytes converts a 32 bit unsigned integer into a 4-byte slice in
|
||||
|
@ -2012,6 +2013,47 @@ func putBirthdayBlock(ns walletdb.ReadWriteBucket, block BlockStamp) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// fetchBirthdayBlockVerification retrieves the bit that determines whether the
|
||||
// wallet has verified that its birthday block is correct.
|
||||
func fetchBirthdayBlockVerification(ns walletdb.ReadBucket) bool {
|
||||
bucket := ns.NestedReadBucket(syncBucketName)
|
||||
verifiedValue := bucket.Get(birthdayBlockVerifiedName)
|
||||
|
||||
// If there is no verification status, we can assume it has not been
|
||||
// verified yet.
|
||||
if verifiedValue == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Otherwise, we'll determine if it's verified by the value stored.
|
||||
verified := binary.BigEndian.Uint16(verifiedValue[:])
|
||||
return verified != 0
|
||||
}
|
||||
|
||||
// putBirthdayBlockVerification stores a bit that determines whether the
|
||||
// birthday block has been verified by the wallet to be correct.
|
||||
func putBirthdayBlockVerification(ns walletdb.ReadWriteBucket, verified bool) error {
|
||||
// Convert the boolean to an integer in its binary representation as
|
||||
// there is no way to insert a boolean directly as a value of a
|
||||
// key/value pair.
|
||||
verifiedValue := uint16(0)
|
||||
if verified {
|
||||
verifiedValue = 1
|
||||
}
|
||||
|
||||
var verifiedBytes [2]byte
|
||||
binary.BigEndian.PutUint16(verifiedBytes[:], verifiedValue)
|
||||
|
||||
bucket := ns.NestedReadWriteBucket(syncBucketName)
|
||||
err := bucket.Put(birthdayBlockVerifiedName, verifiedBytes[:])
|
||||
if err != nil {
|
||||
str := "failed to store birthday block verification"
|
||||
return managerError(ErrDatabase, str, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// managerExists returns whether or not the manager has already been created
|
||||
// in the given database namespace.
|
||||
func managerExists(ns walletdb.ReadBucket) bool {
|
||||
|
|
Loading…
Reference in a new issue