Skip to content

Commit

Permalink
sphinx: allow concurrent onion packet processing
Browse files Browse the repository at this point in the history
  • Loading branch information
joostjager committed Apr 27, 2021
1 parent 3c8c8d0 commit c6877ca
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sphinx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"math/big"
"sync"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg"
Expand Down Expand Up @@ -701,6 +702,8 @@ type Tx struct {
// only be accessed if the index is *not* included in the replay set, or
// otherwise failed any other stage of the processing.
packets []ProcessedPacket

sync.Mutex
}

// BeginTxn creates a new transaction that can later be committed back to the
Expand Down Expand Up @@ -751,6 +754,9 @@ func (t *Tx) ProcessOnionPacket(seqNum uint16, onionPkt *OnionPacket,
return err
}

t.Lock()
defer t.Unlock()

// Add the hash prefix to pending batch of shared secrets that will be
// written later via Commit().
err = t.batch.Put(seqNum, hashPrefix, incomingCltv)
Expand Down

0 comments on commit c6877ca

Please sign in to comment.