Skip to content

Commit 522b799

Browse files
authored
Merge pull request #49 from joostjager/concurrent-decoder
sphinx: allow concurrent onion packet processing
2 parents 3c8c8d0 + c6877ca commit 522b799

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

sphinx.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"math/big"
10+
"sync"
1011

1112
"github.com/btcsuite/btcd/btcec"
1213
"github.com/btcsuite/btcd/chaincfg"
@@ -701,6 +702,8 @@ type Tx struct {
701702
// only be accessed if the index is *not* included in the replay set, or
702703
// otherwise failed any other stage of the processing.
703704
packets []ProcessedPacket
705+
706+
sync.Mutex
704707
}
705708

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

757+
t.Lock()
758+
defer t.Unlock()
759+
754760
// Add the hash prefix to pending batch of shared secrets that will be
755761
// written later via Commit().
756762
err = t.batch.Put(seqNum, hashPrefix, incomingCltv)

0 commit comments

Comments
 (0)