@@ -2,7 +2,6 @@ package sphinx
22
33import (
44 "bytes"
5- "crypto/sha256"
65 "encoding/binary"
76 "errors"
87 "fmt"
@@ -20,15 +19,10 @@ const (
2019
2120 // dbPermissions sets the database permissions to user write-and-readable.
2221 dbPermissions = 0600
23-
24- // sharedHashSize is the size in bytes of the keys we will be storing
25- // in the DecayedLog. It represents the first 20 bytes of a truncated
26- // sha-256 hash of a secret generated by ECDH.
27- sharedHashSize = 20
2822)
2923
3024var (
31- // sharedHashBucket is a bucket which houses the first sharedHashSize
25+ // sharedHashBucket is a bucket which houses the first HashPrefixSize
3226 // bytes of a received HTLC's hashed shared secret as the key and the HTLC's
3327 // CLTV expiry as the value.
3428 sharedHashBucket = []byte ("shared-hash" )
3933 batchReplayBucket = []byte ("batch-replay" )
4034)
4135
42- // HashPrefix is a statically size, 20-byte array containing the prefix
43- // of a Hash256, and is used to detect duplicate sphinx packets.
44- type HashPrefix [sharedHashSize ]byte
45-
4636var (
4737 // ErrDecayedLogInit is used to indicate a decayed log failed to create
4838 // the proper bucketing structure on startup.
5343 ErrDecayedLogCorrupted = errors .New ("decayed log structure corrupted" )
5444)
5545
56- // ReplayLog is an interface that defines a new on-disk data structure that
57- // contains a persistent log to enable strong replay protection. The interface
58- // is general to allow implementations near-complete autonomy. All of these
59- // calls should be safe for concurrent access.
60- type ReplayLog interface {
61- // Start starts up the on-disk persistent log. It returns an error if
62- // one occurs.
63- Start () error
64-
65- // Stop safely stops the on-disk persistent log.
66- Stop () error
67-
68- // Get retrieves an entry from the persistent log given its hash prefix. It
69- // returns the value stored and an error if one occurs. Returns
70- // ErrLogEntryNotFound if hash prefix is not in the log.
71- Get (* HashPrefix ) (uint32 , error )
72-
73- // Put stores an entry into the persistent log given a []byte and an
74- // accompanying purposefully general type. It returns an error if the
75- // provided hash prefix already exists in the log.
76- Put (* HashPrefix , uint32 ) error
77-
78- // PutBatch stores
79- PutBatch (* Batch ) (* ReplaySet , error )
80-
81- // Delete deletes an entry from the persistent log given its hash prefix.
82- Delete (* HashPrefix ) error
83- }
84-
8546// DecayedLog implements the PersistLog interface. It stores the first
86- // sharedHashSize bytes of a sha256-hashed shared secret along with a node's
47+ // HashPrefixSize bytes of a sha256-hashed shared secret along with a node's
8748// CLTV value. It is a decaying log meaning there will be a garbage collector
8849// to collect entries which are expired according to their stored CLTV value
8950// and the current block height. DecayedLog wraps boltdb for simplicity and
@@ -282,20 +243,6 @@ func (d *DecayedLog) gcExpiredHashes(height uint32) (uint32, error) {
282243 return numExpiredHashes , nil
283244}
284245
285- // hashSharedSecret Sha-256 hashes the shared secret and returns the first
286- // sharedHashSize bytes of the hash.
287- func hashSharedSecret (sharedSecret * Hash256 ) HashPrefix {
288- // Sha256 hash of sharedSecret
289- h := sha256 .New ()
290- h .Write (sharedSecret [:])
291-
292- var sharedHash HashPrefix
293-
294- // Copy bytes to sharedHash
295- copy (sharedHash [:], h .Sum (nil ))
296- return sharedHash
297- }
298-
299246// Delete removes a <shared secret hash, CLTV> key-pair from the
300247// sharedHashBucket.
301248func (d * DecayedLog ) Delete (hash * HashPrefix ) error {
0 commit comments