Skip to content

Commit fdbaa27

Browse files
committed
Fix TTL behaviour for lock keys
1 parent 7a321c8 commit fdbaa27

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

stores/utxo/aerospike/create.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ import (
8282
var placeholderKey *aerospike.Key
8383

8484
// LockRecordIndex is a special index value for lock records
85-
// Uses max uint32 to avoid conflict with actual sub-records (0, 1, 2, ...)
86-
const LockRecordIndex = uint32(0xFFFFFFFF)
85+
// Uses high uint32 values to avoid conflict with actual sub-records (0, 1, 2, ...)
86+
// Version history:
87+
// - v1: 0xFFFFFFFF (had TTL bug - locks never expired)
88+
// - v2: 0xFFFFFFFE (TTL fix applied)
89+
const LockRecordIndex = uint32(0xFFFFFFFE)
8790

8891
// LockRecordBaseTTL is the minimum time-to-live for lock records in seconds
8992
const LockRecordBaseTTL = uint32(30)
@@ -1002,7 +1005,8 @@ func (s *Store) acquireLock(txHash *chainhash.Hash, numRecords int) (*aerospike.
10021005

10031006
lockTTL := calculateLockTTL(numRecords)
10041007

1005-
lockPolicy := util.GetAerospikeWritePolicy(s.settings, lockTTL)
1008+
lockPolicy := util.GetAerospikeWritePolicy(s.settings, 0) // generation 0
1009+
lockPolicy.Expiration = lockTTL // Set TTL in seconds
10061010
lockPolicy.RecordExistsAction = aerospike.CREATE_ONLY
10071011

10081012
hostname, _ := os.Hostname()
@@ -1022,7 +1026,7 @@ func (s *Store) acquireLock(txHash *chainhash.Hash, numRecords int) (*aerospike.
10221026
return nil, errors.NewTxExistsError("transaction creation in progress or already exists: %s", txHash)
10231027
}
10241028

1025-
return nil, errors.NewProcessingError("failed to acquire lock", err)
1029+
return nil, errors.NewProcessingError("failed to acquire lock for %s", lockKey, err)
10261030
}
10271031

10281032
return lockKey, nil

0 commit comments

Comments
 (0)