mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 07:35:07 +02:00
multi: make AddPreimage variadic, optimistically compute key
In this commit, we modify the WitnessCache's AddPreimage method to accept a variadic number of preimages. This enables callers to batch preimage writes in performance critical areas of the codebase, e.g. the htlcswitch. Additionally, we lift the computation of the witnesses' keys outside of the db transaction. This saves us from having to do hashing inside and blocking other callers, and limits extraneous blocking at the call site.
This commit is contained in:
@@ -64,8 +64,10 @@ type WitnessBeacon interface {
|
||||
// True is returned for the second argument if the preimage is found.
|
||||
LookupPreimage(payhash []byte) ([]byte, bool)
|
||||
|
||||
// AddPreImage adds a newly discovered preimage to the global cache.
|
||||
AddPreimage(pre []byte) error
|
||||
// AddPreimages adds a batch of newly discovered preimages to the global
|
||||
// cache, and also signals any subscribers of the newly discovered
|
||||
// witness.
|
||||
AddPreimages(preimages ...[]byte) error
|
||||
}
|
||||
|
||||
// ChannelArbitratorConfig contains all the functionality that the
|
||||
|
@@ -79,7 +79,7 @@ func (h *htlcOutgoingContestResolver) Resolve() (ContractResolver, error) {
|
||||
|
||||
// With the preimage obtained, we can now add it to the global
|
||||
// cache.
|
||||
if err := h.PreimageDB.AddPreimage(preimage[:]); err != nil {
|
||||
if err := h.PreimageDB.AddPreimages(preimage[:]); err != nil {
|
||||
log.Errorf("%T(%v): unable to add witness to cache",
|
||||
h, h.htlcResolution.ClaimOutpoint)
|
||||
}
|
||||
|
Reference in New Issue
Block a user